JwtAuthenticationProvider
should use provided authentication details
#11822
Labels
in: oauth2
An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose)
type: bug
A general bug
Milestone
Describe the bug
JwtAuthenticationProvider
delegates the instantiation of anAuthentication
to aConverter<Jwt, ? extends AbstractAuthenticationToken>
but it then alters returned valuedetails
property.For framework user providing a
Converter<Jwt, AbstractAuthenticationToken>
bean which sets authentication details, this means he won't get the details he had set when later accessing the authentication (from security expressions for instance).Please note that
JwtReactiveAuthenticationManager
, the reactive pendant ofJwtAuthenticationProvider
written by @rwinch , does not setdetails
after the Authentication is returned by the converter.To Reproduce
DemoAuthentication extends AbstractAuthenticationToken
class which sets details in constructor and make it immutable (overridesetDetails
to throw an exception)Converter<Jwt, DemoAuthentication>
An exception will be thrown by
JwtAuthenticationProvider
as soon as a request is submitted with a valid JWT.Expected behavior
This kind of side effect on Authentication instance is a problem when the framework user has provided a jwtAuthenticationConverter which intentionally set authentication
details
.Ideally,
details
property would be set by thejwtAuthenticationConverter
(not theJwtAuthenticationProvider
).Other sollution with minimum code impact would be preventing
JwtAuthenticationProvider
to touch authenticationdetails
when it is not null.Sample
https://github.com/ch4mpy/spring-security-11822
TOKEN
value inSpringSecurity11822ApplicationTests
SpringSecurity11822ApplicationTests
The text was updated successfully, but these errors were encountered: