2016-05-06 4 views
1

Я изо всех сил пытаюсь настроить конфигурацию безопасности LDAP с конфигурацией xml.LDAP Authentication - Spring Security - LdapAuthenticationProvider

Я получаю следующее сообщение об ошибке:

org.springframework.beans.factory.BeanCreationException: Error creating bean    with name 'securityConfig': Injection of autowired dependencies failed; nested  exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.security.ldap.authentication.LdapAuthenticationProvider sgcbmw.security.SecurityConfig.ldapAuthenticationProvider; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.security.ldap.authentication.LdapAuthenticationProvider] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: @org.springframework.beans.factory.annotation.Autowired(required=true) 

Моя конфигурация безопасности:

<bean id="contextSource"class="org.springframework.security.ldap.DefaultSpringSecurityContextSource"> 
     <constructor-arg value="ldap:/ldapserver"/> 
     <property name="userDn" value="user"/> 
     <property name="password" value="pass"/> 
    </bean> 

    <bean id="ldapAuthProvider" 
      class="org.springframework.security.ldap.authentication.LdapAuthenticationProvider"> 
     <constructor-arg> 
      <bean class="org.springframework.security.ldap.authentication.BindAuthenticator"> 
       <constructor-arg ref="contextSource"/> 
       <property name="userSearch"> 
       <bean id="userSearch" 
         class="org.springframework.security.ldap.search.FilterBasedLdapUserSearch"> 
        <constructor-arg index="0" value=""/> 
        <constructor-arg index="1" value="(&amp;(objectClass=user)(sAMAccountName={0}))"/> 
        <constructor-arg index="2" ref="contextSource" /> 
       </bean> 
       </property> 
       <property name="userDnPatterns"> 
        <list><value>uid={0},ou=people</value></list> 
       </property> 
      </bean> 
     </constructor-arg> 
     <constructor-arg> 
      <bean class="org.springframework.security.ldap.userdetails.DefaultLdapAuthoritiesPopulator"> 
       <constructor-arg ref="contextSource"/> 
       <constructor-arg value="ou=groups"/> 
       <property name="groupRoleAttribute" value="memberOf"/> 
      </bean> 
     </constructor-arg> 
    </bean> 
    <security:authentication-manager> 
     <security:authentication-provider ref="ldapAuthProvider" /> 
    </security:authentication-manager> 

конфигурации адаптера:

@Configuration 
@EnableWebSecurity 
public class SecurityConfig extends WebSecurityConfigurerAdapter { 

@Autowired 
private LdapAuthenticationProvider ldapAuthenticationProvider; 

@Override 
protected void configure(AuthenticationManagerBuilder auth) throws Exception { 
    auth.authenticationProvider(ldapAuthenticationProvider); 
} 

@Override 
protected void configure(HttpSecurity http) throws Exception { 
    http 
      .csrf().disable() 
      .authorizeRequests() 
      .anyRequest().fullyAuthenticated() 
      .and() 
      .formLogin(); 
} 
} 

Если не впрыскивать LdapAuthenticationProvider этот путь?

+0

Ваш контекст проанализирован вообще? – Palcente

+0

Что вы подразумеваете под анализом? В Сети, XML У меня есть следующий код: <контекстно-параметры> contextConfigLocation классам: весна/бизнес-config.xml Ricardo

+0

Попробуйте это, может помочь: инъецируя с помощью установщика ldapAuthenticationProvider, создайте сеттер ldapAuthenticationProvider в классе SecurityConfig, удалите @Autowired аннотацию. – PeaceIsPearl

ответ

0

Что решить мою проблему:

Я создал конфигурации XML один контекст только для безопасности и добавил следующее web.xml:

<context-param> 
    <param-name>contextConfigLocation</param-name> 
    <param-value>classpath:spring/business-config.xml classpath:spring/spring-security-config.xml</param-value> 
</context-param> 

И, наконец, я позволяю конфигурации фасоль на моей весны -security-config.xml и Autowire в моем классе WebSecurityConfigurerAdapter. Удалено это из xml:

<security:authentication-manager> 
    <security:authentication-provider ref="ldapAuthProvider" /> 
</security:authentication-manager> 

Спасибо за помощь.

Смежные вопросы