use of org.springframework.security.oauth2.server.resource.InvalidBearerTokenException in project spring-security by spring-projects.
the class DefaultAuthenticationEventPublisherBearerTokenTests method publishAuthenticationFailureWhenInvalidBearerTokenExceptionThenMaps.
@Test
public void publishAuthenticationFailureWhenInvalidBearerTokenExceptionThenMaps() {
ApplicationEventPublisher appPublisher = mock(ApplicationEventPublisher.class);
Authentication authentication = new JwtAuthenticationToken(TestJwts.jwt().build());
Exception cause = new Exception();
this.publisher = new DefaultAuthenticationEventPublisher(appPublisher);
this.publisher.publishAuthenticationFailure(new InvalidBearerTokenException("invalid"), authentication);
this.publisher.publishAuthenticationFailure(new InvalidBearerTokenException("invalid", cause), authentication);
verify(appPublisher, times(2)).publishEvent(isA(AuthenticationFailureBadCredentialsEvent.class));
}
use of org.springframework.security.oauth2.server.resource.InvalidBearerTokenException in project dhis2-core by dhis2.
the class Dhis2JwtAuthenticationManagerResolver method getAuthenticationManager.
/**
* Looks for a DhisOidcClientRegistration in the DhisOidcProviderRepository
* that matches the input JWT "issuer". It creates a new
* DhisJwtAuthenticationProvider if it finds a matching config.
* <p>
* The DhisJwtAuthenticationProvider is configured with a custom
* {@link Converter} that "converts" the incoming JWT token into a
* {@link DhisJwtAuthenticationToken}.
* <p>
* It also configures a JWT decoder that "decodes" incoming JSON string into
* a JWT token ({@link Jwt}
*
* @param issuer JWT issuer to look up
*
* @return a DhisJwtAuthenticationProvider
*/
private AuthenticationManager getAuthenticationManager(String issuer) {
return this.authenticationManagers.computeIfAbsent(issuer, s -> {
DhisOidcClientRegistration clientRegistration = clientRegistrationRepository.findByIssuerUri(issuer);
if (clientRegistration == null) {
throw new InvalidBearerTokenException("Invalid issuer");
}
Converter<Jwt, DhisJwtAuthenticationToken> authConverter = getConverter(clientRegistration);
JwtDecoder decoder = getDecoder(issuer);
return new DhisJwtAuthenticationProvider(decoder, authConverter)::authenticate;
});
}
Aggregations