1
votes

Hi I'm working on Spring Boot and I'm trying to use spring security for user authentication from active directory. But I'm unable to login user into the application I've tried several stuff and here is the code which I've tried:

@Override
    public void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth
            .ldapAuthentication()
                .userDnPatterns("uid={0},ou=Users")
                .groupSearchBase("ou=groups")
                .contextSource(contextSource())
                .passwordCompare()
                    .passwordEncoder(new LdapShaPasswordEncoder())
                    .passwordAttribute("userPassword");
    }

    @Bean
    public DefaultSpringSecurityContextSource contextSource() {
        return  new DefaultSpringSecurityContextSource(Arrays.asList("ldap://WIN-BSCF2478SL5.Adexample.com"), "CN=Administrator,DC=ADExample,DC=com");
    }

I tried to implement the example from here

and the error I get as I try to login from administrator is as follows:

Reason: Uncategorized exception occured during LDAP processing; nested exception is javax.naming.NamingException: [LDAP: error code 1 - 000004DC: LdapErr: DSID-0C0906E8, comment: In order to perform this operation a successful bind must be completed on the connection., data 0, v1db1]; remaining name 'uid=administrator,ou=Users'

I also tried to use userSearchFilter instead of userDnPatterns but still got the exception here is code

auth.ldapAuthentication().userSearchFilter("uid={0}").contextSource()
                .url("ldap://WIN-BSCF2478SL5.Adexample.com/DC=ADExample,DC=com").managerDn("Administrator")
                .managerPassword("Passw0rd");

and the exception from this code I get is as follows: Exception I get: Reason: [LDAP: error code 49 - 80090308: LdapErr: DSID-0C0903A9, comment: AcceptSecurityContext error, data 52e, v1db1]; nested exception is javax.naming.AuthenticationException: [LDAP: error code 49 - 80090308: LdapErr: DSID-0C0903A9, comment: AcceptSecurityContext error, data 52e, v1db1]

and in the end I also tried without providing userid and its password

auth.ldapAuthentication().userSearchFilter("uid={0}").contextSource()
            .url("ldap://WIN-BSCF2478SL5.Adexample.com/DC=ADExample,DC=com");

and it also didn't work for me and the exception on this I get is

Reason: Uncategorized exception occured during LDAP processing; nested exception is javax.naming.NamingException: [LDAP: error code 1 - 000004DC: LdapErr: DSID-0C0906E8, comment: In order to perform this operation a successful bind must be completed on the connection., data 0, v1db1]; remaining name '/'

1

1 Answers

0
votes

Similar questions can be found here.

The error you are getting could be caused by multiple other causes because we can't see your configuration. Looks like you are unable to bind to the LDAP. Is your LDAP configured correctly? Did you try configuring a test-server.ldif like the tutorial pointed it out?