【发布时间】:2013-05-01 07:45:46
【问题描述】:
我一直在尝试在我一直在开发的这个应用程序上使用“方法级别”安全性。这个想法是保护使用 DWR 从表示层调用的方法。 现在,我尝试在我的方法中添加以下注释:
@PreAuthorize("isAuthenticated() and hasRole('ROLE_CUSTOMER')")
以及我的安全上下文中的相应条目:
<global-method-security pre-post-annotations="enabled" />
在类似的行中,我尝试了@Secured 注释:
@Secured({"ROLE_CUSTOMER" })
以及我的安全上下文中的相应条目:
<global-method-security secured-annotations="enabled" />
理想情况下,我希望如果用户未通过身份验证,他们应该被重定向到“登录”页面,并且不应该检查“角色”。在这种情况下,即使对于未经身份验证的用户,此方法调用也会导致“AccessDeniedException”。在这种情况下,我需要它来将用户重定向到登录页面。
为了向前推进,我什至尝试通过创建自定义 AccessDenied 处理程序来处理 accessdenied 异常。不幸的是,处理程序从未被调用,但抛出了异常。
这是配置:
<access-denied-handler ref="customAccessDeniedHandler"/>
这在同一文件中定义了相应的处理程序 bean。
仍然没有运气。 accessdeniedhandler 永远不会被调用。
总结一下需求,我需要一个方法。如果此方法被调用,并且用户未经身份验证,则用户应该被重定向到“登录”页面(目前正在抛出 Accessdenied execption)。
感谢您的帮助..
编辑 1:这是来自安全上下文的 sn-p:
<http>
<intercept-url pattern="/*sign-in.do*" requires-channel="$secure.channel}" />
.....
.....
.....
<intercept-url pattern="/j_acegi_security_check.do" requires-channel="${secure.channel}" />
<intercept-url pattern="/*.do" requires-channel="http" />
<intercept-url pattern="/*.do\?*" requires-channel="http" />
<form-login login-page="/sign-in.do" authentication-failure-url="/sign-in.do?login_failed=1"
authentication-success-handler-ref="authenticationSuccessHandler" login-processing-url="/j_acegi_security_check.do"/>
<logout logout-url="/sign-out.do" logout-success-url="/index.do" />
<session-management session-authentication-strategy-ref="sessionAuthenticationStrategy" />
<access-denied-handler ref="customAccessDeniedHandler"/>
</http>
<beans:bean id="customAccessDeniedHandler" class="com.mypackage.interceptor.AccessDeniedHandlerApp"/>
【问题讨论】:
标签: spring security spring-mvc spring-security dwr