[英]Checking whether a user is logged in using stormpath and spring-boot
我有一个简单的Web应用程序,正在使用spring-boot和Storm路径编写用户身份验证。 (我实际上正在使用spring-boot-starter-stormpath-thymeleaf)
我的控制器中有以下请求映射
@RequestMapping(value = "/secure", method = RequestMethod.GET)
public String secure(Model mode, HttpServletRequest request) {
Account account = AccountResolver.INSTANCE.getAccount(request);
if (account != null)
return "secure";
else
return "redirect:/login?next=secure";
}
强制用户登录以查看安全页面。 它可以工作,但感觉不是最优雅的解决方案。 有没有更好的办法? 我认为使用过滤器的解决方案应该可行,但我无法弄清楚。
当前的Stormpath Spring Boot入门程序(尚未)没有身份验证过滤器,但是它将在将来的发行版中提供给那些希望立即使用而不需要使用Spring Security或Apache Shiro的用户。
就是说,我们目前正在努力本地支持Spring Security和Apache Shiro作为Spring Boot启动程序,它们可以与Stormpath Spring Boot启动程序“一起使用”。 直到我们释放它们之前,按照您的指示创建一个自定义servlet过滤器是最好的方法。
您是否也在使用Stormpath Servlet?
如果是这样,您可以按照此文档操作 。 这样,您只需声明要保护应用程序的资源,Stormpath的authc过滤器将在需要时提示进行身份验证。
如果您使用的是Spring MVC,则应使用Spring Security并让Stormpath充当身份验证提供程序。 然后使用标准的Spring Security工具声明访问规则,并在需要时注入当前用户。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.