【问题标题】:How can I use basic authentication and form based authentication spring security如何使用基本身份验证和基于表单的身份验证 Spring Security
【发布时间】:2015-02-06 19:31:27
【问题描述】:

所以我正在寻找一种在同一资源上使用基于表单的身份验证和基本身份验证的编程配置方式。我的意思是,如果我填写登录表单并进行身份验证,我应该能够使用该网站。同时,如果我使用基本身份验证进行身份验证,我应该能够访问相同的资源。可能吗?我什至在想可能使用 DelegatingAuthenticationEntryPoint ,如果指定了某个标头,它将使用基本的,否则它将使用基于表单的登录。无论如何,任何帮助将不胜感激?

【问题讨论】:

  • 有点混乱,但要澄清一下,您是否想同时拥有基于表单的登录身份验证和等效于 AD/SSO 登录功能?
  • 你为什么想要这个?
  • 你想要的当然是可能的。您的应用程序应同时支持 cookie 和基本身份验证。

标签: spring forms security authentication


【解决方案1】:

我认为您应该查看Spring Security Current Reference Documentation 中http 元素的request-matcher-ref 属性。它使您能够指定使用或不使用特定FilterChain 的自定义条件。例如,您可以根据传入请求的主机头来确定使用哪种认证机制。

<bean id="customMatcher1" class="org.springframework.security.web.util.matcher.ELRequestMatcher">
    <constructor-arg value="hasHeader('host', 'stackoverflow.com')"/>
</bean>
<bean id="customMatcher2" class="org.springframework.security.web.util.matcher.ELRequestMatcher">
    <constructor-arg value="hasHeader('host', 'careers.stackoverflow.com')"/>
</bean>
<sec:http request-matcher-ref="customMatcher1">
    <sec:http-basic />
</sec:http>
<sec:http request-matcher-ref="customMatcher2">
    <sec:form-login />
</sec:http>

查看并选择现有实现之一,或者查看并编写自己的 RequestMatcher 接口实现。

【讨论】:

    猜你喜欢
    • 2010-11-20
    • 2011-02-11
    • 2016-03-20
    • 1970-01-01
    • 2013-01-01
    • 2013-09-14
    • 2017-07-08
    • 2012-08-15
    • 2013-01-11
    相关资源
    最近更新 更多