在具有多个http元素的模式中使用服务器名Spring Security?

在具有多个http元素的模式中使用服务器名Spring Security?,spring,spring-security,Spring,Spring Security,SpringSecurity3.1支持多个http元素 我想有我们的移动网站的安全性,基本上总是需要登录,而“正常”的网站将有更多的公共页面 我曾考虑使用SpringSecurity的多http元素特性来实现这一点,但在模式字段中找不到任何关于使用服务器名称(例如m.site.com)等变量的信息 我可以在http模式字段中使用请求变量吗。如果是,怎么做 以下是我尝试过的一些代码: <http security="none" pattern="/assets/**"/> &l

SpringSecurity3.1支持多个http元素

我想有我们的移动网站的安全性,基本上总是需要登录,而“正常”的网站将有更多的公共页面

我曾考虑使用SpringSecurity的多http元素特性来实现这一点,但在模式字段中找不到任何关于使用服务器名称(例如m.site.com)等变量的信息

我可以在http模式字段中使用请求变量吗。如果是,怎么做

以下是我尝试过的一些代码:

    <http security="none" pattern="/assets/**"/>
<!-- 
<http use-expressions="true" request-matcher-ref="mobileHttpConfigSelector" entry-point-ref="myAuthenticationProcessingFilterEntryPoint" >

    <intercept-url pattern="/*/*/login.html"  access="permitAll" />
    <intercept-url pattern="/*/*/registration/**"  access="permitAll" />
    <intercept-url pattern="/**"  access="isAuthenticated()" />

    <anonymous enabled="true" granted-authority="ROLE_ANONYMOUS"/>
    <remember-me services-ref="rememberMeServices" key="${msa.security.key}" use-secure-cookie="true"/>
    <custom-filter position="CONCURRENT_SESSION_FILTER" ref="concurrencyFilter" />
    <custom-filter position="FORM_LOGIN_FILTER" ref="myUserPassFilter"/>
    <custom-filter position="LOGOUT_FILTER" ref="myLogoutFilter"/>
    <custom-filter ref="countrySelectFilter" before="FIRST" />
    <custom-filter ref="userAgentFilter" before="LAST" />

    <session-management invalid-session-url="/" session-authentication-strategy-ref="sas">
    </session-management>
</http>
-->
<http use-expressions="true" entry-point-ref="myAuthenticationProcessingFilterEntryPoint" >

    <intercept-url pattern="/*/*/account/**" access="isAuthenticated()" />

    <intercept-url pattern="/**"  access="permitAll" />

    <anonymous enabled="true" granted-authority="ROLE_ANONYMOUS"/>
    <remember-me services-ref="rememberMeServices" key="${msa.security.key}" use-secure-cookie="true"/>

    <custom-filter position="CONCURRENT_SESSION_FILTER" ref="concurrencyFilter" />
    <custom-filter position="FORM_LOGIN_FILTER" ref="myUserPassFilter"/>
    <custom-filter position="LOGOUT_FILTER" ref="myLogoutFilter"/>
    <custom-filter ref="countrySelectFilter" before="FIRST" />
    <custom-filter ref="userAgentFilter" before="LAST" />

    <session-management invalid-session-url="/" session-authentication-strategy-ref="sas">
        <!-- <concurrency-control max-sessions="2" error-if-maximum-exceeded="false" session-registry-alias="sessionRegistry"/>-->
    </session-management>
</http>
<global-method-security secured-annotations="enabled" pre-post-annotations="enabled"/>

<beans:bean id="mobileHttpConfigSelector" class="nl.msw.compraventa.interceptor.security.MobileHttpConfigSelector"/>

mobileHttpConfigSelector的http部分已被注释掉,因为如果激活,则不会定义类型为[org.springframework.security.web.context.SecurityContextRepository]的唯一bean

亲切问候,,
Marc

您可以使用
请求匹配器ref
属性而不是
模式
来插入
请求匹配器
实例,该实例可以使用
HttpRequest
中的任何数据。使用
模式
只是一种特殊情况,其中使用选择过滤器链


有关可用属性的更多信息,请参阅。

Cool。我只是想知道您是否可以使用它来选择适当的http配置,然后让spring security从那里使用它的标准拦截url。看起来是:是。结果是:不是。我试过了,我不能使用两个http定义和一个在这两个定义之间切换的请求匹配器。我得到了一个错误提示我需要使用一个模式来区分这两者。问题是:模式是相同的。不同的是服务器名称。有什么想法吗?使用request matcher ref的第一个备选http配置也会引发一个错误:没有定义类型为[org.springframework.security.web.context.securityContentExtrepository]的唯一bean。我建议您发布代码,因为从您的注释中看不出您做了什么或出现了什么错误。在筛选器链中,所有客户端提供的信息都可以访问请求。所以,当您说“服务器名”时,您应该问问自己,这在请求方面意味着什么。从您的描述中我不太清楚,但我猜它可以从
requestURI
属性或HTTP客户端应该发送的主机头中获得。好的,我已经用代码更新了我的原始帖子。问题不是我不能创建RequestMatcher。问题是如何根据某些请求属性的值(在本例中为服务器名称)进行不同的http配置。