2017-04-17 9 views
-1

현재 스프링 플렉스 통합을 사용하고 있으며 스프링을 통해 보안이 유지 된 웹 서비스를 추가하려고합니다.이름이 '_loginCommandPostProcessor'인 bean을 생성하는 중 오류가 발생했습니다.

이렇게하려면 두 개의 HTTP 태그를 만들려고합니까?

봄 보안-config.xml에 나는 다음과 같은 오류 받고 있어요

<?xml version="1.0" encoding="UTF-8"?> 
<beans:beans xmlns="http://www.springframework.org/schema/security" 
    xmlns:beans="http://www.springframework.org/schema/beans" 
    xmlns:context="http://www.springframework.org/schema/context" 
    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-4.3.xsd 
    http://www.springframework.org/schema/security 
    http://www.springframework.org/schema/security/spring-security-4.2.xsd 
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-4.3.xsd"> 

    <context:component-scan base-package="com.somenamespace.login" /> 
    <context:annotation-config/> 

    <beans:bean id="entryPoint" 
     class="org.springframework.flex.security4.FlexAuthenticationEntryPoint"/> 


    <http entry-point-ref="entryPoint" pattern="/messagebroker/**"> 
     <intercept-url pattern="/**" access="authenticated"/> 
     <custom-filter position="FORM_LOGIN_FILTER" ref="myAuthFilter" /> 
     <session-management session-authentication-strategy-ref="sas"/> 
    </http> 

    <http pattern="*"> 
    <intercept-url pattern="/**" access="authenticated"/> 
     <http-basic /> 
     <custom-filter position="FORM_LOGIN_FILTER" ref="myAuthFilter" /> 
     <session-management session-authentication-strategy-ref="sas"/> 
    </http> 

    <beans:bean id="myAuthFilter" class= 
"org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter"> 
     <beans:property name="sessionAuthenticationStrategy" ref="sas" /> 
     <beans:property name="authenticationManager" ref="authenticationManager" /> 

    </beans:bean> 
    <beans:bean id="sas" class="org.springframework.security.web.authentication.session.SessionFixationProtectionStrategy" /> 

    <beans:bean id="switchUserProcessingFilter" class="org.springframework.security.web.authentication.switchuser.SwitchUserFilter"> 
     <beans:property name="userDetailsService" ref="customAuthenticationProvider"/> 
     <beans:property name="switchUserUrl" value="/admin/impersonate"/> 
     <beans:property name="targetUrl" value="/cre/CRE.html"/> 
     <beans:property name="switchFailureUrl" value="/admin/switchUser"/> 
    </beans:bean> 


    <beans:bean id="defaultMessageTemplate" class="org.springframework.flex.messaging.MessageTemplate" /> 

    <beans:bean id="customAuthenticationProvider" class="com.somenamespace.login.CustomAuthenticationProvider"/> 

    <authentication-manager alias="authenticationManager"> 
    <authentication-provider ref="customAuthenticationProvider"/> <  
    </authentication-manager> 

</beans:beans> 

: -

Error creating bean with name '_loginCommandPostProcessor': Unsatisfied dependency expressed through bean property 'sessionAuthenticationStrategy'; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'org.springframework.security.web.authentication.session.SessionAuthenticationStrategy' available: expected single matching bean but found 3: org.springframework.security.web.authentication.session.CompositeSessionAuthenticationStrategy#0,org.springframework.security.web.authentication.session.CompositeSessionAuthenticationStrategy#1,sas 
+0

'sas'와는 달리 스프링 컨텍스트에서 초기화 된 2 개의 bean이 있음을 분명히 알 수 있습니다. 'org.springframework.security.web.authentication.session'을 검사하지 않습니까? 다른 XML 파일에서 선언 될 수 있습니다. –

+0

그게 무슨 뜻인지 잘 모르겠습니다. 내가 스캔하지 않도록하려면 어떻게해야합니까? – DangeRuss

+0

답변을 가능한 해결책으로 아래에 답변으로 게시했습니다. 제발,보세요. –

답변

0

<context:component-scan base-package="com.somenamespace.login" />을 당신이 봄 말하고있다 이것에 의해이 ", com.somenamespace.login를 스캔 초기화하십시오 주석으로 표시된 모든 콩 : @Component, @Repository, @Service, @Controller 내 응용 프로그램 컨텍스트에 ".

그래서, 당신은 재산 sessionAuthenticationStrategy에 autowire가 될 후보 컨텍스트로 초기화 3 콩이 :

  1. sas - com.somenamespace.login를 스캔하여 초기화를 (이 답변의 시작 부분에 선언을 참조).
  2. org.springframework.security.web.authentication.session.CompositeSessionAuthenticationStrategy#0 - 사용자가 초기화 할 것으로 예상하지 않은 bean; 아마도 다른 XML 파일에 컨텍스트 파일이있을 수 있습니다 (해당 응용 프로그램에있는 경우 - 나는 을 모르겠습니다).
  3. org.springframework.security.web.authentication.session.CompositeSessionAuthenticationStrategy#1 - 포인트 2.

봄이 선택할 수있는 하나 모르는 참조하십시오. 따라서 오류가 발생합니다.

  1. 더러운 일,하지만 빠른 :

    난 당신에게 두 가지 가능한 솔루션을 제안 할 수 있습니다. sas 빈을 기본으로 표시합니다. 이와 같이 : <beans:bean id="sas" class="org.springframework.security.web.authentication.session.SessionFixationProtectionStrategy" primary=true/>CompositeSessionAuthenticationStrategy 클래스 또는 SessionAuthenticationStrategy을 구현하는 다른 bean을 응용 프로그램에 삽입해야하지만 sas이 아닌 경우이 솔루션은 적합하지 않습니다. sas.

  2. 더 깨끗한 해결책이지만 더 많은 시간이 필요할 수 있습니다. 은 무엇을 찾아서 예상치 못한 빈을 초기화하고 고칠 수 있는지 알아보십시오. 내가 말했던 것처럼 뷰에서 스프링 컨텍스트 XML 파일의 어딘가에 <context:component-scan /> 선언 (어쨌든 이있는 경우)이 될 수 있습니다.

    행운을 빈다. 이것이 도움이되기를 바랍니다.

관련 문제