Search in sources :

Example 1 with UserService

use of com.moon.admin.service.UserService in project moon by gentoo111.

the class ShiroRealm method doGetAuthenticationInfo.

@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
    UsernamePasswordToken usernamePasswordToken = (UsernamePasswordToken) token;
    String username = usernamePasswordToken.getUsername();
    UserService userService = SpringUtil.getBean(UserService.class);
    User user = userService.getUser(username);
    if (user == null) {
        throw new UnknownAccountException("用户名不存在");
    }
    if (!user.getPassword().equals(userService.passwordEncoder(new String(usernamePasswordToken.getPassword()), user.getSalt()))) {
        throw new IncorrectCredentialsException("密码错误");
    }
    if (user.getStatus() != Status.VALID) {
        throw new IncorrectCredentialsException("无效状态,请联系管理员");
    }
    SimpleAuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo(user, user.getPassword(), ByteSource.Util.bytes(user.getSalt()), getName());
    UserUtil.setUserSession(user);
    return authenticationInfo;
}
Also used : User(com.moon.admin.domain.User) UserService(com.moon.admin.service.UserService)

Aggregations

User (com.moon.admin.domain.User)1 UserService (com.moon.admin.service.UserService)1