2009-08-19 3 views

답변

6

당신이 가능 원하는 최종 결과, 그 똑같은 문제로 실행하고 여기 내 솔루션입니다했다.

언제가 자동으로 네임 스페이스를 통해 적용되는 다른 인증 필터를 무시합니다 네임 스페이스에서 폼 로그인을 정의. 이것은 스프링 보안의 FilterChainOrder.java에서의 필터 체인보기의 순서를 통해 각 필터에 실제로 순서가 적용되는 방식을 확인하는 방식으로 수행됩니다.

이 문제를 해결하려면 네임 스페이스에서 http-basic 태그를 제거한 다음 기본 인증을 처리 할 Bean을 수동으로 정의하고 AuthenticationProcessingFilter 앞에 순서를 지정하십시오. 이는 폼 로그인을 처리 할 스프링 보안 필터이기 때문입니다.

BasicProcessingFilter 봄은 기본 인증 처리를 제공합니다. 수동 인증 필터는 자격 증명이 누락 된 경우 요청을 처리 할 적절한 필터를 찾을 때까지 필터 체인을 계속 사용함을 의미합니다. 수동으로 BasicProcessingFilter가 빈 우리가 필터 체인에 나타납니다 순서를 설정할 수를 정의하여 지금

. 이 다음은 보안 XML로 제공해야합니다 추가 XML 선언의 예입니다 (봄 보안 < 3.X) 당신의 AuthenticationManager 참조하면 별칭을 추가 할 수없는 경우

<bean id="basicProcessingFilter" class="org.springframework.security.ui.basicauth.BasicProcessingFilter"> 
    <property name="authenticationManager"><ref bean="authenticationManager"/></property> 
    <security:custom-filter before="AUTHENTICATION_PROCESSING_FILTER"/> 
    <property name="authenticationEntryPoint"><ref bean="authenticationEntryPoint"/></property> 
</bean> 

<bean id="authenticationEntryPoint" 
    class="org.springframework.security.ui.basicauth.BasicProcessingFilterEntryPoint"> 
       <property name="realmName" value="My Realm Here"/> 
</bean> 

이 또한주의 네임 스페이스는 아래와 같습니다.

<security:authentication-manager alias="authenticationManager"/> 

결과적 기본 필터는 수동 필터로서 적용되며, 그 필요한 인증 정보가없는 경우는 필터 체인하고이를 처리하는 폼 로그인 필터를 계속한다.

이 방법의 문제점은 자격 증명을 올바르게 입력하면 응답이 form-login 필터의 로그인 페이지라는 것입니다.

그러나이 문제는 스프링 보안 버전 3.1에서 수정 될 예정이며이 문제는 더 이상 필요하지 않습니다.

10

response by @grimesjm이 맞습니다. 당신이 봄 3.X를 사용하는 경우, 당신은에 클래스 이름을 적응해야 :

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

<bean id="authenticationEntryPoint" 
    class="org.springframework.security.web.authentication.www.BasicAuthenticationEntryPoint"> 
    <property name="realmName" value="Your realm here" /> 
</bean> 

그리고

<sec:http auto-config="true"> 
    ... your intercept-url here 

    <sec:custom-filter before="SECURITY_CONTEXT_FILTER" ref="basicProcessingFilter" /> 

    <sec:form-login ... /> 
    .... 
</sec:http> 

내가 SECURITY_CONTEXT_FILTER하기 전에 필터를 배치하는 것이 최선의 선택인지 여부를 알 수없는 .

1

이제 스프링 시큐리티 3.1로 가능합니다.0

+1

이것은 정확합니다, 여기에이 답변을 확장 할 링크가 있습니다 : http://stackoverflow.com/questions/3671861/two-realms-in-same-application-with-spring-security –

+0

나는 목표가 REST API가 동일한 영역 내에서 두 가지 인증을 모두 지원하도록하십시오. 두 영역을 정의하는 것은 두 가지 전쟁을 정의하는 것과 같습니다. 작동하지만 이상적이지는 않습니다. – Eugen