Printemps LDAP bind pour le succès de la connexion

J'essaie d'authentifier et puis notre requête LDAP de l'entreprise à l'aide de Printemps LDAP et de la sécurité Printemps. J'ai réussi à faire de l'authentification de travail, mais lorsque je tente d'exécuter la recherche je reçois toujours l'exception suivante

Pour effectuer cette opération un succès de la liaison doit être complété sur la connexion

Après beaucoup de recherches, j'ai une théorie qui après que je l'authentifier et avant que je puisse requête j'ai besoin de se lier à la connexion. Je ne sais pas quoi, et comment?

Pour n'en citer que - je peux parcourir avec succès et de la recherche dans notre LDAP à l'aide de JXplorer si mes paramètres sont corrects.

Voici l'article de mon securityContext.xml

<security:http auto-config='true'>
    <security:intercept-url pattern="/reports/goodbye.html" 
            access="ROLE_LOGOUT" />
    <security:intercept-url pattern="/reports/**" access="ROLE_USER" />
    <security:http-basic />
    <security:logout logout-url="/reports/logout" 
            logout-success-url="/reports/goodbye.html" />
</security:http>
<security:ldap-server url="ldap://s140.foo.com:1389/dc=td,dc=foo,dc=com" />
<security:authentication-manager>
    <security:authentication-provider ref="ldapAuthProvider">
</security:authentication-provider>
</security:authentication-manager>
<!-- Security beans -->
<bean id="contextSource" class="org.springframework.security.ldap.DefaultSpringSecurityContextSource">
    <constructor-arg value="ldap://s140.foo.com:1389/dc=td,dc=foo,dc=com" />
</bean>
<bean id="ldapAuthProvider" 
   class="org.springframework.security.ldap.authentication.LdapAuthenticationProvider">
    <constructor-arg>
        <bean class="foo.bar.reporting.server.security.ldap.LdapAuthenticatorImpl">
            <property name="contextFactory" ref="contextSource" />
            <property name="principalPrefix" value="TD\" />
            <property name="employee" ref="employee"></property>
        </bean>
    </constructor-arg>
    <constructor-arg>
      <bean class="foo.bar.reporting.server.security.ldap.LdapAuthoritiesPopulator" />
    </constructor-arg>
</bean>
<!-- DAOs -->
<bean id="ldapTemplate" class="org.springframework.ldap.core.LdapTemplate">
  <constructor-arg ref="contextSource" />

Voici un extrait de code de LdapAuthenticatorImpl qui effectue l'authentification. Pas de problème ici:

@Override
public DirContextOperations authenticate(final Authentication authentication) {
    //Grab the username and password out of the authentication object.
    final String name = authentication.getName();
    final String principal = this.principalPrefix + name;
    String password = "";
    if (authentication.getCredentials() != null) {
        password = authentication.getCredentials().toString();
    }
    if (!("".equals(principal.trim())) && !("".equals(password.trim()))) {
        final InitialLdapContext ldapContext = (InitialLdapContext)
     this.contextFactory.getContext(principal, password);
        //We need to pass the context back out, so that the auth provider 
        //can add it to the Authentication object.
        final DirContextOperations authAdapter = new DirContextAdapter();
        authAdapter.addAttributeValue("ldapContext", ldapContext);
        this.employee.setqId(name);
        return authAdapter;
    } else {
        throw new BadCredentialsException("Blank username and/or password!");
    }
}

Et voici un autre extrait de code de EmployeeDao avec ma vaine tentative pour la requête:

public List<Employee> queryEmployeesByName(String query) 
   throws BARServerException {
    AndFilter filter = new AndFilter();
    filter.and(new EqualsFilter("objectclass", "person"));
    filter.and(new WhitespaceWildcardsFilter("cn", query));
    try {
        //the following line throws bind exception
        List result = ldapTemplate.search(BASE, filter.encode(), 
            new AttributesMapper() {
            @Override
            public Employee mapFromAttributes(Attributes attrs) 
                throws NamingException {
                Employee emp = new Employee((String) attrs.get("cn").get(), 
                   (String) attrs.get("cn").get(),
                        (String) attrs.get("cn").get());
                return emp;
            }
        });
        return result;
    } catch (Exception e) { 
        throw new BarServerException("Failed to query LDAP", e);
    }
}

Et enfin - à l'exception, je suis

org.springframework.ldap.UncategorizedLdapException: 
    Uncategorized exception occured during LDAP processing; nested exception is 
    javax.naming.NamingException: [LDAP: error code 1 - 00000000: LdapErr: 
    DSID-0C090627, comment: In order to perform this operation a successful bind 
    must be completed on the connection., data 0, vece]; remaining name 
    'DC=TD,DC=FOO,DC=COM'
Je sais que c'est vieux mais @Bostone pouvez-vous m'aider à régler cette question. J'obtiens exactement la même exception, cependant j'obtiens cette erreur sur la page de connexion où l'utilisateur entre des informations d'identification. Le ldap renvoie avec succès lorsque le nom d'utilisateur correct et le mot de passe est entré mais j'obtiens l'erreur suivante: [code d'erreur LDAP: 1 - 00000000: LdapErr: DSID-0C090627, commentaire: pour effectuer cette opération un succès de la liaison doit être effectuée sur la connexion., données 0, vece ]; remaning nom "
veuillez voir ma réponse ci-dessous. Il a travaillé pour moi

OriginalL'auteur Bostone | 2011-03-10