use of org.apache.shiro.authz.SimpleAuthorizationInfo in project nutzboot by nutzam.
the class SimpleAuthorizingRealm method doGetAuthorizationInfo.
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
// null usernames are invalid
if (principals == null) {
throw new AuthorizationException("PrincipalCollection method argument cannot be null.");
}
long userId = ((Number) principals.getPrimaryPrincipal()).longValue();
User user = dao().fetch(User.class, userId);
if (user == null)
return null;
SimpleAuthorizationInfo auth = new SimpleAuthorizationInfo();
auth.addRole(user.getName());
auth.addStringPermission("user:list");
return auth;
}
use of org.apache.shiro.authz.SimpleAuthorizationInfo in project knox by apache.
the class KnoxLdapRealm method queryForAuthorizationInfo.
/**
* Get groups from LDAP.
*
* @param principals
* the principals of the Subject whose AuthenticationInfo should
* be queried from the LDAP server.
* @param ldapContextFactory
* factory used to retrieve LDAP connections.
* @return an {@link AuthorizationInfo} instance containing information
* retrieved from the LDAP server.
* @throws NamingException
* if any LDAP errors occur during the search.
*/
@Override
protected AuthorizationInfo queryForAuthorizationInfo(final PrincipalCollection principals, final LdapContextFactory ldapContextFactory) throws NamingException {
if (!isAuthorizationEnabled()) {
return null;
}
final Set<String> roleNames = getRoles(principals, ldapContextFactory);
SimpleAuthorizationInfo simpleAuthorizationInfo = new SimpleAuthorizationInfo(roleNames);
Set<String> stringPermissions = permsFor(roleNames);
simpleAuthorizationInfo.setStringPermissions(stringPermissions);
return simpleAuthorizationInfo;
}
use of org.apache.shiro.authz.SimpleAuthorizationInfo in project Ganster-CMS by Gangster-trio.
the class UserShiroRealm method doGetAuthorizationInfo.
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
User user = (User) principals.getPrimaryPrincipal();
List<Group> groupList = groupService.selectByUserId(user.getUserId());
Set<String> groupSet = groupList.stream().map(Group::getGroupName).collect(Collectors.toSet());
Set<String> permissionSet = groupSet.stream().flatMap(group -> permissionService.selectByGroupName(group).stream().map(Permission::getPermissionName)).collect(Collectors.toSet());
SimpleAuthorizationInfo simpleAuthorizationInfo = new SimpleAuthorizationInfo();
simpleAuthorizationInfo.setStringPermissions(permissionSet);
simpleAuthorizationInfo.setRoles(groupSet);
return simpleAuthorizationInfo;
}
use of org.apache.shiro.authz.SimpleAuthorizationInfo in project Ganster-CMS by Gangster-trio.
the class UserShiroRealm method doGetAuthorizationInfo.
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
logger.info("进入权限配置");
String username = (String) principals.getPrimaryPrincipal();
UserExample userExample = new UserExample();
userExample.createCriteria().andUserNameEqualTo(username);
List<User> users = userService.selectByExample(userExample);
Integer j = 0;
for (User i : users) {
userId = i.getUserId();
j++;
}
if (j >= 2) {
return null;
}
User user = userService.selectByPrimaryKey(userId);
List<Group> groupList = groupService.selectByUserId(user.getUserId());
Set<String> groupSet = new HashSet<>();
for (Group i : groupList) {
if (!StringUtil.isNullOrEmpty(user.getUserName())) {
groupSet.add(i.getGroupName());
}
}
Set<String> permissionSet = new HashSet<>();
for (Group i : groupList) {
if (!StringUtil.isNullOrEmpty(i.getGroupName())) {
try {
List<Permission> permissions = permissionService.selectByGroupId(i.getGroupId());
for (Permission permission : permissions) {
permissionSet.add(permission.getPermissionName());
}
} catch (GroupNotFountException e) {
logger.info("角色未找到");
}
}
}
SimpleAuthorizationInfo simpleAuthorizationInfo = new SimpleAuthorizationInfo();
simpleAuthorizationInfo.setStringPermissions(permissionSet);
simpleAuthorizationInfo.setRoles(groupSet);
return simpleAuthorizationInfo;
}
use of org.apache.shiro.authz.SimpleAuthorizationInfo in project vip by guangdada.
the class ShiroDbRealm method doGetAuthorizationInfo.
/**
* 权限认证
*/
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
IShiro shiroFactory = ShiroFactroy.me();
ShiroUser shiroUser = (ShiroUser) principals.getPrimaryPrincipal();
List<Integer> roleList = shiroUser.getRoleList();
Set<String> permissionSet = new HashSet<>();
Set<String> roleNameSet = new HashSet<>();
for (Integer roleId : roleList) {
List<String> permissions = shiroFactory.findPermissionsByRoleId(roleId);
if (permissions != null) {
for (String permission : permissions) {
if (ToolUtil.isNotEmpty(permission)) {
permissionSet.add(permission);
}
}
}
String roleName = shiroFactory.findRoleNameByRoleId(roleId);
roleNameSet.add(roleName);
}
SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
info.addStringPermissions(permissionSet);
info.addRoles(roleNameSet);
return info;
}
Aggregations