I want to customize 401 Unauthorized error page in spring Oauth 2-2.3.3
Right now I am getting below error form Spring Oauth
<UnauthorizedException><error>unauthorized</error><error_description>Full authentication is required to access this resource</error_description></UnauthorizedException>
I have written CustomWebResponseExceptionTranslator class that extends DefaultWebResponseExceptionTranslator
public class CustomWebResponseExceptionTranslator extends DefaultWebResponseExceptionTranslator {
@Override
public ResponseEntity<OAuth2Exception> translate(Exception e) throws Exception {
// custom logic
}
}
I have configured this CustomWebResponseExceptionTranslator in @EnableResourceServer But this is not getting invoked. Am I missing anything else?
@Import(ServerSecurityConfig.class)
@EnableResourceServer
public class ResourceServerConfiguration extends ResourceServerConfigurerAdapter {
@Override
public void configure(ResourceServerSecurityConfigurer resources) {
OAuth2AuthenticationEntryPoint oAuth2AuthenticationEntryPoint = new OAuth2AuthenticationEntryPoint();
oAuth2AuthenticationEntryPoint.setExceptionTranslator(new CustomWebResponseExceptionTranslator());
resources.authenticationEntryPoint(oAuth2AuthenticationEntryPoint);
}
```