public class ShiroDbRealm extends AuthorizingRealm {
@Inject
private UserService userService ;
/**
* 认证回调函数,登录时调用.
*/
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken)
throws AuthenticationException {
UsernamePasswordToken token = (UsernamePasswordToken) authcToken;
User user= userService.getUserByUserId(token.getUsername());
if (user!= null) {
return new SimpleAuthenticationInfo(user.getUserId(), user.getUserId(), getName());
} else {
return null;
}
}
/**
* 授权查询回调函数, 进行鉴权但缓存中无用户的授权信息时调用.
*/
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
String loginName = (String) principals.fromRealm(getName()).iterator().next();
User user= userService.getUserByUserId(loginName);
if (user != null) {
SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
info.addStringPermission("common-user");
return info;
} else {
return null;
}
}
}权限的认证类
最新推荐文章于 2025-05-03 15:06:28 发布
965

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



