1.自定义realm,在Shiro的配置类中加入以下bean
/**
* 身份认证 realm
*/
@Bean
public MyShiroRealm myShiroRealm(){
MyShiroRealm myShiroRealm = new MyShiroRealm();
System.out.println("myShiroRealm 注入成功");
return myShiroRealm;
}
2.重写方法
// 身份认证
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
String username = (String) authenticationToken.getPrincipal();
System.out.println("MyShiroRealm.....doGetAuthenticationInfo");
UserInfo user=null;
try {
user = iUserInfoService.findByUsername(username);
}catch (Exception e){
e.printStackTrace();
}
if (user==null){
return null;
}
// 进行验证,将正确数据讲给shiro处理
SimpleAuthenticationInfo authenticationInfo = ne