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

Questions:

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.

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

And after that I set to original RemoteTokenServices that converter.

@Bean
@Primary
public RemoteTokenServices customRemoteTokenService(RemoteTokenServices remoteTokenServices) 
{
    remoteTokenServices.setAccessTokenConverter(tokenEnhancer());
    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: