복붙노트

[SPRING] 이름이 AuthenticationManager 인 빈을 만드는 중 오류가 발생했습니다.

SPRING

이름이 AuthenticationManager 인 빈을 만드는 중 오류가 발생했습니다.

Spring Security를 ​​사용하는 Spring MVC 애플리케이션을 개발 중이다. 로그인 응용 프로그램에서 나는 2 개의 로그인 URL을 사용해야합니다.

UserDetails와 userDetailsService를 구현 한 데이터베이스에 대한 로그인 URL 확인. 로그인을 위해이 두 url을 연결하려면 springSecurityFilterChain을 사용하고 있습니다. 불행히도 작동하지 않습니다. 나는 2 일 이래로이 문제에 빠져있다. 어리석은 실수를 저지르고 있을지도 모른다. 친절하게 로그와 xml을 확인하고,

오류 기록 :

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.authenticationManager': Could not resolve matching constructor (hint: specify index/type/name arguments for simple parameters to avoid type ambiguities)
    at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:239)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1114)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1017)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
    at org.springframework.security.config.authentication.AuthenticationManagerFactoryBean.getObject(AuthenticationManagerFactoryBean.java:28)
    at org.springframework.security.config.authentication.AuthenticationManagerFactoryBean.getObject(AuthenticationManagerFactoryBean.java:20)
    at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:168)

security-application-context.xml

<security:http create-session="ifRequired" use-expressions="true"
               auto-config="true" disable-url-rewriting="true">
    <security:form-login login-page="/" default-target-url="/canvas/list"
               always-use-default-target="false"  authentication-failure-url="/denied.jsp" />
<security:logout logout-success-url="/" delete-cookies="JSESSIONID"
                     invalidate-session="true" logout-url="/j_spring_security_logout"/>
</security:http>



<bean id="springSecurityFilterChain" class="org.springframework.security.web.FilterChainProxy">
        <security:filter-chain-map path-type="ant">
            <security:filter-chain pattern="/**" filters="authenticationProcessingFilterForPersonal, authenticationProcessingFilterForGroup"/>
        </security:filter-chain-map>
    </bean>


    <bean id="authenticationProcessingFilterForPersonal"
          class="org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter">
        <property name="authenticationManager" ref="authenticationManagerForPersonal"/>
        <property name="filterProcessesUrl" value="/j_spring_security_check_for_person" />
    </bean>

    <bean id="authenticationProcessingFilterForGroup"
          class="org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter">
        <property name="authenticationManager" ref="authenticationManagerForGroup"/>
        <property name="filterProcessesUrl" value="/j_spring_security_check_for_group"/>
    </bean>


    <bean id="authenticationManagerForPersonal" class="org.springframework.security.authentication.ProviderManager">
    <property name="providers">
            <list>
                <bean class="org.springframework.security.authentication.dao.DaoAuthenticationProvider">
                    <property name="userDetailsService">
                        <ref bean="userDetailsService"/>
                    </property>
                    <property name="passwordEncoder" ref="encoder"/>
                </bean>
            </list>
        </property>
    </bean>



    <bean id="authenticationManagerForGroup" class="org.springframework.security.authentication.ProviderManager">
        <property name="providers">
            <list>
                <bean class="org.springframework.security.authentication.dao.DaoAuthenticationProvider">
                    <property name="userDetailsService">
                        <ref bean="groupDetailsService"/>
                    </property>
                    <property name="passwordEncoder" ref="encoder"/>
                </bean>
            </list>
        </property>
    </bean>

    <security:authentication-manager alias="authenticationManager">
        <security:authentication-provider ref="authenticationManagerForPersonal"/>
        <security:authentication-provider ref="authenticationManagerForGroup"/>
    </security:authentication-manager>


    <beans:bean id="encoder"
                class="org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder">
        <beans:constructor-arg name="strength" value="11" />
    </beans:bean>

인증 관리자 코드를 아래 스 니펫으로 바꾸면 오류가 발생하지 않지만 2 개의 로그인 URL은 등록되지 않았습니다.

<security:authentication-manager alias="authenticationManager">
            <security:authentication-provider user-service-ref="userDetailsService">
                <security:password-encoder ref="encoder"/>
            </security:authentication-provider>
            <security:authentication-provider user-service-ref="groupDetailsService">
                <security:password-encoder ref="encoder"/>
            </security:authentication-provider>
        </security:authentication-manager>-->

해결법

  1. ==============================

    1.authenticationManagerForPersonal 및 authenticationManagerForGroup은 빈 유형 ProviderManager입니다. 이것은 잘못된 것입니다. 이러한 bean을 DaoAuthenticationProvider 유형으로 선언해야합니다. 내 봄 보안 구성을 자세히 살펴보십시오.

    authenticationManagerForPersonal 및 authenticationManagerForGroup은 빈 유형 ProviderManager입니다. 이것은 잘못된 것입니다. 이러한 bean을 DaoAuthenticationProvider 유형으로 선언해야합니다. 내 봄 보안 구성을 자세히 살펴보십시오.

  2. ==============================

    2.예외 메시지에서 알 수 있듯이 authenticationManagerForGroup 및 authenticationManagerForPersonal이 잘못 구성되었습니다. 형식 서명 및 JavaDoc에서 검색 할 수 있으므로 ProviderManager는 생성자 인수로 AuthenticationManager 목록을 사용하지만 AuthenticationManager를 등록 정보 인수로 구성합니다.

    예외 메시지에서 알 수 있듯이 authenticationManagerForGroup 및 authenticationManagerForPersonal이 잘못 구성되었습니다. 형식 서명 및 JavaDoc에서 검색 할 수 있으므로 ProviderManager는 생성자 인수로 AuthenticationManager 목록을 사용하지만 AuthenticationManager를 등록 정보 인수로 구성합니다.

    요소를 로 대체하여이 작업을 수행 할 수 있어야합니다.

  3. from https://stackoverflow.com/questions/28041310/error-creating-bean-with-name-authenticationmanager by cc-by-sa and MIT license