Description
Summary
I would like to log requests for invalid attempts for authenticating via OAuth 2.0 bearer tokens (via JWT) for which I have ApplicationListeners for both AbstractAuthenticationEvent
and AbstractAuthorizationEvent
events which log failures as they are seen. Currently when presented with invalid JWT bearer tokens a 401 HTTP response is provided but no Application Listener events are fired that corresponds to the error response.
Actual Behavior
When submitting a request with a bad JWT bearer token the application responds with a 401 response code but no ApplicationListener event is fired that correlates to the bad response. Currently I see an error that says:
"classname": "org.springframework.security.oauth2.server.resource.web.BearerTokenAuthenticationFilter",
"method": "doFilterInternal",
"file": "BearerTokenAuthenticationFilter.java",
"line": 135,
"logger_name": "org.springframework.security.oauth2.server.resource.web.BearerTokenAuthenticationFilter",
"level": "DEBUG",
"message": "Authentication request for failed!",
"stack_trace": "org.springframework.security.oauth2.core.OAuth2AuthenticationException: An error occurred while attempting to decode the Jwt: Signed JWT rejected: Invalid signature
.......
Upon inspection of the BearerTokenAuthenticationFilter it seems to merely manipulate the HTTPServletResponse in the default implementation instead of producing any application events.
Expected Behavior
On malformed JWT bearer token error responses a corresponding application event should be sent that implements an AbstractAuthenticationFailureEvent
.
Configuration
Dependencies:
implementation("org.springframework.boot:spring-boot-starter-actuator")
implementation("org.springframework.boot:spring-boot-starter-oauth2-resource-server")
...
WebSecurityConfigurerAdapter
:
http
.cors()
.and()
.authorizeRequests()
.antMatchers(AUTH_WHITELIST)
.permitAll()
.anyRequest()
.hasAnyAuthority("ROLE_REDACTED", .....)
.and()
.oauth2ResourceServer()
.jwt()
.jwtAuthenticationConverter(authenticationConverter);
Version
Spring Boot 2.2.2.RELEASE -> (Spring Security 5.2.1.RELEASE)