当前位置: 首页>>代码示例>>Java>>正文


Java AuthorityUtils.authorityListToSet方法代码示例

本文整理汇总了Java中org.springframework.security.core.authority.AuthorityUtils.authorityListToSet方法的典型用法代码示例。如果您正苦于以下问题:Java AuthorityUtils.authorityListToSet方法的具体用法?Java AuthorityUtils.authorityListToSet怎么用?Java AuthorityUtils.authorityListToSet使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.security.core.authority.AuthorityUtils的用法示例。


在下文中一共展示了AuthorityUtils.authorityListToSet方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onAuthenticationSuccess

import org.springframework.security.core.authority.AuthorityUtils; //导入方法依赖的package包/类
@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
		Authentication authentication) throws IOException {

	String targetUrl = "/";

	Set<String> authorities = AuthorityUtils.authorityListToSet(authentication.getAuthorities());

	if (authorities.contains("ROLE_OWNER")) {
		targetUrl = "/owner";
	} else if (authorities.contains("ROLE_CLIENT")) {
		targetUrl = "/client";
	} else if (authorities.contains("ROLE_RECEPTION")) {
		targetUrl = "/reception";
	} else {
		throw new IllegalStateException("Niedozwolona rola użytkownika!");
	}

	if (response.isCommitted())
		return;

	redirectStrategy.sendRedirect(request, response, targetUrl);

}
 
开发者ID:marcin-pwr,项目名称:hotel,代码行数:25,代码来源:AuthenticationSuccessHandlerImpl.java

示例2: correctlyExtractsNamedAttributeFromAssertionAndConvertsThemToAuthorities

import org.springframework.security.core.authority.AuthorityUtils; //导入方法依赖的package包/类
@Test
public void correctlyExtractsNamedAttributeFromAssertionAndConvertsThemToAuthorities() {
    GrantedAuthorityFromMemberOfAssertionAttributeUserDetailsService uds
            = new GrantedAuthorityFromMemberOfAssertionAttributeUserDetailsService();
    uds.setConvertToUpperCase(false);
    uds.setConvertSpacesToUnderscores(false);
    uds.setAttribute("a");
    uds.setRolePrefix("");
    Assertion assertion = mock(Assertion.class);
    AttributePrincipal principal = mock(AttributePrincipal.class);
    Map<String, Object> attributes = new HashMap<>();
    attributes.put("a", Arrays.asList("CN=role_a1,OU=roles,DC=spring,DC=io", "CN=role_a2,OU=roles,DC=spring,DC=io"));
    attributes.put("b", "b");
    attributes.put("c", "c");
    attributes.put("d", null);
    attributes.put("someother", "unused");
    when(assertion.getPrincipal()).thenReturn(principal);
    when(principal.getAttributes()).thenReturn(attributes);
    when(principal.getName()).thenReturn("somebody");
    CasAssertionAuthenticationToken token = new CasAssertionAuthenticationToken(assertion, "ticket");
    UserDetails user = uds.loadUserDetails(token);
    Set<String> roles = AuthorityUtils.authorityListToSet(user.getAuthorities());
    assertTrue(roles.size() == 2);
    assertTrue(roles.contains("role_a1"));
    assertTrue(roles.contains("role_a2"));
}
 
开发者ID:acu-dev,项目名称:spring-security-cas-memberOf-roles,代码行数:27,代码来源:GrantedAuthorityFromMemberOfAssertionAttributeUserDetailsServiceTest.java

示例3: correctlyExtractsDefaultNamedAttributeFromAssertionAndConvertsThemToAuthorities

import org.springframework.security.core.authority.AuthorityUtils; //导入方法依赖的package包/类
@Test
public void correctlyExtractsDefaultNamedAttributeFromAssertionAndConvertsThemToAuthorities() {
    GrantedAuthorityFromMemberOfAssertionAttributeUserDetailsService uds
            = new GrantedAuthorityFromMemberOfAssertionAttributeUserDetailsService();
    Assertion assertion = mock(Assertion.class);
    AttributePrincipal principal = mock(AttributePrincipal.class);
    Map<String, Object> attributes = new HashMap<>();
    attributes.put("memberOf", Arrays.asList("CN=a1,ou=other,OU=roles,DC=spring,DC=io", "CN=a2,OU=roles,dc=spring,DC=io", null));
    attributes.put("someother", "unused");
    when(assertion.getPrincipal()).thenReturn(principal);
    when(principal.getAttributes()).thenReturn(attributes);
    when(principal.getName()).thenReturn("somebody");
    CasAssertionAuthenticationToken token = new CasAssertionAuthenticationToken(assertion, "ticket");
    UserDetails user = uds.loadUserDetails(token);
    Set<String> roles = AuthorityUtils.authorityListToSet(user.getAuthorities());
    assertTrue(roles.size() == 2);
    assertTrue(roles.contains("ROLE_A1"));
    assertTrue(roles.contains("ROLE_A2"));
}
 
开发者ID:acu-dev,项目名称:spring-security-cas-memberOf-roles,代码行数:20,代码来源:GrantedAuthorityFromMemberOfAssertionAttributeUserDetailsServiceTest.java

示例4: clientHasAnyRole

import org.springframework.security.core.authority.AuthorityUtils; //导入方法依赖的package包/类
public static boolean clientHasAnyRole(Authentication authentication, String... roles) {
	if (authentication instanceof OAuth2Authentication) {
		OAuth2Request clientAuthentication = ((OAuth2Authentication) authentication).getOAuth2Request();
		Collection<? extends GrantedAuthority> clientAuthorities = clientAuthentication.getAuthorities();
		if (clientAuthorities != null) {
			Set<String> roleSet = AuthorityUtils.authorityListToSet(clientAuthorities);
			for (String role : roles) {
				if (roleSet.contains(role)) {
					return true;
				}
			}
		}
	}

	return false;
}
 
