use of com.auth0.jwt.JWT in project spring-security by spring-projects.
the class JwtAuthenticationConverterTests method convertWhenDefaultGrantedAuthoritiesConverterSet.
@Test
public void convertWhenDefaultGrantedAuthoritiesConverterSet() {
Jwt jwt = TestJwts.jwt().claim("scope", "message:read message:write").build();
AbstractAuthenticationToken authentication = this.jwtAuthenticationConverter.convert(jwt);
Collection<GrantedAuthority> authorities = authentication.getAuthorities();
assertThat(authorities).containsExactly(new SimpleGrantedAuthority("SCOPE_message:read"), new SimpleGrantedAuthority("SCOPE_message:write"));
}
use of com.auth0.jwt.JWT in project spring-security by spring-projects.
the class JwtAuthenticationTokenTests method getNameWhenJwtHasSubjectThenReturnsSubject.
@Test
public void getNameWhenJwtHasSubjectThenReturnsSubject() {
Jwt jwt = builder().subject("Carl").build();
JwtAuthenticationToken token = new JwtAuthenticationToken(jwt);
assertThat(token.getName()).isEqualTo("Carl");
}
use of com.auth0.jwt.JWT in project spring-security by spring-projects.
the class JwtAuthenticationTokenTests method getNameWhenJwtHasNoSubjectThenReturnsNull.
@Test
public void getNameWhenJwtHasNoSubjectThenReturnsNull() {
Jwt jwt = builder().claim("claim", "value").build();
JwtAuthenticationToken token = new JwtAuthenticationToken(jwt);
assertThat(token.getName()).isNull();
}
use of com.auth0.jwt.JWT in project spring-security by spring-projects.
the class JwtGrantedAuthoritiesConverterTests method convertWhenTokenHasUnsupportedTypeForScopeThenTranslatesToNoAuthorities.
@Test
public void convertWhenTokenHasUnsupportedTypeForScopeThenTranslatesToNoAuthorities() {
// @formatter:off
Jwt jwt = TestJwts.jwt().claim("scope", new String[] { "message:read", "message:write" }).build();
// @formatter:on
JwtGrantedAuthoritiesConverter jwtGrantedAuthoritiesConverter = new JwtGrantedAuthoritiesConverter();
Collection<GrantedAuthority> authorities = jwtGrantedAuthoritiesConverter.convert(jwt);
assertThat(authorities).isEmpty();
}
use of com.auth0.jwt.JWT in project spring-security by spring-projects.
the class JwtGrantedAuthoritiesConverterTests method convertWhenTokenHasEmptyCustomClaimNameThenCustomClaimNameAttributeIsTranslatedToNoAuthorities.
@Test
public void convertWhenTokenHasEmptyCustomClaimNameThenCustomClaimNameAttributeIsTranslatedToNoAuthorities() {
// @formatter:off
Jwt jwt = TestJwts.jwt().claim("roles", Collections.emptyList()).claim("scope", "missive:read missive:write").build();
// @formatter:on
JwtGrantedAuthoritiesConverter jwtGrantedAuthoritiesConverter = new JwtGrantedAuthoritiesConverter();
jwtGrantedAuthoritiesConverter.setAuthoritiesClaimName("roles");
Collection<GrantedAuthority> authorities = jwtGrantedAuthoritiesConverter.convert(jwt);
assertThat(authorities).isEmpty();
}
Aggregations