我正在为我的Web应用程序项目使用spring-lemon。Spring-lemon默认使用标准表单登录,工作正常。但是,现在我需要对 json 请求使用身份验证,如下所示:
{"username":"spring.user", "password":"s3cret"}
我应该如何安全地实现这一目标?我已经搜索了它,我看到了不同的解决方案,但我无法成功使用它们。
Spring Lemon没有这个功能。但是,我认为您可以编写一个端点,您可以在其中手动获取用户,匹配密码,装饰它,然后设置身份验证,如下所示:
SecurityContextHolder.getContext().setAuthentication(
new UsernamePasswordAuthenticationToken(user,
user.getPassword(), user.getAuthorities()));
LemonTokenAuthenticationFilter 做了类似的事情 - 你可以看看它。