2011-04-27 3 views
2

사용자의 컨텍스트 경로에 따라 Spring Security 구성을 기반으로하고 싶습니다. 사용자가 http://path1/resource1으로 URL을 위반하는 경우 해당 사용자를 특정 인증 공급자로 안내하고 싶습니다. 그들이 http://path2/resource2에 오면 다른 인증 공급자에게 보내고 싶습니다. 이 URL 경로는 REST 기반 웹 서비스 호출이므로 상태가없고 양식에서 오는 것이 아닙니다. 현재 모든 인증 공급자가 실행됩니다. 이 상황에 가장 적합한 방법은 무엇입니까? 저는 봄 보안 3.1.0.M1을 사용하고 있습니다.각 http 블록을 특정 인증 제공자에 매핑하기

<http pattern="/path1/**" create-session="stateless"> 
     <intercept-url pattern="/**" access="ROLE_USER,ROLE_VAR,ROLE_ADMIN" /> 
     <http-basic />  
</http> 
<http pattern="/path2/**" create-session="stateless"> 
     <intercept-url pattern="/**" access="ROLE_USER,ROLE_VAR,ROLE_ADMIN" /> 
     <http-basic />  
</http> 

답변

0

이것은 나를 위해 작동 : 나는 특정 상황에서 특별한 오류 코드를 보낼 필요가 있었기 때문에

<security:authentication-manager alias="basicAuthenticationManager"> 
    <security:authentication-provider user-service-ref="accountService"> 
    <security:password-encoder hash="sha"/> 
    </security:authentication-provider> 
    <security:authentication-provider user-service-ref="accountService"/> 
</security:authentication-manager> 

<bean id="basicProcessingFilter" class="org.springframework.security.web.authentication.www.BasicAuthenticationFilter"> 
    <property name="authenticationManager"> 
     <ref bean="basicAuthenticationManager" /> 
    </property>  
    <property name="authenticationEntryPoint"> 
     <ref bean="basicProcessingEntryPoint" /> 
    </property> 
</bean> 

<bean id="basicProcessingEntryPoint" 
    class="com.yourpackage.web.util.CustomBasicAuthenticationEntryPoint"> 
    <property name="realmName" value="yourRealm" /> 
</bean> 

<!-- Stateless RESTful service using Basic authentication --> 
<security:http pattern="/rest/**" create-session="stateless" entry-point-ref="basicProcessingEntryPoint">  
    <security:custom-filter ref="basicProcessingFilter" position="BASIC_AUTH_FILTER" />  
    <security:intercept-url pattern="/rest/new" access="IS_AUTHENTICATED_ANONYMOUSLY" /> 
    <security:intercept-url pattern="/rest/**" access="ROLE_USER" /> 
</security:http> 

<!-- Additional filter chain for normal users, matching all other requests --> 
<security:http use-expressions="true"> 
    <security:intercept-url pattern="/index.jsp" access="permitAll" />  
    <security:intercept-url pattern="/**" access="hasRole('ROLE_USER')" /> 

    <security:form-login login-page="/signin" 
     authentication-failure-url="/signin?signin_error=1" 
     default-target-url="/" 
     always-use-default-target="true"/>  
    <security:logout /> 
</security:http> 

나는 인증 진입 점을 구현하지만 당신은 그렇게 할 필요가 없습니다.

당신은 각 HTTP 블록에 인증 관리자 참조 정의 할 수 있습니다
+0

응답 martincastell에 감사드립니다. 한 가지 확실한 점은 나머지 http 블록을 하나의 인증 공급자에 매핑하면서 양식 http 블록을 다른 인증 공급자에 매핑하는 방법입니다. 그게 내가 성취하려고하는 것이고 당신에게보기에 분명하지 않다. 감사! – c12

7

:이 기능은 스프링 시큐리티 3.1에 추가 된

<http pattern="/api/**" authentication-manager-ref="apiAccess"> 
    ... 
</http> 

<http auto-config = "true" authentication-manager-ref="webAccess"> 
    ... 
</http> 

<!-- Web authentication manager --> 
<authentication-manager id="webAccess"> 
    <authentication-provider 
     user-service-ref="userService"> 
    </authentication-provider> 
</authentication-manager> 

<!-- API authentication manager -->  
<authentication-manager id="apiAccess"> 
    <authentication-provider 
     user-service-ref="developerService"> 
    </authentication-provider> 
</authentication-manager> 

합니다.

+2

'authentication-manager'에는'alias'보다는'id'를 사용합니다. '별칭'을 사용하면 스프링 보안이 잘못된 인증 관리자를 선택할 수 있습니다. – Raedwald