如何在spring security oauth2中将错误/异常作为json对象返回?

时间:2016-09-21 05:18:53

标签: java spring spring-security oauth-2.0 spring-security-oauth2

我正在使用服务器到服务器spring restfull web-services并在spring-security.xml中编写了所有配置(我的oauth2 jar版本是2.0.10 RELEASE ),所以现在如何渲染在浏览器上自定义jsp以显示此错误?

创建令牌时的Json响应

 {
    "access_token": "d7a82d67-228f-459f-bf02-5c3501706c6d",
    "token_type": "bearer",
    "expires_in": 29,
    "scope": "read trust write"
 }

错误XMLformat

<oauth>
    <error_description> An Authentication object was not found in the SecurityContext </error_description>
    <error>unauthorized</error>
</oauth>

I just want to remove this xml response and want my custom error.jsp

1 个答案:

答案 0 :(得分:0)

web.xml

中添加此内容
 <!-- Unauthorized -->
   <error-page>
    <error-code>401</error-code>
    <location>x.jsp</location>
  </error-page>

 <!-- access forbidden -->
  <error-page>
    <error-code>403</error-code>
    <location> x.jsp</location>
  </error-page>