项目环境spring boot 2.1
首先实现自己的验证类
import com.glodon.security.MD5;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.authc.credential.SimpleCredentialsMatcher;
public class CustomCredentialsMatcher extends SimpleCredentialsMatcher {
@Override
public boolean doCredentialsMatch(AuthenticationToken authcToken, AuthenticationInfo info) {
UsernamePasswordToken token = (UsernamePasswordToken) authcToken;
Object tokenCredentials = encrypt(String.valueOf(token.getPassword()));
Object accountCredentials = getCredentials(info);
//将密码加密与系统加密后的密码校验,内容一致就返回true,不一致就返回false
return equals(tokenCredentials, accountCredentials);
}
//将传进来密码加密方法
private String encrypt(String data) {
String encodePwd = MD5.toMD5(data);//这里可以选择自己的密码验证方式 比如 md5或者sha256等

本文介绍了如何在Spring Boot 2.1环境下自定义Shiro的密码验证方式,通过实现自己的验证类并集成到自定义Realm中,实现密码校验的个性化需求。

751

被折叠的 条评论
为什么被折叠?



