shiro里面有许多加密的算法md5,base64
public class UserRealm extends AuthorizingRealm {
@Override
public String getName() {
return "userReam";
}
// 获取身份认证信息
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
String userName =(String) token.getPrincipal();
// 模拟数据库找密码
String psw="1234";
// 通过加密算法迭代两次,并且加盐的密码
Md5Hash md5Hash=new Md5Hash(psw,"lishuai",2);
SimpleAuthenticationInfo info=new SimpleAuthenticationInfo(userName,md5Hash.toString(), ByteSource.Util.bytes("lishuai"),getName());
return info;
}
//获取授权信息
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
return null;
}
}
还需要配置迭代的次数,使用的名称
[main]
userRealm= UserRealm
credentialsMatcher=org.apache.shiro.authc.credential.HashedCredentialsMatcher
credentialsMatcher.hashAlgorithmName=md5
credentialsMatcher.hashIterations=2
securityManager.realm=$userRealm
userRealm.credentialsMatcher=$credentialsMatcher
网友评论