Example #1
0
 /**
  * login
  *
  * @param userName login userName
  * @param password login password
  * @throws InvalidateLoginUserException userName or password invalidate
  */
 public static void login(String userName, String password) throws InvalidateLoginUserException {
   try {
     Subject subject = getSubject();
     UsernamePasswordToken token = new UsernamePasswordToken();
     token.setUsername(userName);
     token.setPassword(password.toCharArray());
     subject.login(token);
   } catch (Exception e) {
     throw new InvalidateLoginUserException("userName or password error.", e);
   }
 }
Example #2
0
 /** 认证回调函数,登录时调用. */
 @Override
 protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken)
     throws AuthenticationException {
   UsernamePasswordToken token = (UsernamePasswordToken) authcToken;
   SecurityUser<Long> user =
       userHessianService.findUserByAccount(token.getUsername(), UserStaEnum.ENABLE);
   if (user != null) {
     token.setUsername(user.getLoginName());
     return new SimpleAuthenticationInfo(user, user.getPassWord(), getName());
   } else {
     return null;
   }
 }