Home » Java » java – Custom UserAuthenticationConverter in Oauth ResourceServer-Exceptionshub

java – Custom UserAuthenticationConverter in Oauth ResourceServer-Exceptionshub

Posted by: admin February 25, 2020 Leave a comment


I need to use custom UserAuthenticationConverter implementation to extract custom Authentication objects.

I used the following way:

I at first created bean for my access converter with required UserAuthenticationConverter implementation.

public JwtAccessTokenConverter tokenEnhancer() {
    final JwtAccessTokenConverter jwtConverter = new JwtAccessTokenConverter();
    final DefaultAccessTokenConverter tokenConverter = new DefaultAccessTokenConverter();
    tokenConverter.setUserTokenConverter(new CustomUserConverter());
    return jwtConverter;

And after that I set to original RemoteTokenServices that converter.

public RemoteTokenServices customRemoteTokenService(RemoteTokenServices remoteTokenServices) 
    return remoteTokenServices;

I want to ask if this is the correct way to achieve that, or there is a better or recommended way? Thank you.

How to&Answers: