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());
}
Aggregations