See
http://www.nabble.com/AOP-security-bubbling-up-to-views-tf3870458s2369.html
AccessDeniedException doesn't properly bubble up to the view layer as intended.
The case is where a non-authorized, and non-ROLE_ADMIN, user tries to save a user. The UserSecurityAdvice should throw AccessDeniedException according to the aop:advisor, and the user should get a HTTP 403, and an "Access Denied" message page for their view.
This doesn't happen because the UserAction class doesn't catch a AccessDeniedException when saveUser is called. A catch statement in the UserAction.save(), after the saveUser call, will fix it, generally:
user = userManager.saveUser(user);
} catch (AccessDeniedException ade) {
this.getResponse().sendError(HttpServletResponse.SC_FORBIDDEN);
return null;
}
This affects both UserAction and SignupAction type controllers.
In the AppFuse 1.x implementation using Struts 1.x, the BaseAction was configured to catch this, and all Struts Actions extended BaseAction. AF2/Struts2 isn't setup the same way, so AccessDeniedException should be caught in each Action that needs it.
The attached patch fixes this for User/Signup controllers for JSF, Spring, Struts, and Tapestry web frameworks. It passes all maven tests on the current HEAD revision.
1) start the webapp (mvn jetty:run)
2) login as "user/user"
3) edit the user profile, change the Username to "user2"
4) press Save button
See this error:
Yikes!
org.acegisecurity.AccessDeniedException: Access Denied: Only administrators are allowed to modify other users.
at org.appfuse.service.UserSecurityAdvice.before(UserSecurityAdvice.java:63)
at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:49)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:161)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:161)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at $Proxy22.saveUser(Unknown Source)
at org.appfuse.webapp.action.UserAction.save(UserAction.java:155)
[SNIP]