28
28
import org .springframework .context .annotation .Role ;
29
29
import org .springframework .http .HttpEntity ;
30
30
import org .springframework .http .ResponseEntity ;
31
- import org .springframework .http .converter .HttpMessageNotWritableException ;
32
31
import org .springframework .security .access .AccessDeniedException ;
33
32
import org .springframework .security .authorization .method .AuthorizationAdvisorProxyFactory ;
34
33
import org .springframework .security .web .util .ThrowableAnalyzer ;
@@ -52,11 +51,11 @@ public void extendHandlerExceptionResolvers(List<HandlerExceptionResolver> resol
52
51
for (int i = 0 ; i < resolvers .size (); i ++) {
53
52
HandlerExceptionResolver resolver = resolvers .get (i );
54
53
if (resolver instanceof DefaultHandlerExceptionResolver ) {
55
- resolvers .add (i , new HttpMessageNotWritableAccessDeniedExceptionResolver ());
54
+ resolvers .add (i , new AccessDeniedExceptionResolver ());
56
55
return ;
57
56
}
58
57
}
59
- resolvers .add (new HttpMessageNotWritableAccessDeniedExceptionResolver ());
58
+ resolvers .add (new AccessDeniedExceptionResolver ());
60
59
}
61
60
62
61
static class WebTargetVisitor implements AuthorizationAdvisorProxyFactory .TargetVisitor {
@@ -84,24 +83,20 @@ public Object visit(AuthorizationAdvisorProxyFactory proxyFactory, Object target
84
83
85
84
}
86
85
87
- static class HttpMessageNotWritableAccessDeniedExceptionResolver implements HandlerExceptionResolver {
86
+ static class AccessDeniedExceptionResolver implements HandlerExceptionResolver {
88
87
89
88
final ThrowableAnalyzer throwableAnalyzer = new ThrowableAnalyzer ();
90
89
91
90
@ Override
92
91
public ModelAndView resolveException (HttpServletRequest request , HttpServletResponse response , Object handler ,
93
92
Exception ex ) {
94
- // Only resolves AccessDeniedException if it occurred during serialization,
95
- // otherwise lets the user-defined handler deal with it.
96
- if (ex instanceof HttpMessageNotWritableException ) {
97
- Throwable [] causeChain = this .throwableAnalyzer .determineCauseChain (ex );
98
- Throwable accessDeniedException = this .throwableAnalyzer
99
- .getFirstThrowableOfType (AccessDeniedException .class , causeChain );
100
- if (accessDeniedException != null ) {
101
- return new ModelAndView ((model , req , res ) -> {
102
- throw ex ;
103
- });
104
- }
93
+ Throwable [] causeChain = this .throwableAnalyzer .determineCauseChain (ex );
94
+ Throwable accessDeniedException = this .throwableAnalyzer
95
+ .getFirstThrowableOfType (AccessDeniedException .class , causeChain );
96
+ if (accessDeniedException != null ) {
97
+ return new ModelAndView ((model , req , res ) -> {
98
+ throw ex ;
99
+ });
105
100
}
106
101
return null ;
107
102
}
0 commit comments