Example usage for org.apache.shiro.authz SimpleAuthorizationInfo SimpleAuthorizationInfo

List of usage examples for org.apache.shiro.authz SimpleAuthorizationInfo SimpleAuthorizationInfo

Introduction

In this page you can find the example usage for org.apache.shiro.authz SimpleAuthorizationInfo SimpleAuthorizationInfo.

Prototype

public SimpleAuthorizationInfo() 

Source Link

Document

Default no-argument constructor.

Usage

From source file:$.ShiroDbRealm.java

License:Apache License

/**
     * ?, ???./*from   www .  j a  v  a  2s  .  c om*/
     */
    @Override
    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
        ShiroUser shiroUser = (ShiroUser) principals.getPrimaryPrincipal();
        User user = accountService.findUserByLoginName(shiroUser.loginName);
        SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
        info.addRoles(user.getRoleList());
        return info;
    }

From source file:action.ShiroDbRealm.java

License:Apache License

/**
 * ?, ???.//from   w w w .j  a  va2s.  c  o m
 */
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
    ShiroUser shiroUser = (ShiroUser) principals.getPrimaryPrincipal();

    SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
    // roles
    List<Role> roles = roleService.getByUserId(shiroUser.id);
    List<String> stringRoles = new ArrayList<String>(roles.size());
    for (Role role : roles) {
        stringRoles.add(role.getName());
    }
    info.addRoles(stringRoles);

    // permissions
    List<Permission> permissions = permissionService.getByUserId(shiroUser.id);
    Set<String> stringPermissions = new HashSet<String>(permissions.size());
    for (Permission permission : permissions) {
        stringPermissions.add(permission.getValue());
    }
    info.setStringPermissions(stringPermissions);

    return info;
}

From source file:annis.security.ANNISUserRealm.java

License:Apache License

@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);//from  w  ww  . j a  v  a 2  s  .co m

            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;
}

From source file:apm.modules.sys.security.SystemAuthorizingRealm.java

License:Open Source License

/**
 * ?, ???//w  w  w  . jav  a  2s .c  o m
 */
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
    Principal principal = (Principal) getAvailablePrincipal(principals);
    User user = getUserService().findByLoginName(principal.getLoginName());
    if (user != null) {
        Users.putCache("user", user);
        SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
        List<Menu> list = Users.getMenuList();
        for (Menu menu : list) {
            if (StringUtils.isNotBlank(menu.getPermission())) {
                // Permission???
                info.addStringPermission(menu.getPermission());
            }
        }
        // IP
        getUserService().updateUserLoginInfo(user.getId());
        return info;
    } else {
        return null;
    }
}

From source file:au.org.theark.core.security.AAFRealm.java

License:Open Source License

@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
    SimpleAuthorizationInfo simpleAuthInfo = new SimpleAuthorizationInfo();

    // Get the logged in user name from Shiro Session
    String ldapUserName = (String) principals.getPrimaryPrincipal();

    Long sessionStudyId = (Long) SecurityUtils.getSubject().getSession()
            .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID);
    Long sessionFunctionId = (Long) SecurityUtils.getSubject().getSession()
            .getAttribute(au.org.theark.core.Constants.ARK_FUNCTION_KEY);
    Long sessionModuleId = (Long) SecurityUtils.getSubject().getSession()
            .getAttribute(au.org.theark.core.Constants.ARK_MODULE_KEY);

    try {//from www. ja v a2 s. c o  m

        if (sessionModuleId != null && sessionFunctionId != null && sessionStudyId == null) {
            // Load the role for the given module and use case
            ArkFunction arkFunction = iArkCommonService.getArkFunctionById(sessionFunctionId);
            ArkModule arkModule = iArkCommonService.getArkModuleById(sessionModuleId);

            String role = iArkCommonService.getUserRole(ldapUserName, arkFunction, arkModule, null);
            simpleAuthInfo.addRole(role);

            /* Check if the logged in user is a Super Administrator */
            if (iArkCommonService.isSuperAdministator(ldapUserName, arkFunction, arkModule)) {

                java.util.Collection<String> userRolePermission = iArkCommonService.getArkRolePermission(role);
                simpleAuthInfo.addStringPermissions(userRolePermission);
            } else {
                if (role != null) {
                    java.util.Collection<String> userRolePermission = iArkCommonService
                            .getArkRolePermission(arkFunction, role, arkModule);
                    simpleAuthInfo.addStringPermissions(userRolePermission);
                }
            }
        } else if (sessionModuleId != null && sessionFunctionId != null && sessionStudyId != null) {
            // Get the roles for the study in context
            Study study = iArkCommonService.getStudy(sessionStudyId);
            ArkFunction arkFunction = iArkCommonService.getArkFunctionById(sessionFunctionId);
            ArkModule arkModule = iArkCommonService.getArkModuleById(sessionModuleId);
            String role = iArkCommonService.getUserRole(ldapUserName, arkFunction, arkModule, study);
            simpleAuthInfo.addRole(role);

            if (iArkCommonService.isSuperAdministator(ldapUserName, arkFunction, arkModule)) {
                java.util.Collection<String> userRolePermission = iArkCommonService.getArkRolePermission(role);
                simpleAuthInfo.addStringPermissions(userRolePermission);
            } else {
                if (role != null) {
                    java.util.Collection<String> userRolePermission = iArkCommonService
                            .getArkRolePermission(arkFunction, role, arkModule);
                    simpleAuthInfo.addStringPermissions(userRolePermission);
                }
            }
        }
    } catch (EntityNotFoundException e) {
        log.error(e.getMessage());
    }

    return simpleAuthInfo;
}

From source file:au.org.theark.core.security.ArkLdapRealm.java

License:Open Source License

protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
    SimpleAuthorizationInfo simpleAuthInfo = new SimpleAuthorizationInfo();

    // Get the logged in user name from Shiro Session
    String ldapUserName = (String) principals.getPrimaryPrincipal();

    Long sessionStudyId = (Long) SecurityUtils.getSubject().getSession()
            .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID);
    Long sessionFunctionId = (Long) SecurityUtils.getSubject().getSession()
            .getAttribute(au.org.theark.core.Constants.ARK_FUNCTION_KEY);
    Long sessionModuleId = (Long) SecurityUtils.getSubject().getSession()
            .getAttribute(au.org.theark.core.Constants.ARK_MODULE_KEY);

    try {/*  w ww  . ja  v  a2  s.c om*/

        if (sessionModuleId != null && sessionFunctionId != null && sessionStudyId == null) {
            // Load the role for the given module and use case
            ArkFunction arkFunction = iArkCommonService.getArkFunctionById(sessionFunctionId);
            ArkModule arkModule = iArkCommonService.getArkModuleById(sessionModuleId);

            String role = iArkCommonService.getUserRole(ldapUserName, arkFunction, arkModule, null);
            simpleAuthInfo.addRole(role);

            /*//Add multiple roles
            iArkCommonService.getArkRoleListByUserAndStudy(arkUserVo, study);
            simpleAuthInfo.addRoles(roles);*/

            /* Check if the logged in user is a Super Administrator */
            if (iArkCommonService.isSuperAdministator(ldapUserName, arkFunction, arkModule)) {

                java.util.Collection<String> userRolePermission = iArkCommonService.getArkRolePermission(role);
                simpleAuthInfo.addStringPermissions(userRolePermission);
            } else {
                if (role != null) {
                    java.util.Collection<String> userRolePermission = iArkCommonService
                            .getArkRolePermission(arkFunction, role, arkModule);
                    simpleAuthInfo.addStringPermissions(userRolePermission);
                }
            }
        } else if (sessionModuleId != null && sessionFunctionId != null && sessionStudyId != null) {
            // Get the roles for the study in context
            Study study = iArkCommonService.getStudy(sessionStudyId);
            ArkFunction arkFunction = iArkCommonService.getArkFunctionById(sessionFunctionId);
            ArkModule arkModule = iArkCommonService.getArkModuleById(sessionModuleId);
            String role = iArkCommonService.getUserRole(ldapUserName, arkFunction, arkModule, study);
            simpleAuthInfo.addRole(role);

            if (iArkCommonService.isSuperAdministator(ldapUserName, arkFunction, arkModule)) {
                java.util.Collection<String> userRolePermission = iArkCommonService.getArkRolePermission(role);
                simpleAuthInfo.addStringPermissions(userRolePermission);
            } else {
                if (role != null) {
                    java.util.Collection<String> userRolePermission = iArkCommonService
                            .getArkRolePermission(arkFunction, role, arkModule);
                    simpleAuthInfo.addStringPermissions(userRolePermission);
                }
            }
        }

    } catch (EntityNotFoundException e) {
        log.error(e.getMessage());
    }

    return simpleAuthInfo;
}

From source file:b4f.seguridad.ShiroAuthorizingRealm.java

public AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {

    System.out.println("ShiroAuthorizingRealm.doGetAuthorizationInfo()");

    String userName = (String) (principals.fromRealm(getName()).iterator().next());
    Usuario user;//from  w  ww  .  ja  va  2  s. co m
    try {
        user = UsersManager.getUser(userName);
    } catch (Exception ex) {
        throw new RuntimeException("Error looking up user " + userName, ex);
    }

    if (user != null) {
        List<String> roles;
        try {
            //TODO IMPLEMENTAR ROLES
            roles = new ArrayList<>();
            //                roles = umgr.getRoles(user);
        } catch (Exception ex) {
            throw new RuntimeException("Error looking up roles for user " + userName, ex);
        }
        SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
        for (String role : roles) {
            info.addRole(role);
        }
        System.out.println("Returning " + roles.size() + " roles for user " + userName + " roles= " + roles);
        return info;

    } else {
        throw new RuntimeException("Usuarioname not found: " + userName);
    }
}

From source file:cc.rainier.fss.service.account.ShiroDbRealm.java

License:Apache License

/**
 * ?, ???.//from  ww w. ja v  a  2s . c  o m
 */
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
    ShiroUser shiroUser = (ShiroUser) principals.getPrimaryPrincipal();
    User user = accountService.findUserByLoginName(shiroUser.loginName);
    SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
    info.addRoles(user.getRoleList());
    return info;
}

From source file:cc.sion.base.auth.shiro.ShiroDbRealm.java

License:Apache License

@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
    String loginName = principals.getPrimaryPrincipal().toString();//?
    System.out.println("===user name:" + loginName);
    SysUser user = accountService.findUserByLoginName(loginName);
    SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
    info.addRoles(user.getRoleList());//  www . j  av a2s. co m
    return info;
}

From source file:cn.com.axiom.system.security.ShiroDbRealm.java

License:Apache License

/**
 * ?, ???.//  ww w  .  j  a v a2 s.c o m
 */
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
    // ShiroUser shiroUser = (ShiroUser) principals.getPrimaryPrincipal();
    // User user = userService.findUserByUserName(shiroUser.loginName);

    SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
    // Set<String> permissions = Sets.newHashSet();
    // for (Role role : user.getRoles()) {
    // //Role???
    // if (role!=null) {
    // info.addRole(role.getName());
    // //Permission???
    // for(Permission permission : role.getPermissions()){
    // permissions.add(permission.getLink());
    // }
    // info.addStringPermissions(permissions);
    // }
    // }
    return info;
}