Search in sources :

Example 26 with SimpleAuthorizationInfo

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;
}
Also used : SimpleAuthorizationInfo(org.apache.shiro.authz.SimpleAuthorizationInfo)

Example 27 with SimpleAuthorizationInfo

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;
}
Also used : SimpleAuthorizationInfo(org.apache.shiro.authz.SimpleAuthorizationInfo)

Example 28 with SimpleAuthorizationInfo

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;
}
Also used : Role(com.moon.admin.domain.Role) SimpleAuthorizationInfo(org.apache.shiro.authz.SimpleAuthorizationInfo) User(com.moon.admin.domain.User) RoleDao(com.moon.admin.dao.RoleDao) PermissionDao(com.moon.admin.dao.PermissionDao) Permission(com.moon.admin.domain.Permission)

Example 29 with SimpleAuthorizationInfo

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;
}
Also used : SimpleAuthorizationInfo(org.apache.shiro.authz.SimpleAuthorizationInfo) SysRole(com.neo.entity.SysRole) UserInfo(com.neo.entity.UserInfo) SysPermission(com.neo.entity.SysPermission)

Example 30 with SimpleAuthorizationInfo

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;
}
Also used : User(com.fruit.manage.model.User) SimpleAuthorizationInfo(org.apache.shiro.authz.SimpleAuthorizationInfo)

Aggregations

SimpleAuthorizationInfo (org.apache.shiro.authz.SimpleAuthorizationInfo)48 Permission (org.apache.shiro.authz.Permission)8 AuthorizationException (org.apache.shiro.authz.AuthorizationException)6 KeyValueCollectionPermission (ddf.security.permission.KeyValueCollectionPermission)5 KeyValuePermission (ddf.security.permission.KeyValuePermission)5 ArrayList (java.util.ArrayList)5 HashSet (java.util.HashSet)5 AuthenticationException (org.apache.shiro.authc.AuthenticationException)5 AuthorizationInfo (org.apache.shiro.authz.AuthorizationInfo)5 KeyValuePermissionImpl (ddf.security.permission.impl.KeyValuePermissionImpl)4 CollectionPermission (ddf.security.permission.CollectionPermission)3 HashMap (java.util.HashMap)3 PrincipalCollection (org.apache.shiro.subject.PrincipalCollection)3 Group (com.ganster.cms.core.pojo.Group)2 Permission (com.ganster.cms.core.pojo.Permission)2 User (com.ganster.cms.core.pojo.User)2 UserExample (com.ganster.cms.core.pojo.UserExample)2 TbRolePermission (com.netsteadfast.greenstep.po.hbm.TbRolePermission)2 TbUserRole (com.netsteadfast.greenstep.po.hbm.TbUserRole)2 Set (java.util.Set)2