如何shiro中principal 属性的属性

2024-12-20 17:51:05
推荐回答(1个)
回答1:

public class ShiroDbRealm extends AuthorizingRealm

/**
* 授权查询回调函数, 进行鉴权但缓存中无用户的授权信息时调用.
*/
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
ShiroUser shiroUser = (ShiroUser) principals.getPrimaryPrincipal();
SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
Setlt;String; activeRoles = privilegeService.getActiveRolesByUserId(shiroUser.id);
Setlt;String; activePermissions = privilegeService.getActivePermissionsByUserId(shiroUser.id);
info.addRoles(activeRoles);
info.addStringPermissions(activePermissions);
return info;
}