检查用户是否使用stormpath和spring-boot登录

时间:2015-05-03 20:43:26

标签: java spring-mvc spring-boot stormpath

我有一个简单的Web应用程序,我正在使用spring-boot和storm path编写用户身份验证。 (我实际上使用的是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";
}

强制用户登录以查看安全页面。它有效,但它并不觉得它是最优雅的解决方案。有没有更好的办法?我认为应该可以使用过滤器的解决方案,但我无法弄明白。

3 个答案:

答案 0 :(得分:3)

当前Stormpath Spring Boot启动程序尚未(还)具有身份验证过滤器,但它将在未来版本中针对那些需要开箱即用体验的用户而不必使用Spring Security或Apache Shiro。

也就是说,我们目前正致力于将Spring Security和Apache Shiro本身作为Spring Boot启动器支持,这些启动器只能与Stormpath Spring Boot启动器一起工作。在我们发布之前,创建一个自定义servlet过滤器是你最好的方法。

答案 1 :(得分:2)

您是否也在使用Stormpath Servlet?

如果是这样,您可以按照this piece of documentation执行所需操作。这样,您只需要声明要保护的应用程序的资源,Stormpath的authc过滤器将在需要时提示进行身份验证。

答案 2 :(得分:1)

如果您正在使用Spring MVC,则应使用Spring Security并让Stormpath充当身份验证提供程序。然后使用标准的Spring Security工具声明访问规则并在需要时注入当前用户。