Thiago E S
Thiago E S

Reputation: 75

Spring 5, get info from LDAP (AD)

I'm trying to make a controller that receives an email and fetches information from that user in an Active Directory returning it as json. I'm having a hard time finding useful material because everything I find is trying to teach authentication through WebSecurity annotation... I couldn't care less about the authentication, I only want Spring to get info and nothing else.

Can anybody tell me how to get out from this to what I need?

@Bean
public ActiveDirectoryLdapAuthenticationProvider activeDirectoryLdapAuthenticationProvider() {
    ActiveDirectoryLdapAuthenticationProvider provider = new ActiveDirectoryLdapAuthenticationProvider(LDAP_DOMAIN, LDAP_URL, LDAP_ROOT_DN);
    provider.setConvertSubErrorCodesToExceptions(true);
    provider.setUseAuthenticationRequestCredentials(true);
    provider.setSearchFilter(LDAP_FILTER);
    return provider;
}

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

Upvotes: 0

Views: 456

Answers (1)

Hatice
Hatice

Reputation: 944

You can use LdapTemplate if you want to just get information. You can find information spring documentation . Besides, this tutorial has lots of ldap query examples with LdapTemplate

Upvotes: 2

Related Questions