【问题标题】:SAML OAuth Integration - toggle SAMLSAML OAuth 集成 - 切换 SAML
【发布时间】:2016-02-21 00:47:19
【问题描述】:

我们正在实现配置 OAuth 或 SAML 或同时配置 OAuth 和 SAML 的灵活性。在 saml 安全上下文中配置以下内容:

<security:http pattern="/oauth/authorize/**" entry-point-ref="samlEntryPoint" use-expressions="true">
<security:custom-filter after="BASIC_AUTH_FILTER" ref="samlFilter" />
 ........
 ........

<bean id="samlFilter" class="org.springframework.security.web.FilterChainProxy">
        <security:filter-chain pattern="/saml/login/**" filters="samlEntryPoint" />     
        <security:filter-chain pattern="/saml/metadata/**" filters="metadataDisplayFilter" />
        <security:filter-chain pattern="/saml/SSO/**" filters="samlWebSSOProcessingFilter" />
        <security:filter-chain pattern="/saml/SingleLogout/**" filters="samlLogoutProcessingFilter" />
        <security:filter-chain pattern="/oauth/authorize/**" filters="samlEntryPoint" />
    </security:filter-chain-map>
</bean>

有一个可配置的属性决定 SAML 是启用还是禁用。禁用 SAML 时,如何跳过调用 samlEntryPoint?切换 SAML 时总是会重新启动应用程序,我不必考虑在应用程序运行时打开/关闭它的用例。

感谢任何帮助。

【问题讨论】:

    标签: spring-security spring-security-oauth2 spring-saml


    【解决方案1】:

    如何在禁用 SAML 时跳过 samlEntryPoint?

    要拥有各种身份验证方案,您可以使用 Spring 配置文件并编写单独的安全上下文文件。这就是你的做法:

    <beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
                           http://www.springframework.org/schema/beans/spring-beans.xsd">
    
        <!-- Spring Security configuration for SAML only authentication --> 
        <beans profile="auth-saml">
            <import resource="security/applicationContext-security-saml.xml" />
        </beans>
    
        <!-- Spring Security configuration for OAUTH only authentication -->
        <beans profile="auth-oauth">
            <import resource="security/applicationContext-security-oauth.xml" />
        </beans>
    
        <!-- Spring Security configuration for SAML+OAUTH authentication -->
        <beans profile="auth-saml-oauth">
            <import resource="security/applicationContext-security-saml-oauth.xml" />
        </beans>
    
    </beans>
    

    然后您选择带有环境变量 spring.profiles.active 的活动 Spring 配置文件,其值对应于配置文件属性值(auth-samlauth-oauthauth-saml-oauth)。

    【讨论】:

    • 感谢您的及时回复。
    • 我决定使用 spel 以下列方式执行此操作: entry-point-ref="#{ ssoEnabled ? 'samlEntryPoint' : 'loginUrlAuthenticationEntryPoint'}"
    【解决方案2】:

    除了 Gregoire 的响应之外,您还可以创建诸如 multiAuthenticationEntryPoint 之类的类 - 它将这些入口点作为属性 - 您可以在其中实现

    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response,
            AuthenticationException authException) throws IOException, ServletException {
        // TODO Auto-generated method stub
        if(sth) 
            {
            customAuthenticationEntryPoint.commence(request, response, authException);
            return;
            }
        else {
            samlEntryPoint.commence(request, response, authException);
            return;
        }
    
    }
    

    【讨论】:

      猜你喜欢
      • 2019-12-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多