2011-07-11 37 views
4

我想在我的GWT應用程序上使用方法級安全性。我試圖使用Spring Security 3.1,因爲我發現了一個工作示例here,但它不使用form-login。閱讀this answer第一個方法調用成功獲得SecurityContext的,但在以後的調用之前將其清除後:春季方法級別安全性在第二次調用時失敗

[org.springframework.security.web.context.HttpSessionSecurityContextRepository] - Obtained a valid SecurityContext from SPRING_SECURITY_CONTEXT: '[email protected]e9f089: Authentication: [email protected]e9f089' 
... 
[org.springframework.security.access.intercept.aspectj.AspectJMethodSecurityInterceptor] - Authorization successful 
... 
[org.springframework.security.web.context.SecurityContextPersistenceFilter] - SecurityContextHolder now cleared, as request processing completed 
... 
[org.springframework.security.web.context.HttpSessionSecurityContextRepository] - SecurityContext is empty or contents are anonymous - context will not be stored in HttpSession. 
[org.springframework.security.web.context.SecurityContextPersistenceFilter] - SecurityContextHolder now cleared, as request processing completed 
... 
[org.springframework.security.web.context.HttpSessionSecurityContextRepository] - HttpSession returned null object for SPRING_SECURITY_CONTEXT 

第二個電話的第一,只是在用戶登錄後,在連敗之後發生

是它因爲我跟着其他的答案,並刪除<http pattern="/MyAppName/**" security="none" />並添加<intercept-url pattern="/MyAppName/**" access="permitAll()" />

我的過濾器如下所示:

<http pattern="/favicon.ico" security="none" /> 

<http access-decision-manager-ref="accessDecisionManager" use-expressions="true" auto-config="false" entry-point-ref="LoginUrlAuthenticationEntryPoint"> 
    <form-login login-page="/Login.html" always-use-default-target="true" default-target-url="/Main.html?gwt.codesvr=127.0.0.1:9997" /> 
    <intercept-url pattern="/Login.html" access="permitAll()" /> 
    <intercept-url pattern="/Login2.html" access="permitAll()" /> 
    <intercept-url pattern="/MyAppName/**" access="permitAll()" /> 
    <intercept-url pattern="/**" access="isAuthenticated()" /> 
    <logout delete-cookies="JSESSIONID" logout-success-url="/Login.html" /> 
    <remember-me token-validity-seconds="86400" key="key" user-service-ref="userDetailsService" /> 
</http> 

下面我得到我用AspectJ爲全局法安全的例子,但不會使用它,如果我能得到那工作:

<global-method-security secured-annotations="enabled" pre-post-annotations="enabled" mode="aspectj" proxy-target-class="true" > 
    <expression-handler ref="expressionHandler"/> 
</global-method-security> 

感謝您花時間閱讀本文。

請讓我知道是否需要更多的細節。

+2

我認爲你需要修整更多的東西到可以管理的東西,沒有多少人會花費時間閱讀和瀏覽所有的文本,試圖找出問題的癥結所在。 –

+0

感謝您的評論。我嘗試刪除3個成功調用中的2個日誌,因爲它們可能是多餘的。 – WhiteKnight

回答

0

此問題已解決。

解決方案的最後部分是刪除使SecurityContextHolder爲全局的請求。

如果你有同樣的問題,可能會發現this後有幫助。

+1

你是怎麼真正解決這個問題的?我有同樣的問題。我瀏覽了鏈接,但沒有幫助。 – Tiny

+0

@Tiny在嘗試獲得兩個因子認證工作時,我將SecurityContextHolder設置爲全局的,因此刪除這個問題對我來說已經解決了問題,但是可能有很多事情導致了這個問題。此外,我沒有從盧克那裏聽說爲什麼會導致我遇到的問題。 – WhiteKnight

相關問題