@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken)
throws AuthenticationException {
UsernamePasswordToken token = (UsernamePasswordToken) authcToken;
User user = loginService.findUserByUsername(token.getUsername());
if (user != null) {
// 不加密认证
// return new SimpleAuthenticationInfo(new
// ShiroUser(user.getId(),user.getUsername()),user.getPassword(),getName());
// 加密认证
byte[] salt = Encodes.decodeHex(user.getSalt());
return new SimpleAuthenticationInfo(new ShiroUser(user.getId(), user.getUsername()), user.getPassword(),
ByteSource.Util.bytes(salt), getName());
} else {
return null;
}
}
//指定shiro密码加密方式,shiro用password和salt加密后得到的字符串和数据库中的字符串对比
@PostConstruct
public void initCredentialsMatcher() {
HashedCredentialsMatcher matcher = new HashedCredentialsMatcher("SHA-1");
setCredentialsMatcher(matcher);
}
自定义realm shiro加密配置
最新推荐文章于 2023-08-25 11:18:56 发布