本文整理匯總了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);
}
示例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;
}
示例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;
}
示例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;
}
示例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());
}
示例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));
}
示例10: getAuthoritiesAsStrings
import org.springframework.security.core.authority.AuthorityUtils; //導入方法依賴的package包/類
@JsonProperty("authorities")
private List<String> getAuthoritiesAsStrings() {
return new ArrayList<String>(AuthorityUtils.authorityListToSet(authorities));
}