1

我很惊讶地发现在 Grails 中没有明显的插件或设置来启用任何类型的多因素身份验证。有没有优雅的解决方案?理想情况下,我希望实现一个TOTP解决方案,以与 Google Authenticator 或独立 fobs 等应用程序一起使用,但也会考虑基于文本消息的解决方案。

该解决方案必须很好地配合并增强内置的 Spring Security 身份验证。

4

1 回答 1

1

我在自己构建的 Web 应用程序中做了类似的事情。我找不到像直接插件一样干净的东西,但我仍然能够将它与 Spring Security 集成。

所以基本上我最终做的是使用 authy api(http://docs.authy.com/我相信你可以找到与 google auth 类似的东西)来进行 TOTP 交付和验证。初始登录后,我授予他们 ROLE_PRE_AUTH,然后将他们发送到受保护的页面以处理 TOTP。然后我用

    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>(auth.getAuthorities());
    authorities.add(new SimpleGrantedAuthority("ROLE_USER"));
    Authentication newAuth = new UsernamePasswordAuthenticationToken(auth.getPrincipal(), auth.getCredentials(), authorities);
    SecurityContextHolder.getContext().setAuthentication(newAuth);

在我验证(再次使用可用的 api)他们具有有效的 TOTP 后更新用户的角色。所以基本上你想创建一个类来做这个验证,只有在它运行之后你才想导航到下一页(他们现在有权访问)

于 2015-10-06T21:35:40.160 回答