Merge branch 'v1.4' into master

This commit is contained in:
Captain.B 2020-10-27 17:55:05 +08:00
commit f119fe08d1
1 changed files with 12 additions and 7 deletions

View File

@ -18,6 +18,7 @@ import org.springframework.ldap.core.DirContextOperations;
import org.springframework.ldap.core.LdapTemplate; import org.springframework.ldap.core.LdapTemplate;
import org.springframework.ldap.core.support.AbstractContextMapper; import org.springframework.ldap.core.support.AbstractContextMapper;
import org.springframework.ldap.core.support.DefaultDirObjectFactory; import org.springframework.ldap.core.support.DefaultDirObjectFactory;
import org.springframework.ldap.core.support.LdapContextSource;
import org.springframework.ldap.query.SearchScope; import org.springframework.ldap.query.SearchScope;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -145,17 +146,21 @@ public class LdapService {
preConnect(url, dn, password); preConnect(url, dn, password);
String credentials = EncryptUtils.aesDecrypt(password).toString(); String credentials = EncryptUtils.aesDecrypt(password).toString();
LdapContextSource sourceLdapCtx;
SSLLdapContextSource sourceLdapCtx = new SSLLdapContextSource(); if (StringUtils.startsWith(url, "ldaps://")) {
sourceLdapCtx.setUrl(url); sourceLdapCtx = new SSLLdapContextSource();
sourceLdapCtx.setUserDn(dn); // todo 这里加上strategy 会报错
sourceLdapCtx.setPassword(credentials);
sourceLdapCtx.setDirObjectFactory(DefaultDirObjectFactory.class);
// todo 这里加上strategy 会报错
// DefaultTlsDirContextAuthenticationStrategy strategy = new DefaultTlsDirContextAuthenticationStrategy(); // DefaultTlsDirContextAuthenticationStrategy strategy = new DefaultTlsDirContextAuthenticationStrategy();
// strategy.setShutdownTlsGracefully(true); // strategy.setShutdownTlsGracefully(true);
// strategy.setHostnameVerifier((hostname, session) -> true); // strategy.setHostnameVerifier((hostname, session) -> true);
// sourceLdapCtx.setAuthenticationStrategy(strategy); // sourceLdapCtx.setAuthenticationStrategy(strategy);
} else {
sourceLdapCtx = new LdapContextSource();
}
sourceLdapCtx.setUrl(url);
sourceLdapCtx.setUserDn(dn);
sourceLdapCtx.setPassword(credentials);
sourceLdapCtx.setDirObjectFactory(DefaultDirObjectFactory.class);
sourceLdapCtx.afterPropertiesSet(); sourceLdapCtx.afterPropertiesSet();
LdapTemplate ldapTemplate = new LdapTemplate(sourceLdapCtx); LdapTemplate ldapTemplate = new LdapTemplate(sourceLdapCtx);
ldapTemplate.setIgnorePartialResultException(true); ldapTemplate.setIgnorePartialResultException(true);