[英]Spring Security - caching credentials from SSO
我正在更新一個較舊的程序以使用Spring Security。 以前,它使用Acegi安全性,並在對SSO標頭進行初步檢查后將憑據緩存到會話cookie中。 使用Spring Security 3.1.4,我能夠檢查SSO用戶名標頭(SM_USER,並且不,我們不再使用Siteminder,但為了避免在切換到OAM時進行繁瑣的軟件更新,我們將OAM配置為將SM_USER標頭插入請求中),然后在tomcat(6.0)中使用閥門設置在本地工作; 但是,當使用實時SSO部署到開發環境時,它僅在POSTS上失敗,然后僅在使用相同URL但使用不同HTTP RequestMethod的頁面上失敗。 從網絡流量來看,舊代碼和新代碼之間的區別似乎是新代碼正在發出OAM SSO身份驗證請求,然后身份驗證重定向將丟棄POST數據並將RequestMethod更改為GET; 因此,我認為也許在應用程序中添加憑據緩存可以解決該問題; 但是我很難找到可以添加以啟用緩存的配置,這就是我尋求幫助的地方。
這是按請求身份驗證執行的安全配置,並且可以在本地運行:
<security:http use-expressions="true" auto-config="true" entry-point-ref="http403EntryPoint">
<security:intercept-url pattern="/**" access="isAuthenticated()" />
<security:intercept-url pattern="/fastjump/auth/admin/*" access="hasRole('ROLE_ADMINISTRATOR')" />
<security:intercept-url pattern="/fastjump/auth/*" access="permitAll" />
<security:custom-filter position="PRE_AUTH_FILTER" ref="siteminderFilter" />
</security:http>
<bean id="siteminderFilter" class="org.springframework.security.web.authentication.preauth.RequestHeaderAuthenticationFilter">
<property name="principalRequestHeader" value="SM_USER"/>
<property name="authenticationManager" ref="authenticationManager" />
</bean>
<bean id="preauthAuthProvider" class="org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationProvider">
<property name="preAuthenticatedUserDetailsService">
<bean id="userDetailsServiceWrapper" class="org.springframework.security.core.userdetails.UserDetailsByNameServiceWrapper">
<property name="userDetailsService" ref="userDetailsService"/>
</bean>
</property>
</bean>
<security:authentication-manager alias="authenticationManager">
<security:authentication-provider ref="preauthAuthProvider" />
</security:authentication-manager>
<!-- This is the class that handles actually looking up the user from the persistent store and associating their
GrantedAuthority objects. This custom implementation uses a PersonService object to do the lookup. -->
<bean id="userDetailsService" class="corporate.fastjump.security.DefaultUserDetailsService">
<property name="personService" ref="personService"/>
<property name="fastJumpService" ref="fastJumpService"/>
</bean>
<bean id="http403EntryPoint" class="org.springframework.security.web.authentication.Http403ForbiddenEntryPoint"/>
我嘗試將以下內容添加到安全配置中:
<bean id="filterChainProxy" class="org.springframework.security.web.FilterChainProxy">
<security:filter-chain-map>
<security:filter-chain filters="httpSessionContextIntegrationFilter, securityContextHolderAwareRequest, siteminderFilter" pattern="/fastjump/auth/**"/>
</security:filter-chain-map>
</bean>
<bean id="httpSessionContextIntegrationFilter" class="org.springframework.security.web.context.SecurityContextPersistenceFilter">
<property name="securityContextRepository">
<bean class="org.springframework.security.web.context.HttpSessionSecurityContextRepository">
<property name="allowSessionCreation" value="false"/>
</bean>
</property>
</bean>
<bean id="securityContextHolderAwareRequest" class="org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter">
</bean>
並將其添加到web.xml中:
<!-- This filter is used to implement request level authorization. -->
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<!-- Note that we only send requests which require authentication and authorization services through the
Spring Security filters -->
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/auth/*</url-pattern>
</filter-mapping>
但這現在給/ auth上下文請求增加了一個基本的auth挑戰。 我缺少將緩存與預身份驗證聯系在一起的部分。 有沒有人有什么建議?
事實證明,SSO是問題所在,但不是我們最初的想法。 我們有多個不同的SSO域(DEV,INT,PROD),並且該頁面上有一個自動完成程序,該代碼已硬編碼以發送到Prod域中的Web服務,而Web Service API在此專門排除在外不受SSO保護的生產域(它對所有用戶開放),查詢生產服務器的操作導致對生產SSO域的查詢,並使用生產憑據覆蓋了會話。 回到開發服務器並嘗試使用Prod憑據執行POST失敗,並且在向Dev SSO查詢正確憑據的過程中,它刪除了POST數據,並將html請求類型更改為GET。 我們的解決方案是更新自動填充程序,使其具有邏輯來確定它在哪個服務器上運行(通過JavaScript,查看主機),然后根據我們所處的環境為自動填充程序后端構建URL。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.