【发布时间】:2018-01-11 06:56:04
【问题描述】:
我的应用程序使用带有 JWTToken 的 Spring Security Oauth2。
当它返回错误 401 时,我正在尝试修改响应的正文,当未经身份验证的用户尝试访问数据时会发生这种情况:
{
"error": "invalid_token",
"error_description": "Cannot convert access token to JSON"
}
为此,我实现了自己的WebResponseExceptionTranslator,并将其设置在我的身份验证入口点中,如下所示:
@Configuration
@EnableAuthorizationServer
public class AuthorizationServerConfiguration extends AuthorizationServerConfigurerAdapter {
@Override
public void configure(AuthorizationServerSecurityConfigurer oauthServer) throws Exception {
oauthServer.authenticationEntryPoint(authenticationEntryPoint());
}
@Bean
public AuthenticationEntryPoint authenticationEntryPoint () {
OAuth2AuthenticationEntryPoint authenticationEntryPoint = new OAuth2AuthenticationEntryPoint();
authenticationEntryPoint.setExceptionTranslator(new CustomWebResponseExceptionTranslator());
return authenticationEntryPoint;
}
}
但是,它继续使用默认的WebResponseExceptionTranslator。所以,我的问题是,我怎样才能强迫他使用我的?
【问题讨论】:
标签: java spring-security spring-oauth2