use of org.apache.shiro.authz.SimpleAuthorizationInfo in project ssm_shiro_blog by Mandelo.
the class MyRealm method doGetAuthorizationInfo.
/**
* 登录之后用于授权
*/
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
String username = (String) principals.getPrimaryPrincipal();
SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo();
authorizationInfo.setRoles(new HashSet<>(userExtendDao.getRoles(username)));
authorizationInfo.setStringPermissions(new HashSet<>(userExtendDao.getPermissions(username)));
return authorizationInfo;
}
use of org.apache.shiro.authz.SimpleAuthorizationInfo in project ANNIS by korpling.
the class ANNISUserRealm method doGetAuthorizationInfo.
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
Validate.isInstanceOf(String.class, principals.getPrimaryPrincipal());
String userName = (String) principals.getPrimaryPrincipal();
SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
User user = confManager.getUser(userName);
if (user != null) {
// only add any user role/permission if account is not expired
if (user.getExpires() == null || user.getExpires().isAfterNow()) {
info.addRole(userName);
info.addRoles(user.getGroups());
info.addRole(defaultUserRole);
// add the permission to create url short IDs from every IP
info.addStringPermission("shortener:create:*");
// add any manual given permissions
info.addStringPermissions(user.getPermissions());
}
} else if (userName.equals(anonymousUser)) {
info.addRole(anonymousUser);
if (confManager.getUseShortenerWithoutLogin() != null) {
// add the permission to create url short IDs from the trusted IPs
for (String trustedIPs : confManager.getUseShortenerWithoutLogin()) {
info.addStringPermission("shortener:create:" + trustedIPs.replaceAll("[.:]", "_"));
}
}
}
return info;
}
use of org.apache.shiro.authz.SimpleAuthorizationInfo in project moon by gentoo111.
the class ShiroRealm method doGetAuthorizationInfo.
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
log.debug("权限配置");
SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo();
User user = UserUtil.getCurrentUser();
List<Role> roles = SpringUtil.getBean(RoleDao.class).listByUserId(user.getId());
Set<String> roleNames = roles.stream().map(Role::getName).collect(Collectors.toSet());
authorizationInfo.setRoles(roleNames);
List<Permission> permissionList = SpringUtil.getBean(PermissionDao.class).listByUserId(user.getId());
UserUtil.setPermissionSession(permissionList);
Set<String> permissions = permissionList.stream().filter(p -> !StringUtils.isEmpty(p.getPermission())).map(Permission::getPermission).collect(Collectors.toSet());
authorizationInfo.setStringPermissions(permissions);
return authorizationInfo;
}
use of org.apache.shiro.authz.SimpleAuthorizationInfo in project spring-boot-examples by ityouknow.
the class MyShiroRealm method doGetAuthorizationInfo.
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
System.out.println("权限配置-->MyShiroRealm.doGetAuthorizationInfo()");
SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo();
UserInfo userInfo = (UserInfo) principals.getPrimaryPrincipal();
for (SysRole role : userInfo.getRoleList()) {
authorizationInfo.addRole(role.getRole());
for (SysPermission p : role.getPermissions()) {
authorizationInfo.addStringPermission(p.getPermission());
}
}
return authorizationInfo;
}
use of org.apache.shiro.authz.SimpleAuthorizationInfo in project fruit-manage by liuzhaozhao.
the class ShiroDbRealm method doGetAuthorizationInfo.
/**
* 权限认证
*
* @param principalCollection
* @return
*/
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
User user = (User) principals.getPrimaryPrincipal();
SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
if (user == null) {
return info;
}
int id = user.getId();
authRole(id, info);
return info;
}
Aggregations