當前位置: 首頁>>代碼示例>>Java>>正文


Java SimpleAuthorizationInfo.setStringPermissions方法代碼示例

本文整理匯總了Java中org.apache.shiro.authz.SimpleAuthorizationInfo.setStringPermissions方法的典型用法代碼示例。如果您正苦於以下問題:Java SimpleAuthorizationInfo.setStringPermissions方法的具體用法?Java SimpleAuthorizationInfo.setStringPermissions怎麽用?Java SimpleAuthorizationInfo.setStringPermissions使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.shiro.authz.SimpleAuthorizationInfo的用法示例。


在下文中一共展示了SimpleAuthorizationInfo.setStringPermissions方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: doGetAuthorizationInfo

import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
@SuppressWarnings("rawtypes")
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
	String username = (String) principals.getPrimaryPrincipal();
	SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo();
	// 根據用戶名查詢當前用戶擁有的角色
	List<Map> roles = userService.findRolesByUserName(username);
	Set<String> roleNames = new HashSet<String>();
	for (Map role : roles) {
		roleNames.add(role.get("name").toString());
	}
	// 將角色名稱提供給info
	authorizationInfo.setRoles(roleNames);
	// 根據用戶名查詢當前用戶權限
	List<Map> permissions = userService.findPermissionsByUserName(username);
	Set<String> permissionNames = new HashSet<String>();
	for (Map permission : permissions) {
		permissionNames.add(permission.get("name").toString());
	}
	// 將權限名稱提供給info
	authorizationInfo.setStringPermissions(permissionNames);

	return authorizationInfo;
}
 
開發者ID:phoenix-varus,項目名稱:jeeWe,代碼行數:24,代碼來源:UserRealm.java

示例2: doGetAuthorizationInfo

import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
/** 
   * 授權 
   */  
  @Override  
  protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {  
  	
  	//Long userId = TokenManager.getUserId();
  	User token = (User)SecurityUtils.getSubject().getPrincipal();
  	
SimpleAuthorizationInfo info =  new SimpleAuthorizationInfo();
//根據用戶ID查詢角色(role),放入到Authorization裏。
Set<String> roleName = roleService.findRoleNameByUserId(String.valueOf(token.getUuid()));
info.setRoles(roleName);
//根據用戶ID查詢權限(permission),放入到Authorization裏。
Set<String> permissions = permissionService.findPermissionByUserId(String.valueOf(token.getUuid()));
info.setStringPermissions(permissions);
      return info;  
  }
 
開發者ID:miracle857,項目名稱:weibo,代碼行數:19,代碼來源:SampleRealm.java

示例3: doGetAuthorizationInfo

import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection arg0)
{
    ShiroToken token = (ShiroToken) SecurityUtils.getSubject().getPrincipal();
    String username = token.getUsername();
    logger.info(username + "授權...");

    // 從數據庫中查找該用戶的角色和權限
    SimpleAuthorizationInfo sainfo = new SimpleAuthorizationInfo();

    Set<String> roles = new HashSet<String>();
    roles.add("admin");
    //roles.add("role1");
    Set<String> permissions = new HashSet<String>();
    permissions.add("add");
    permissions.add("delete");
    sainfo.setRoles(roles);
    sainfo.setStringPermissions(permissions);
    return sainfo;
}
 
開發者ID:peterchenhdu,項目名稱:spring-shiro-demo,代碼行數:21,代碼來源:UserRealm.java

示例4: doGetAuthorizationInfo

import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
    // 根據用戶名查找角色,請根據需求實現
    String username = (String) principals.getPrimaryPrincipal();

    User user = userService.findByName(username);
    SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo();

    SimplePrincipalCollection principalCollection = (SimplePrincipalCollection) principals;
    principalCollection.clear();
    principalCollection.add(user, getName());

    RolePermission rolePermission = user.new RolePermission();
    authorizationInfo.setRoles(rolePermission.getRoleSet());
    authorizationInfo.setStringPermissions(rolePermission.getPermissionSet());
    return authorizationInfo;
}
 
開發者ID:howiefh,項目名稱:jee-restful-web,代碼行數:18,代碼來源:StatelessRealm.java

示例5: doGetAuthorizationInfo

