use of org.springframework.security.oauth2.server.resource.BearerTokenAuthenticationToken in project spring-security by spring-projects.
the class JwtReactiveAuthenticationManagerTests method authenticateWhenJwtExceptionThenOAuth2AuthenticationException.
@Test
public void authenticateWhenJwtExceptionThenOAuth2AuthenticationException() {
BearerTokenAuthenticationToken token = new BearerTokenAuthenticationToken("token-1");
given(this.jwtDecoder.decode(any())).willReturn(Mono.error(new BadJwtException("Oops")));
assertThatExceptionOfType(OAuth2AuthenticationException.class).isThrownBy(() -> this.manager.authenticate(token).block());
}
use of org.springframework.security.oauth2.server.resource.BearerTokenAuthenticationToken in project spring-security by spring-projects.
the class JwtReactiveAuthenticationManagerTests method authenticateWhenDecoderThrowsIncompatibleErrorMessageThenWrapsWithGenericOne.
// gh-7549
@Test
public void authenticateWhenDecoderThrowsIncompatibleErrorMessageThenWrapsWithGenericOne() {
BearerTokenAuthenticationToken token = new BearerTokenAuthenticationToken("token-1");
given(this.jwtDecoder.decode(token.getToken())).willThrow(new BadJwtException("with \"invalid\" chars"));
// @formatter:off
assertThatExceptionOfType(OAuth2AuthenticationException.class).isThrownBy(() -> this.manager.authenticate(token).block()).satisfies((ex) -> assertThat(ex).hasFieldOrPropertyWithValue("error.description", "Invalid token"));
// @formatter:on
}
use of org.springframework.security.oauth2.server.resource.BearerTokenAuthenticationToken in project spring-security by spring-projects.
the class JwtReactiveAuthenticationManagerTests method authenticateWhenEmptyJwtThenEmpty.
@Test
public void authenticateWhenEmptyJwtThenEmpty() {
BearerTokenAuthenticationToken token = new BearerTokenAuthenticationToken("token-1");
given(this.jwtDecoder.decode(token.getToken())).willReturn(Mono.empty());
assertThat(this.manager.authenticate(token).block()).isNull();
}
use of org.springframework.security.oauth2.server.resource.BearerTokenAuthenticationToken in project spring-security by spring-projects.
the class JwtReactiveAuthenticationManagerTests method authenticateWhenDecoderFailsGenericallyThenThrowsGenericException.
// gh-7785
@Test
public void authenticateWhenDecoderFailsGenericallyThenThrowsGenericException() {
BearerTokenAuthenticationToken token = new BearerTokenAuthenticationToken("token-1");
given(this.jwtDecoder.decode(token.getToken())).willThrow(new JwtException("no jwk set"));
// @formatter:off
assertThatExceptionOfType(AuthenticationException.class).isThrownBy(() -> this.manager.authenticate(token).block()).isNotInstanceOf(OAuth2AuthenticationException.class);
// @formatter:on
}
use of org.springframework.security.oauth2.server.resource.BearerTokenAuthenticationToken in project spring-security by spring-projects.
the class JwtReactiveAuthenticationManagerTests method authenticateWhenNotJwtExceptionThenPropagates.
@Test
public void authenticateWhenNotJwtExceptionThenPropagates() {
BearerTokenAuthenticationToken token = new BearerTokenAuthenticationToken("token-1");
given(this.jwtDecoder.decode(any())).willReturn(Mono.error(new RuntimeException("Oops")));
// @formatter:off
assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> this.manager.authenticate(token).block());
// @formatter:on
}
Aggregations