2

Web アプリケーションに春のセキュリティを実装しようとしています。問題は、私の Web が b2b と b2c の 2 つの環境で動作することです。

b2b 環境では、ユーザー名とパスワードによる春のセキュリティ制御と、数ページのみの b2c が必要です。

例えば:

  www.myb2b.com/home  -> login required
  www.myb2c.com/home  -> no login required
  www.myb2c.com/private/admin  -> login required

最も重要なフィルターは 1 番目と 2 番目のフィルターで、3 番目のフィルターは他のシステムで実現できます。

これどうやってするの?

カスタム FilterSecurityInterceptor を構成して doFilter 関数をオーバーライドしようとしています。しかし、競合のエラーが発生しています。

私の appContext-web-security.xml (まだ開発中のため、完全ではありません):

<beans:beans
xmlns="http://www.springframework.org/schema/security"
    xmlns:beans="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-3.1.xsd
                    http://www.springframework.org/schema/security
                    http://www.springframework.org/schema/security/spring-security-3.1.xsd">
    <http auto-config="false" use-expressions="true" entry-point-ref="loginUrlAuthenticationEntryPoint">
        <custom-filter position="FILTER_SECURITY_INTERCEPTOR" ref="filterSecurityInterceptor" />

        <intercept-url pattern="/**" access="ROLE_USER" />
    </http>

    <beans:bean id="loginUrlAuthenticationEntryPoint" class="org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint">
        <beans:property name="loginFormUrl" value="/login"/>
    </beans:bean>

    <beans:bean id="filterSecurityInterceptor" class="com.hotelbeds.tuiuk.web.spring.CustomSecurityInterceptor">
        <beans:property name="observeOncePerRequest" value="true"/>
        <beans:property name="authenticationManager" ref="authenticationManager" />
        <beans:property name="accessDecisionManager" ref="accessDecisionManager" />
    </beans:bean>

    <beans:bean id="accessDecisionManager" class="org.springframework.security.access.vote.AffirmativeBased">
        <beans:property name="decisionVoters">
            <beans:list>
                <beans:bean class="org.springframework.security.access.vote.RoleVoter" />
            </beans:list>
        </beans:property>
    </beans:bean>


    <authentication-manager alias="authenticationManager">
        <authentication-provider>
            <password-encoder hash="sha-256" />
            <user-service>
                <user name="admin"
                    password="8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918"
                    authorities="ROLE_ADMIN" />
                <user name="user"
                    password="04f8996da763b7a969b1028ee3007569eaf3a635486ddab211d512c85b9df8fb"
                    authorities="ROLE_USER" />
            </user-service>
        </authentication-provider>
    </authentication-manager>
</beans:beans>
4

1 に答える 1

0

要件が明確であれば、コード レベルのカスタマイズなしで実装するのは非常に簡単です。

<bean id="b2bHostMatcher" class="org.springframework.security.web.util.ELRequestMatcher">
    <constructor-arg value="hasHeader('host','myb2b.com')"/>
</bean>

<bean id="b2cHostMatcher" class="org.springframework.security.web.util.ELRequestMatcher">
    <constructor-arg value="hasHeader('host','myb2c.com')"/>
</bean>

<security:http request-matcher-ref="b2bHostMatcher" ...>
    <!-- config for b2b requests -->
</security:http>


<security:http request-matcher-ref="b2cHostMatcher" ...>
    <!-- config for b2c requests -->
</security:http>

<http>IDE は、どちらも属性を持たない2 つの要素について不平を言うかもしれませんがpattern、両方がデフォルトを使用した場合にのみ問題になるため、安全に無視できますAntPathRequestMatcher

于 2013-02-19T17:41:59.580 に答える