简体   繁体   中英

Unable to Authenticate a User with an LDAP Server using LDAP User Search Query with Spring Security

LDAP Server Hierarchy as retrieved via Apache Directory Studio:

Root DSE:

DC=company,DC=com

OU=Offices

OU=Region Offices

OU=Region1 Office

OU=Users

CN=Jayesh Mulwani

WebSecurity is enabled as a part of below class:

public class LDAPSecurityConfig extends WebSecurityConfigurerAdapter{
    protected void configure(AuthenticationManagerBuilder authenticationManagerBuilder) throws Exception {                  
            authenticationManagerBuilder.ldapAuthentication()
            .contextSource().url("ldap://server-url/CN=auth_support,OU=Misc,DC=company,DC=com")
            .managerDn("username").managerPassword("password")
            .and()
            .userSearchBase("OU=Offices,DC=company,DC=com")
            .userSearchFilter("(&(objectClass=user)(cn={0}))");
    }
}

Once the application is setup on tomcat, i enter the username along with its password but the authentication fails and no error is prompted.

Can someone please assist me with the approach or specify if i'm missing something here ?

I have fixed the problem by adding the below two conditions

.groupSearchFilter("(&(objectClass=group)(AccountName={0}))")
.groupSearchBase("CN=DEPT_All_Employees,OU=DepartmentSecurityGroups,OU=Resources,DC=company,DC=com")

I referred this example to fix the issue http://www.jcombat.com/spring/spring-security-ldap-authentication

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM