TwoFactorAuthenticationAction.java 文件源码

java
阅读 16 收藏 0 点赞 0 评论 0

项目:lams 作者:
@Override
   public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
    HttpServletResponse response) throws Exception {

WebApplicationContext ctx = WebApplicationContextUtils
    .getWebApplicationContext(getServlet().getServletContext());
UserManagementService userManagementService = (UserManagementService) ctx.getBean("userManagementService");

// check if user needs to get his shared two-factor authorization secret
User loggedInUser = userManagementService.getUserByLogin(request.getRemoteUser());
if (loggedInUser.isTwoFactorAuthenticationEnabled() && loggedInUser.getTwoFactorAuthenticationSecret() == null) {

    GoogleAuthenticator gAuth = new GoogleAuthenticator();
    final GoogleAuthenticatorKey key = gAuth.createCredentials();
    String sharedSecret = key.getKey();

    loggedInUser.setTwoFactorAuthenticationSecret(sharedSecret);
    userManagementService.saveUser(loggedInUser);

    request.setAttribute("sharedSecret", sharedSecret);
    String QRCode = GoogleAuthenticatorQRGenerator.getOtpAuthURL(null, "LAMS account: " + loggedInUser.getLogin(), key);
    request.setAttribute("QRCode", QRCode);
}

return mapping.findForward("secret");
   }
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号