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

时间:2012-10-23 13:47:16

标签: spring spring-security

Spring Security 3.1支持多个http元素。

我希望我们的移动网站的安全性基本上总是需要登录,而“普通”网站将有更多的公共页面。

我正在考虑使用Spring Security的多个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。

亲切的问候, 马克

1 个答案:

答案 0 :(得分:2)

您可以使用request-matcher-ref属性代替pattern来注入RequestMatcher个实例,该实例可以使用HttpRequest中的任何数据。使用pattern只是一种特殊情况,AntPathRequestMatcher用于选择过滤器链。

有关可用属性的详细信息,请参阅namespace appendix