Search in sources :

Example 1 with IShiro

use of com.ikoori.vip.server.core.shiro.factory.IShiro 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;
}
Also used : SimpleAuthorizationInfo(org.apache.shiro.authz.SimpleAuthorizationInfo) IShiro(com.ikoori.vip.server.core.shiro.factory.IShiro) HashSet(java.util.HashSet)

Example 2 with IShiro

use of com.ikoori.vip.server.core.shiro.factory.IShiro in project vip by guangdada.

the class ShiroDbRealm method doGetAuthenticationInfo.

/**
 * 登录认证
 */
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken) throws AuthenticationException {
    IShiro shiroFactory = ShiroFactroy.me();
    UsernamePasswordToken token = (UsernamePasswordToken) authcToken;
    User user = shiroFactory.user(token.getUsername());
    ShiroUser shiroUser = shiroFactory.shiroUser(user);
    SimpleAuthenticationInfo info = shiroFactory.info(shiroUser, user, super.getName());
    return info;
}
Also used : User(com.ikoori.vip.common.persistence.model.User) SimpleAuthenticationInfo(org.apache.shiro.authc.SimpleAuthenticationInfo) IShiro(com.ikoori.vip.server.core.shiro.factory.IShiro) UsernamePasswordToken(org.apache.shiro.authc.UsernamePasswordToken)

Aggregations

IShiro (com.ikoori.vip.server.core.shiro.factory.IShiro)2 User (com.ikoori.vip.common.persistence.model.User)1 HashSet (java.util.HashSet)1 SimpleAuthenticationInfo (org.apache.shiro.authc.SimpleAuthenticationInfo)1 UsernamePasswordToken (org.apache.shiro.authc.UsernamePasswordToken)1 SimpleAuthorizationInfo (org.apache.shiro.authz.SimpleAuthorizationInfo)1