2010-10-18 6 views
0

J'ai un problème avec la sécurité de printemps LDAP, j'essaie d'autoriser contre le serveur LDAP. Je le fichier xml de configuration de ressort (sécurité config.xml) comme ceci:Printemps Sécurité LDAP - problème de connexion (ProviderNotFoundException)

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:sec="http://www.springframework.org/schema/security" 
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd 
    http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-2.0.4.xsd"> 

<bean id="contextSource" class="org.springframework.security.ldap.DefaultSpringSecurityContextSource"> 
    <constructor-arg value="ldap://111.111.111.111"/> 
    <property name="userDn" value="cn=auth-user,ou=System,dc=foo,dc=com"/> 
    <property name="password" value="fooPwd"/> 
</bean> 

<bean id="ldapAuthProvider" class="org.springframework.security.providers.ldap.LdapAuthenticationProvider"> 
    <constructor-arg> 
    <bean class="org.springframework.security.providers.ldap.authenticator.BindAuthenticator"> 
    <constructor-arg ref="contextSource"/> 
    <property name="userSearch"> 
    <bean id="userSearch" class="org.springframework.security.ldap.search.FilterBasedLdapUserSearch"> 
     <constructor-arg index="0" value="ou=people"/> 
     <constructor-arg index="1" value="(uid={0})"/> 
     <constructor-arg index="2" ref="contextSource" /> 
    </bean> 
    </property> 
    </bean> 
    </constructor-arg> 
    <constructor-arg> 
    <bean class="com.company.name.services.UserAuthoritiesPopulator" /> 
    </constructor-arg> 
</bean> 
</beans> 

Dans le contrôleur de connexion (LoginController.java) J'autorise comme ceci:

@RequestMapping(value = "/login", method = RequestMethod.POST) 
public String loginPPost(String username, String password, Model model, HttpServletRequest req, HttpServletResponse res) throws SQLException { 

UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken(username, password); 
Authentication authentication = authenticationManager.authenticate(authRequest); 
SecurityContextHolder.getContext().setAuthentication(authentication); 
... 
} 

La méthode " authenticationManager.authenticate (authRequest) » lance cette exception:

org.springframework.security.providers.ProviderNotFoundException: No AuthenticationProvider found for org.springframework.security.providers.UsernamePasswordAuthenticationToken 
    at org.springframework.security.providers.ProviderManager.doAuthentication(ProviderManager.java:214) 
    at org.springframework.security.AbstractAuthenticationManager.authenticate(AbstractAuthenticationManager.java:46) 

Quelqu'un sait comment résoudre ce problème? Dois-je utiliser une méthode différente pour l'autorisation? Ou ma configuration est-elle mauvaise?

Merci pour toute aide,

Mateo

Répondre

1

Vous devez ajouter le tag 'sec: fournisseur sur mesure authentification' dans votre fournisseur d'authentification bean:

<bean id="ldapAuthProvider" class="org.springframework.security.providers.ldap.LdapAuthenticationProvider"> 
    <sec:custom-authentication-provider/> 
    ... 
</bean> 

Vous pouvez trouver un exemple qui utilise Crowd au lieu de LDAP sur mon blog: http://aloiscochard.blogspot.com/2009/12/integrating-spring-security-with-ntlm_19.html

+0

Merci beaucoup! Ça m'a aidé. Je me demande juste que je n'ai pas pu le trouver n'importe où dans le document Spring Secuirty: - / – mateo

Questions connexes