2011-12-15 88 views
2

我有一個由兩個模塊組成的GWT應用程序:用於主要功能的「應用程序」和用於登錄/忘記密碼/註冊新用戶功能的「登錄」。成功登錄後用Spring Security導航到其他GWT模塊

我使用Spring Security的用戶重定向到Application.html上全成登錄:

<security:http auto-config="true"> 
    <security:intercept-url pattern="/Application.html**" access="ROLE_USER"/> 
    <security:intercept-url pattern="/**" access="IS_AUTHENTICATED_ANONYMOUSLY"/> 
    <security:form-login login-page="/Login.html" default-target-url="/MainApplication.html" 
     always-use-default-target="true" authentication-failure-url="/Login.html?failed=true"/> 
</security:http> 

通過login.html的全成用戶身份驗證後,Application.html模塊被加載和相應的請求進行到服務器,但瀏覽器內容保持不變,地址欄中的網址仍然是「Login.html」!

所以,問題是:爲什麼重定向不會發生?

在此先感謝!

回答

0

您正通過SpringSecurityFilter攔截Application.html,並將目標URL指定爲MainApplication.html。在mainApplication.html中,請嘗試將此代碼放回到Application.html中,以便將其移回到Application.html。如果你需要,你可以在這裏做一些授權。同時檢查DelegatingFilterProxy是否在web.xml中正確設置。

我的配置如下。我在web.xml中

<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> 
</filter-mapping> 

在我的welcome.jsp使用GWT應用

在我的jsp

<form name="login" action="<c:url value="j_spring_security_check"/>" method="POST"> 

<sec:authorize ifAnyGranted="<%=gRoles%>">  
    <meta http-equiv="REFRESH" content="0; url=demoApp/demoApp.jsp"> 
</sec:authorize> 

彈簧security.xml文件

<http auto-config="false" access-denied-page="/login.jsp?error=Access%20Denied"> 
    <intercept-url pattern="/login.jsp*" filters="none" /> 
    <intercept-url pattern="/demoApp/**" access="${app.roles}" /> 

    <form-login login-page="/login.jsp" 
       default-target-url="/welcome.jsp" 
       always-use-default-target="true" 
       authentication-failure-url="/login.jsp?error=true" /> 
    <logout logout-success-url="/login.jsp"/> 
    <anonymous/> 

+0

感謝您的回覆。 我已經檢查過web.xml中的spring安全 - 它與你的一樣,似乎是正確的。 我已經按照你的建議添加了標記,並且有無限循環--Application.html發送重定向到Login.html,它將重定向發回到Application.html等等。 它的行爲方式與彈簧安全性在加載「應用程序」模塊期間拒絕訪問某處的方式完全相同,但我確信在授權時一切正常 - 我已減少安全配置以啓用對所有資源的匿名訪問並打開DEBUG記錄它。 – Valrog 2011-12-15 18:48:48