2016-03-03 85 views
0

我們正在從SpringSecurity 3遷移我們的應用程序4.我們我們ConcurrentSessionControlStrategy豆配置,因爲我們使用的是帶有基本身份驗證從Excel的HTTP請求總是創建會話(Grails的符號定義豆)有沒有辦法在Spring Security 4中擁有ConcurrentSessionControlStrategy.alwaysCreateSession?

sessionRegistry(SessionRegistryImpl) 
sessionAuthenticationStrategy(ConcurrentSessionControlStrategy, sessionRegistry) { 
    alwaysCreateSession = true 
} 

和其他應用程序與應用程序進行交互,並且沒有該選項,會話不會創建,並且必須爲每個操作執行身份驗證,而不是針對第一個操作執行一次。

在Spring Security 4 ConcurrentSessionControlStrategy遷移到ConcurrentSessionControlStrategy(根據遷移指南 - http://docs.spring.io/spring-security/site/migrate/current/3-to-4/html5/migrate-3-to-4-xml.html)應的CompositeSessionAuthenticationStrategy內部使用,但我們無法找到一個方法來設置會話策略。

我們目前的解決方法是調用驗證之前非基本身份驗證的頁面,是什麼導致創建會話並按照要求將針對本次會議

+1

'ConcurrentSessionControl'和你描述的是不同的東西。 'ConcurrentSessionControl'是一次允許同一用戶有多少會話。你正在混合會話創建和併發控制......這些是完全不同的東西。 –

+0

所以你的意思是'alwaysCreateSession'不影響基本認證上的會話創建?設置此參數後,外部請求會創建會話,因此它提供了我們所需的內容。除此之外,我們還控制每個用戶允許的會話數量,但根據遷移指南進行配置時,此效果在4之內。 – droggo

+1

是的,它會影響會話創建,但它與'ConcurrentSessionControlStrategy'無關。 –

回答

0

從M. Deinum評論指出我進入另一個方向和執行我發現在spring-security-core Grails securityContextPersistenceFilter的插件定義爲forceEagerSessionCreation = false。重寫這個bean迫使急於會話創建的伎倆

securityContextPersistenceFilter(SecurityContextPersistenceFilter, ref('securityContextRepository')) { 
    forceEagerSessionCreation = true 
} 

此使用Grails的Spring Security核心的配置或許也可以做

的源代碼可以在這裏找到: https://github.com/grails-plugins/grails-spring-security-core/blob/master/src/main/groovy/grails/plugin/springsecurity/SpringSecurityCoreGrailsPlugin.groovy

相關問題