Spring security with @RestController - JSONish CustomAuthenticationProvider response

后端 未结 2 2056
挽巷
挽巷 2021-01-15 02:38

I still new with Spring especially spring security. This application is Restful application.

Following is snippet from @RestController :



        
2条回答
  •  终归单人心
    2021-01-15 02:59

    You may be able to create a custom filter that can catch an AccessDeniedException and add the filter after ExceptionTranslationFilter in the configuration file in the following way:

    http.addFilterAfter(customExceptionTranslationFilter, ExceptionTranslationFilter.class)
    

    After catching the exception, you can use the response object to respond in the way you'd like.

    You can then also add the ability to work with other exception you may want to throw in your Controllers.

提交回复
热议问题