我想在springoauth2-2.3.3中自定义401unauthorized错误页
现在我从springoauth得到下面的错误
<UnauthorizedException><error>unauthorized</error><error_description>Full authentication is required to access this resource</error_description></UnauthorizedException>
我已经编写了customwebresponseexceptiontranslator类,它扩展了defaultwebresponseexceptiontranslator
public class CustomWebResponseExceptionTranslator extends DefaultWebResponseExceptionTranslator {
@Override
public ResponseEntity<OAuth2Exception> translate(Exception e) throws Exception {
// custom logic
}
}
我已经在@enableresourceserver中配置了这个customwebresponseexceptiontranslator,但是没有调用它。我还缺什么吗?
@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);
}
暂无答案!
目前还没有任何答案,快来回答吧!