Search in sources :

Example 6 with UserExample

use of com.ganster.cms.core.pojo.UserExample in project Ganster-CMS by Gangster-trio.

the class UserShiroRealm method doGetAuthenticationInfo.

/**
 * 认证信息.(身份验证)
 * Authentication 是用来验证用户身份
 */
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
    String username = (String) token.getPrincipal();
    String password = new String((char[]) token.getCredentials());
    logger.debug("用户登录:{}  凭证:{}", username, password);
    UserExample userExample = new UserExample();
    userExample.createCriteria().andUserNameEqualTo(username);
    List<User> users = userService.selectByExample(userExample);
    if (users.isEmpty()) {
        throw new UnknownAccountException();
    }
    User user = users.get(0);
    if (!user.getUserPassword().equals(password)) {
        throw new IncorrectCredentialsException();
    }
    // 此方法废弃
    SecurityUtils.getSubject().getSession().setAttribute("id", user.getUserId());
    return new SimpleAuthenticationInfo(user, password, getName());
}
Also used : User(com.ganster.cms.core.pojo.User) UserExample(com.ganster.cms.core.pojo.UserExample)

Aggregations

User (com.ganster.cms.core.pojo.User)6 UserExample (com.ganster.cms.core.pojo.UserExample)6 Message (com.ganster.cms.admin.dto.Message)1 GroupNotFountException (com.ganster.cms.core.exception.GroupNotFountException)1 Group (com.ganster.cms.core.pojo.Group)1 Permission (com.ganster.cms.core.pojo.Permission)1 Date (java.util.Date)1 SimpleAuthorizationInfo (org.apache.shiro.authz.SimpleAuthorizationInfo)1