import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
  //null usernames are invalid
  if (principals == null) {
    throw new AuthorizationException("PrincipalCollection method argument cannot be null.");
  }
  String username = (String) getAvailablePrincipal(principals);

  java.util.Set<String> roles = redisManager.smembers(user_roles_KeyPrefix + username);

  SimpleAuthorizationInfo info = new SimpleAuthorizationInfo(roles);

  if (permissionsLookupEnabled) {
    java.util.List<java.lang.String> permissionsList = redisManager.hmget(roles_permissions_Key, roles.toArray(new String[0]));
    Set<String> permissionsSet = new HashSet<String>(permissionsList.size());
    permissionsSet.addAll(permissionsList);
    info.setStringPermissions(permissionsSet);
  }

  return info;
}
 
開發者ID:wjw465150,項目名稱:shiro-redis,代碼行數:23,代碼來源:RedisRealm.java

示例6: doGetAuthorizationInfo

import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
/**
 *
 * @param principalCollection
 * @return
 */
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {

    final User user = (User) this.getAvailablePrincipal(principalCollection);

    final List<GroupPermission> permissions = this.accountService
            .loadUserPermissions(user.getUsername());

    final Set<String> keys = permissions
            .parallelStream()
            .map(GroupPermission::getPermissionKey)
            .collect(Collectors.toSet());

    // creates the basic authorization info
    final SimpleAuthorizationInfo authInfo = new SimpleAuthorizationInfo();

    authInfo.setStringPermissions(keys);

    return authInfo;
}
 
開發者ID:arthurgregorio,項目名稱:exemplos,代碼行數:26,代碼來源:SecurityRealm.java

示例7: queryForAuthorizationInfo

import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
/**
* 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
public AuthorizationInfo queryForAuthorizationInfo(final PrincipalCollection principals,
    final LdapContextFactory ldapContextFactory) throws NamingException {
  if (!isAuthorizationEnabled()) {
    return null;
  }
  final Set<String> roleNames = getRoles(principals, ldapContextFactory);
  if (log.isDebugEnabled()) {
    log.debug("RolesNames Authorization: " + roleNames);
  }
  SimpleAuthorizationInfo simpleAuthorizationInfo = new SimpleAuthorizationInfo(roleNames);
  Set<String> stringPermissions = permsFor(roleNames);
  simpleAuthorizationInfo.setStringPermissions(stringPermissions);
  return simpleAuthorizationInfo;
}
 
開發者ID:apache,項目名稱:zeppelin,代碼行數:29,代碼來源:LdapRealm.java

示例8: doGetAuthorizationInfo

import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
/**
 * 授權
 */
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
	String username = (String) principals.getPrimaryPrincipal();
	CmsUser user = cmsUserMng.findByUsername(username);
	CmsSite site=CmsThreadVariable.getSite();
	SimpleAuthorizationInfo auth = new SimpleAuthorizationInfo();
	if (user != null) {
		Set<String>viewPermissionSet=new HashSet<String>();
		Set<String> perms = user.getPerms(site.getId(),viewPermissionSet);
		if (!CollectionUtils.isEmpty(perms)) {
			// 權限加入AuthorizationInfo認證對象
			auth.setStringPermissions(perms);
		}
	}
	return auth;
}
 
開發者ID:huanzhou,項目名稱:jeecms6,代碼行數:19,代碼來源:CmsAuthorizingRealm.java

示例9: getAuthorizationInfo

import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
public AuthorizationInfo getAuthorizationInfo(final String login) {
  final SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
  
  final UserEntity userEntity = userRepository.findByLogin(login);
  if(userEntity == null) {
    throw new UnknownAccountException("Account does not exist");
  }
  
  final Set<String> permissionNames = new LinkedHashSet<>();
  final Set<PermissionEntity> permissions = this.getUserPermissions(userEntity);

  for (PermissionEntity permission : permissions) {
    permissionNames.add(permission.getValue());
  }

  info.setStringPermissions(permissionNames);
  return info;
}
 
開發者ID:OHDSI,項目名稱:WebAPI,代碼行數:19,代碼來源:PermissionManager.java

示例10: doGetAuthorizationInfo

import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
@Override
protected AuthorizationInfo doGetAuthorizationInfo(
        final PrincipalCollection principals) {
    // retrieve role names and permission names
    final String email = (String) principals.getPrimaryPrincipal();
    final User user = userRepository.findByEmailAndActive(email, true);
    if (user == null) {
        throw new UnknownAccountException("Account does not exist");
    }
    final int totalRoles = user.getRoles().size();
    final Set<String> roleNames = new LinkedHashSet<>(totalRoles);
    final Set<String> permissionNames = new LinkedHashSet<>();
    if (totalRoles > 0) {
        for (Role role : user.getRoles()) {
            roleNames.add(role.getName());
            for (Permission permission : role.getPermissions()) {
                permissionNames.add(permission.getName());
            }
        }
    }
    final SimpleAuthorizationInfo info = new SimpleAuthorizationInfo(roleNames);
    info.setStringPermissions(permissionNames);
    return info;
}
 
