I'm debugging a scenario in my production environment where I intermittently see unexpected HTTP 401 responses from my resource server. I'm using Spring Security OAuth2 (the "old" OAuth libraries; pre Spring Security 5.2.x and its implementation of OAuth2) to handle requests and perform Authn.
What I'm observing is the following:
- A user logs in at time
x
(time in seconds here) and obtains an access token. That access token expires at timex + 900
(15 minute validity). - At time
x + 480
, the user makes a request to a protected endpoint. - The request takes a long time to complete, such that it's still being processed when the token expires. At time
x + 900
, the server returns aHTTP 401
response.
Questions:
- Is this really how Spring Security OAuth2 works? To be more specific, does it track the token's expiration time and return a 401 if the request is still being processed when the token expires? Or on the other end of the security filter, when the response is being prepared?
- Is there a way to disable this behavior, so that the token is only checked when the request is first processed?