use of org.apache.shiro.authz.SimpleAuthorizationInfo in project pmph by BCSquad.
the class PmphUserRealm method doGetAuthorizationInfo.
/**
* 授权
*
* @param principalCollection
* @return
*/
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
logger.info("--- MyRealm doGetAuthorizationInfo ---");
// 获得经过认证的主体信息
PmphUser user = (PmphUser) principalCollection.getPrimaryPrincipal();
Long userId = user.getId();
// UserService userService = (UserService)InitServlet.getBean("userService");
List<PmphPermission> resourceList = null;
List<String> roleSnList = null;
SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
try {
resourceList = userService.getListAllResource(userId);
roleSnList = userService.getListRoleSnByUser(userId);
List<String> resStrList = new ArrayList<>();
for (PmphPermission resource : resourceList) {
resStrList.add(resource.getUrl());
}
info.setRoles(new HashSet<>(roleSnList));
info.setStringPermissions(new HashSet<>(resStrList));
// 以上完成了动态地对用户授权
logger.info("role => " + roleSnList);
logger.info("permission => " + resStrList);
} catch (Exception e) {
logger.info("message => " + e);
}
return info;
}
use of org.apache.shiro.authz.SimpleAuthorizationInfo in project dq-easy-cloud by dq-open-cloud.
the class EcAuthorityRealm method doGetAuthorizationInfo.
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo();
EcAuthorityUserDTO<Long> authorityUserDTO = (EcAuthorityUserDTO) principals.getPrimaryPrincipal();
List<SysRoleDTO> roleList = sysRoleService.findByUserId(authorityUserDTO.getAuthorityUserId());
Set<Integer> roleNos = new HashSet<>();
for (SysRoleDTO role : roleList) {
authorizationInfo.addRole(role.getName());
roleNos.add(role.getRoleNo());
}
List<SysResourceDTO> roleResourceDTOs = sysResourceService.findByRoleNos(new ArrayList<>(roleNos));
for (SysResourceDTO resourceDTO : roleResourceDTOs) {
authorizationInfo.addStringPermission(resourceDTO.getPermission());
}
return authorizationInfo;
}
use of org.apache.shiro.authz.SimpleAuthorizationInfo in project production_ssm by megagao.
the class CustomRealm method doGetAuthorizationInfo.
/**
* realm的授权方法
*/
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
// 从 principals获取主身份信息
// 将getPrimaryPrincipal方法返回值转为真实身份类型(在上边的doGetAuthenticationInfo认证通过填充到SimpleAuthenticationInfo中身份类型),
ActiveUser activeUser = (ActiveUser) principals.getPrimaryPrincipal();
// 根据身份信息从数据库获取到权限数据
List<SysPermission> permissionList = null;
try {
permissionList = sysService.findPermissionListByUserId(activeUser.getUserid());
} catch (Exception e) {
logger.error(e.getMessage());
}
List<String> permissions = new ArrayList<String>();
if (permissionList != null) {
for (SysPermission sysPermission : permissionList) {
permissions.add(sysPermission.getPercode());
}
}
// 查到权限数据,返回授权信息(要包括 上边的permissions)
SimpleAuthorizationInfo simpleAuthorizationInfo = new SimpleAuthorizationInfo();
// 将上边查询到授权信息填充到simpleAuthorizationInfo对象中
simpleAuthorizationInfo.addStringPermissions(permissions);
return simpleAuthorizationInfo;
}
use of org.apache.shiro.authz.SimpleAuthorizationInfo in project bamboobsc by billchen198318.
the class GreenStepBaseAuthorizingRealm method getSimpleAuthorizationInfo.
private SimpleAuthorizationInfo getSimpleAuthorizationInfo(String username) throws Exception {
Map<String, Object> params = new HashMap<String, Object>();
params.put("account", username);
List<TbUserRole> roleList = userRoleService.findListByParams(params);
if (roleList == null) {
return null;
}
SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
for (TbUserRole userRole : roleList) {
info.addRole(userRole.getRole());
params.clear();
params.put("role", userRole.getRole());
List<TbRolePermission> rolePermissionList = rolePermissionService.findListByParams(params);
if (rolePermissionList == null) {
continue;
}
for (TbRolePermission rolePermission : rolePermissionList) {
info.addStringPermission(rolePermission.getPermission());
}
}
return info;
}
use of org.apache.shiro.authz.SimpleAuthorizationInfo in project perry by ca-cwds.
the class AbstractRealm method doGetAuthorizationInfo.
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
List principalsList = principals.asList();
if (principalsList.size() == PRINCIPALS_COUNT) {
PerryAccount perryAccount = (PerryAccount) principalsList.get(1);
SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo();
SecurityModule.getStaticAuthorizers().forEach(staticAuthorizer -> staticAuthorizer.authorize(perryAccount, authorizationInfo));
return authorizationInfo;
}
throw new AuthenticationException("User authorization failed!");
}
Aggregations