開發者ID:pires,項目名稱:spring-boot-shiro-orientdb,代碼行數:25,代碼來源:OrientDbRealm.java

示例11: doGetAuthorizationInfo

import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {

    LOGGER.debug("StatelessRealm doGetAuthenticationInfo");
    String accessToken = (String) getAvailablePrincipal(principalCollection);
    StatelessUser user = authService.getUser(accessToken);
    Set<String> roleNames = new LinkedHashSet<String>();
    for (SysRole sysRole : user.getRoles()) {
        roleNames.add(sysRole.getRoleName());
    }

    Set<String> permissions = authService.getPermissions(user.getUserId());
    SimpleAuthorizationInfo info = new SimpleAuthorizationInfo(roleNames);
    info.setStringPermissions(permissions);
    return info;
}
 
開發者ID:edgar615,項目名稱:javase-study,代碼行數:17,代碼來源:StatelessRealm.java

示例12: doGetAuthorizationInfo

import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
    User user = (User)principals.getPrimaryPrincipal();
    user = userService.get(user.getId());

    SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo();

    Set<String> stringPermissions = new HashSet<>();
    if (user.getRoles() != null && user.getRoles().size() > 0) {
        List<Role> roles = user.getRoles();
        for (Role role : roles) {
            if (role.getResources() != null && role.getResources().size() > 0) {
                for (Resource resource : role.getResources()) {
                    if (resource.getValid() == EnableDisableStatus.ENABLE && !StringUtils.isEmpty(resource.getIdentifier())) {
                        stringPermissions.add(resource.getIdentifier());
                    }
                }
            }
        }
    }

    authorizationInfo.setStringPermissions(stringPermissions);
    return authorizationInfo;
}
 
開發者ID:qatang,項目名稱:ctm,代碼行數:25,代碼來源:UserRealm.java

示例13: doGetAuthorizationInfo

import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
@Override
protected AuthorizationInfo doGetAuthorizationInfo(final PrincipalCollection principals) {
	LOG.debug("Checking doGetAuthorizationInfo for {}", principals);
	// null usernames are invalid
	if (principals == null) {
		throw new AuthorizationException("PrincipalCollection method argument cannot be null.");
	}

	final SimpleAuthorizationInfo info = new SimpleAuthorizationInfo(UserRole.ALL_ROLES);

	final String email = (String) getAvailablePrincipal(principals);
	final User user = userDao.findByEmail(email);

	if (user == null) {
		throw new UnknownAccountException("No user found with email: " + email);
	}

	final Set<String> userRoles = UserRole.getRolesFor(user);
	info.setStringPermissions(userRoles);
	LOG.debug("User {} was assigned permissions: {}", email, userRoles);
	return info;
}
 
開發者ID:devhub-tud,項目名稱:devhub-prototype,代碼行數:23,代碼來源:UserValidator.java

示例14: doGetAuthorizationInfo

import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
/**
 * 對用戶權限進行判定
 *
 * @param principals
 * @return
 */
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
    String username = (String) principals.getPrimaryPrincipal();
    SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo();
    authorizationInfo.setRoles(adminService.findRoles(username));
    authorizationInfo.setStringPermissions(adminService.findPermissions(username));
    return authorizationInfo;
}
 
開發者ID:melonlee,項目名稱:LazyAdmin,代碼行數:15,代碼來源:UserRealm.java

示例15: doGetAuthorizationInfo

import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
/**
 * 授權(驗證權限時調用)
 */
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
    SysUserEntity user = (SysUserEntity)principals.getPrimaryPrincipal();
    Long userId = user.getUserId();

    //用戶權限列表
    Set<String> permsSet = shiroService.getUserPermissions(userId);

    SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
    info.setStringPermissions(permsSet);
    return info;
}
 
開發者ID:zhaoqicheng,項目名稱:renren-fast,代碼行數:16,代碼來源:OAuth2Realm.java


注:本文中的org.apache.shiro.authz.SimpleAuthorizationInfo.setStringPermissions方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。