【问题标题】:Skip certain path on Spring SAML SSO跳过 Spring SAML SSO 上的某些路径
【发布时间】:2016-07-03 03:29:07
【问题描述】:
网站contextPath为root,http://localhost:8080,使用Spring security SAML实现单点登录。无论在 localhost:8080 根路径下输入什么 url,它都会指向 IDP 提供者进行身份验证,目前为止是正确的。
我想要的是localhost:8080/unsecure目录下,用户无需重定向到IDP进行认证即可访问。我不知道在哪里配置来告诉 SAML 跳过某些路径。
【问题讨论】:
标签:
spring-security
spring-saml
【解决方案1】:
在您的 security-applicationContext.xml 文件中,您必须在配置 spring-security-saml 时映射类似这样的 url:
<!-- Unsecured pages -->
<security:http security="none" pattern="/favicon.ico"/>
<security:http security="none" pattern="/images/**"/>
<security:http security="none" pattern="/css/**"/>
<security:http security="none" pattern="/logout.jsp"/>
<!-- Security for the administration UI -->
<security:http pattern="/saml/web/**" use-expressions="false">
<security:access-denied-handler error-page="/saml/web/metadata/login"/>
<security:form-login login-processing-url="/saml/web/login" login-page="/saml/web/metadata/login" default-target-url="/saml/web/metadata"/>
<security:intercept-url pattern="/saml/web/metadata/login" access="IS_AUTHENTICATED_ANONYMOUSLY"/>
<security:intercept-url pattern="/saml/web/**" access="ROLE_ADMIN"/>
<security:custom-filter before="FIRST" ref="metadataGeneratorFilter"/>
</security:http>
<!-- Secured pages with SAML as entry point -->
<security:http entry-point-ref="samlEntryPoint" use-expressions="false">
<security:intercept-url pattern="/**" access="IS_AUTHENTICATED_FULLY"/>
<security:custom-filter before="FIRST" ref="metadataGeneratorFilter"/>
<security:custom-filter after="BASIC_AUTH_FILTER" ref="samlFilter"/>
</security:http>
在这里,我们允许无需登录即可使用图像、css、favicon 等。所以添加更多的 URL 到不安全的映射列表,如果你希望它在没有身份验证的情况下可用。