2012-02-11 110 views
2

我有一個JSF + Spring應用程序。 我使用彈簧安全和我正常工作。但是,當我嘗試達到沒有身份驗證的安全頁面,而不是重定向到拒絕的頁面,我只是顯示403禁止頁面。 我不知道是否有缺少點兒上的applicationContext或web.xml中,這裏是我的代碼:ApplicationContext中如何使用彈簧安全性重定向到訪問拒絕頁面

部分:

<sec:http access-denied-page="/denied.xhtml" auto-config="true" use-expressions="false" > 
    <sec:form-login login-page="/login.xhtml" default-target-url="/" authentication-failure-url="/denied.xhtml" 
    login-processing-url="/static/j_spring_security_check" 
    /> 
    <sec:intercept-url pattern="/PANEL/**" access="ROLE_GENERALT"></sec:intercept-url> 
    <sec:logout invalidate-session="true" logout-url="/index.xhtml"/> 
    </sec:http> 

<sec:global-method-security secured-annotations="enabled" jsr250-annotations="enabled"></sec:global-method-security> 

和web.xml:

<context-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value>classpath:/appContext.xml 
     </param-value> 
    </context-param> 
    <filter> 
    <filter-name>springSecurityFilterChain</filter-name> 
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> 

</filter> 

<filter-mapping> 
    <filter-name>springSecurityFilterChain</filter-name> 
    <url-pattern>/*</url-pattern> 
    <dispatcher>FORWARD</dispatcher> 
    <dispatcher>REQUEST</dispatcher> 
</filter-mapping> 

回答

11

您需要爲發生AccessDeniedException時由ExceptionTranslationFilter使用的accessDeniedHandler設置errorpage屬性

請參閱此處瞭解相關信息link

<bean id="exceptionTranslationFilter" class="org.springframework.security.web.access.ExceptionTranslationFilter"> 
    <property name="authenticationEntryPoint" ref="authenticationEntryPoint"/> 
    <property name="accessDeniedHandler" ref="accessDeniedHandler"/> 
</bean> 

<bean id="accessDeniedHandler" class="org.springframework.security.web.access.AccessDeniedHandlerImpl"> 
    <property name="errorPage" value="/denied.xhtml"/> 
</bean> 

或者,你可以添加到您的web.xml

<error-page> 
    <error-code>403</error-code> 
    <location>/pages/denied.xhtml</location> 
</error-page> 
相關問題