繁体   English   中英

Spring Security-从SSO缓存凭据

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM