use of org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken in project spring-security by spring-projects.
the class JwtAuthenticationTokenTests method getNameWhenConstructedWithJwtAndAuthoritiesThenReturnsSubject.
@Test
public void getNameWhenConstructedWithJwtAndAuthoritiesThenReturnsSubject() {
Collection<GrantedAuthority> authorities = AuthorityUtils.createAuthorityList("test");
Jwt jwt = builder().subject("Hayden").build();
JwtAuthenticationToken token = new JwtAuthenticationToken(jwt, authorities);
assertThat(token.getName()).isEqualTo("Hayden");
}
use of org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken in project spring-security by spring-projects.
the class JwtAuthenticationTokenTests method constructorWhenUsingOnlyJwtThenConstructedCorrectly.
@Test
public void constructorWhenUsingOnlyJwtThenConstructedCorrectly() {
Jwt jwt = builder().claim("claim", "value").build();
JwtAuthenticationToken token = new JwtAuthenticationToken(jwt);
assertThat(token.getAuthorities()).isEmpty();
assertThat(token.getPrincipal()).isEqualTo(jwt);
assertThat(token.getCredentials()).isEqualTo(jwt);
assertThat(token.getToken()).isEqualTo(jwt);
assertThat(token.getTokenAttributes()).isEqualTo(jwt.getClaims());
assertThat(token.isAuthenticated()).isFalse();
}
use of org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken in project spring-security by spring-projects.
the class JwtAuthenticationTokenTests method getNameWhenConstructedWithNoSubjectThenReturnsNull.
@Test
public void getNameWhenConstructedWithNoSubjectThenReturnsNull() {
Collection<GrantedAuthority> authorities = AuthorityUtils.createAuthorityList("test");
Jwt jwt = builder().claim("claim", "value").build();
assertThat(new JwtAuthenticationToken(jwt, authorities, null).getName()).isNull();
assertThat(new JwtAuthenticationToken(jwt, authorities).getName()).isNull();
assertThat(new JwtAuthenticationToken(jwt).getName()).isNull();
}
use of org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken in project spring-security by spring-projects.
the class JwtAuthenticationTokenTests method constructorWhenUsingCorrectParametersThenConstructedCorrectly.
@Test
public void constructorWhenUsingCorrectParametersThenConstructedCorrectly() {
Collection<GrantedAuthority> authorities = AuthorityUtils.createAuthorityList("test");
Jwt jwt = builder().claim("claim", "value").build();
JwtAuthenticationToken token = new JwtAuthenticationToken(jwt, authorities);
assertThat(token.getAuthorities()).isEqualTo(authorities);
assertThat(token.getPrincipal()).isEqualTo(jwt);
assertThat(token.getCredentials()).isEqualTo(jwt);
assertThat(token.getToken()).isEqualTo(jwt);
assertThat(token.getTokenAttributes()).isEqualTo(jwt.getClaims());
assertThat(token.isAuthenticated()).isTrue();
}
use of org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken in project spring-security by spring-projects.
the class JwtAuthenticationTokenTests method getNameWhenConstructedWithJwtThenReturnsSubject.
@Test
public void getNameWhenConstructedWithJwtThenReturnsSubject() {
Jwt jwt = builder().subject("Hayden").build();
JwtAuthenticationToken token = new JwtAuthenticationToken(jwt);
assertThat(token.getName()).isEqualTo("Hayden");
}
Aggregations