Я включил LDAP в свой проект, поэтому вот информация, которая может помочь вам настроить ldap в вашей работе. Вам необходимо настроить аналогично тому, как указано ниже:
private LoginLdapSettings getLdapSettings() {
LoginLdapSettings ldapSettings = new LoginLdapSettings();
ldapSettings.setDn(/**Enter the Dn of the LDAP server**/);
ldapSettings.setLdapUrl(/**Enter the URL of the LDAP server**/);
ldapSettings.setLdapPassword(/**Enter the PASSWORD of the LDAP server**/);
ldapSettings.setSearchFilter(/**Enter the SEARCH FILTER of the LDAP server**/);
ldapSettings.setLdapUsername(/**Enter the USERNAME of the LDAP server**/);
ldapSettings.setUserDnPattern(/**Enter the URL of the LDAP server**/);
return ldapSettings;
}
Метод ниже, когда вы используете Active Directory
private ActiveDirectoryLdapAuthenticationProvider getActiveDirectoryLdapAuthenticationProvider(){
LoginLdapSettings ldapSettings = getLdapSettings();
StringBuilder ldapDomain = getLdapDomain(ldapSettings.getDn());
ActiveDirectoryLdapAuthenticationProvider authenticationProvider = new ActiveDirectoryLdapAuthenticationProvider(ldapDomain.toString(), ldapSettings.getLdapUrl());
authenticationProvider.setConvertSubErrorCodesToExceptions(true);
authenticationProvider.setUseAuthenticationRequestCredentials(false);
if(null != ldapSettings.getSearchFilter() && !ldapSettings.getSearchFilter().trim().isEmpty()) {
authenticationProvider.setSearchFilter(ldapSettings.getSearchFilter().trim());
}
authenticationProvider.setUserDetailsContextMapper(ldapUserDetailsMapper);
return authenticationProvider;
}
@Override
public void configure() throws ConfigurationException, InvalidAttributeValueException, IOException{
auth.authenticationProvider(getActiveDirectoryLdapAuthenticationProvider());
}
Ниже приведен метод, когда вы используете OpenLDAP
@Override
public void configure() throws Exception {
LoginLdapSettings ldapSettings = getLdapSettings();
auth.ldapAuthentication()
.contextSource()
.url(ldapSettings.getLdapUrl() + "/" + ldapSettings.getDn())
.managerDn(ldapSettings.getLdapUsername())
.managerPassword(ldapSettings.getLdapPassword())
.and()
.userSearchFilter(searchFilter)
.userDnPatterns(ldapSettings.getUserDnPattern()) // I used this as the pattern "uid={0}"
.userDetailsContextMapper(ldapUserDetailsMapper);
}
Пожалуйста, проголосуйте, если вам понравился ответ! :)