开发者ID:jungyang,项目名称:oauth-client-master,代码行数:17,代码来源:OAuth2ExpressionUtils.java

示例5: consumerHasAnyRole

import org.springframework.security.core.authority.AuthorityUtils; //导入方法依赖的package包/类
public static boolean consumerHasAnyRole(SecurityExpressionRoot root, String... roles) {
	Authentication authentication = root.getAuthentication();
	if (authentication.getDetails() instanceof OAuthAuthenticationDetails) {
		OAuthAuthenticationDetails details = (OAuthAuthenticationDetails) authentication.getDetails();
		List<GrantedAuthority> consumerAuthorities = details.getConsumerDetails().getAuthorities();
		if (consumerAuthorities != null) {
			Set<String> roleSet = AuthorityUtils.authorityListToSet(consumerAuthorities);
			for (String role : roles) {
				if (roleSet.contains(role)) {
					return true;
				}
			}
		}
	}

	return false;
}
 
开发者ID:jungyang,项目名称:oauth-client-master,代码行数:18,代码来源:OAuthMethodSecurityExpressionHandler.java

示例6: getTimeToLive

import org.springframework.security.core.authority.AuthorityUtils; //导入方法依赖的package包/类
private Optional<Seconds> getTimeToLive(final Authentication successfulAuthentication) {
    final UserInfo userInfo = UserInfo.extractFrom(successfulAuthentication);
    final Set<String> roles = AuthorityUtils.authorityListToSet(userInfo.getAuthorities());

    if (roles.contains(SystemUser.Role.ROLE_REST.name())) {
        return Optional.empty();
    } else if (roles.contains(SystemUser.Role.ROLE_ADMIN.name()) ||
            roles.contains(SystemUser.Role.ROLE_MODERATOR.name())) {
        return Optional.of(securityConfigurationProperties.getRemeberMeTimeToLiveForModerator());
    } else if (roles.contains(SystemUser.Role.ROLE_USER.name())) {
        return Optional.of(securityConfigurationProperties.getRememberMeTimeToLive());
    }

    return Optional.empty();
}
 
开发者ID:suomenriistakeskus,项目名称:oma-riista-web,代码行数:16,代码来源:CustomSpringSessionRememberMeServices.java

示例7: vote

import org.springframework.security.core.authority.AuthorityUtils; //导入方法依赖的package包/类
public int vote(Authentication authentication, Object object, Collection<ConfigAttribute> attributes) {

		int result = ACCESS_ABSTAIN;

		if (!(authentication instanceof OAuth2Authentication)) {
			return result;
		}

		OAuth2Authentication oauth2Authentication = (OAuth2Authentication) authentication;
		OAuth2Request clientAuthentication = oauth2Authentication.getOAuth2Request();
		ClientDetails client = clientDetailsService.loadClientByClientId(clientAuthentication.getClientId());
		Set<String> scopes = clientAuthentication.getScope();
		if (oauth2Authentication.isClientOnly() && clientAuthoritiesAreScopes) {
			scopes = AuthorityUtils.authorityListToSet(clientAuthentication.getAuthorities());
		}

		for (ConfigAttribute attribute : attributes) {
			if (this.supports(attribute)) {

				result = ACCESS_GRANTED;

				for (String scope : scopes) {
					if (!client.getScope().contains(scope)) {
						result = ACCESS_DENIED;
						break;
					}
				}

				if (result == ACCESS_DENIED && throwException) {
					InsufficientScopeException failure = new InsufficientScopeException(
							"Insufficient scope for this resource", client.getScope());
					throw new AccessDeniedException(failure.getMessage(), failure);
				}

				return result;
			}
		}

		return result;
	}
 
开发者ID:jungyang,项目名称:oauth-client-master,代码行数:41,代码来源:ClientScopeVoter.java

示例8: hasAdminOrModeratorRole

import org.springframework.security.core.authority.AuthorityUtils; //导入方法依赖的package包/类
private static boolean hasAdminOrModeratorRole(final UserDetails userDetails) {
    final Set<String> roleNames = AuthorityUtils.authorityListToSet(userDetails.getAuthorities());
    return F.containsAny(roleNames, SystemUser.Role.ROLE_ADMIN.name(), SystemUser.Role.ROLE_MODERATOR.name());
}
 
开发者ID:suomenriistakeskus,项目名称:oma-riista-web,代码行数:5,代码来源:OneTimePasswordAuthenticationProvider.java

示例9: getAuthoritiesAsStrings

import org.springframework.security.core.authority.AuthorityUtils; //导入方法依赖的package包/类
@org.codehaus.jackson.annotate.JsonProperty("authorities")
@com.fasterxml.jackson.annotation.JsonProperty("authorities")
private List<String> getAuthoritiesAsStrings() {
    return new ArrayList<String>(
            AuthorityUtils.authorityListToSet(authorities));
}
 
开发者ID:imCodePartnerAB,项目名称:iVIS,代码行数:7,代码来源:JpaClientDetails.java

示例10: getAuthoritiesAsStrings

import org.springframework.security.core.authority.AuthorityUtils; //导入方法依赖的package包/类
@JsonProperty("authorities")
private List<String> getAuthoritiesAsStrings() {
	return new ArrayList<String>(AuthorityUtils.authorityListToSet(authorities));
}
 
开发者ID:jungyang,项目名称:oauth-client-master,代码行数:5,代码来源:BaseClientDetails.java


注:本文中的org.springframework.security.core.authority.AuthorityUtils.authorityListToSet方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。