use of org.springframework.security.oauth2.server.resource.authentication.JwtGrantedAuthoritiesConverter in project spring-security by spring-projects.
the class JwtGrantedAuthoritiesConverterTests method convertWithBlankAsCustomAuthorityPrefixWhenTokenHasScopeAttributeThenTranslatedToAuthorities.
@Test
public void convertWithBlankAsCustomAuthorityPrefixWhenTokenHasScopeAttributeThenTranslatedToAuthorities() {
// @formatter:off
Jwt jwt = TestJwts.jwt().claim("scope", "message:read message:write").build();
// @formatter:on
JwtGrantedAuthoritiesConverter jwtGrantedAuthoritiesConverter = new JwtGrantedAuthoritiesConverter();
jwtGrantedAuthoritiesConverter.setAuthorityPrefix("");
Collection<GrantedAuthority> authorities = jwtGrantedAuthoritiesConverter.convert(jwt);
assertThat(authorities).containsExactly(new SimpleGrantedAuthority("message:read"), new SimpleGrantedAuthority("message:write"));
}
use of org.springframework.security.oauth2.server.resource.authentication.JwtGrantedAuthoritiesConverter in project spring-security by spring-projects.
the class JwtGrantedAuthoritiesConverterTests method convertWhenTokenHasEmptyScopeAndNonEmptyScpThenScopeAttributeIsTranslatedToNoAuthorities.
@Test
public void convertWhenTokenHasEmptyScopeAndNonEmptyScpThenScopeAttributeIsTranslatedToNoAuthorities() {
// @formatter:off
Jwt jwt = TestJwts.jwt().claim("scp", Arrays.asList("message:read", "message:write")).claim("scope", "").build();
// @formatter:on
JwtGrantedAuthoritiesConverter jwtGrantedAuthoritiesConverter = new JwtGrantedAuthoritiesConverter();
Collection<GrantedAuthority> authorities = jwtGrantedAuthoritiesConverter.convert(jwt);
assertThat(authorities).isEmpty();
}
use of org.springframework.security.oauth2.server.resource.authentication.JwtGrantedAuthoritiesConverter in project spring-security by spring-projects.
the class JwtGrantedAuthoritiesConverterTests method convertWithCustomAuthorityPrefixWhenTokenHasScopeAttributeThenTranslatedToAuthorities.
@Test
public void convertWithCustomAuthorityPrefixWhenTokenHasScopeAttributeThenTranslatedToAuthorities() {
// @formatter:off
Jwt jwt = TestJwts.jwt().claim("scope", "message:read message:write").build();
// @formatter:on
JwtGrantedAuthoritiesConverter jwtGrantedAuthoritiesConverter = new JwtGrantedAuthoritiesConverter();
jwtGrantedAuthoritiesConverter.setAuthorityPrefix("ROLE_");
Collection<GrantedAuthority> authorities = jwtGrantedAuthoritiesConverter.convert(jwt);
assertThat(authorities).containsExactly(new SimpleGrantedAuthority("ROLE_message:read"), new SimpleGrantedAuthority("ROLE_message:write"));
}
use of org.springframework.security.oauth2.server.resource.authentication.JwtGrantedAuthoritiesConverter in project spring-security by spring-projects.
the class JwtGrantedAuthoritiesConverterTests method convertWhenTokenHasEmptyScpAttributeThenTranslatedToNoAuthorities.
@Test
public void convertWhenTokenHasEmptyScpAttributeThenTranslatedToNoAuthorities() {
// @formatter:off
Jwt jwt = TestJwts.jwt().claim("scp", Collections.emptyList()).build();
// @formatter:on
JwtGrantedAuthoritiesConverter jwtGrantedAuthoritiesConverter = new JwtGrantedAuthoritiesConverter();
Collection<GrantedAuthority> authorities = jwtGrantedAuthoritiesConverter.convert(jwt);
assertThat(authorities).isEmpty();
}
use of org.springframework.security.oauth2.server.resource.authentication.JwtGrantedAuthoritiesConverter in project spring-security by spring-projects.
the class JwtGrantedAuthoritiesConverterTests method convertWhenTokenHasCustomClaimNameThenCustomClaimNameAttributeIsTranslatedToAuthorities.
@Test
public void convertWhenTokenHasCustomClaimNameThenCustomClaimNameAttributeIsTranslatedToAuthorities() {
// @formatter:off
Jwt jwt = TestJwts.jwt().claim("roles", Arrays.asList("message:read", "message:write")).claim("scope", "missive:read missive:write").build();
// @formatter:on
JwtGrantedAuthoritiesConverter jwtGrantedAuthoritiesConverter = new JwtGrantedAuthoritiesConverter();
jwtGrantedAuthoritiesConverter.setAuthoritiesClaimName("roles");
Collection<GrantedAuthority> authorities = jwtGrantedAuthoritiesConverter.convert(jwt);
assertThat(authorities).containsExactly(new SimpleGrantedAuthority("SCOPE_message:read"), new SimpleGrantedAuthority("SCOPE_message:write"));
}
Aggregations