LDAP with Spring API

Search AD User and Groups

	LdapContextSource contextSource = new DefaultSpringSecurityContextSource("ldap://10.134.15.138:389");
	contextSource.setBase("DC=TEST,DC=SSM");
	contextSource.setUserDn("test@TEST.SSM");
	contextSource.setPassword("123456");
	DirContextAuthenticationStrategy strategy = createTLSStrategy();
	contextSource.setAuthenticationStrategy(strategy);
	contextSource.afterPropertiesSet();
 
	LdapTemplate ldapTemplate = new LdapTemplate(contextSource);
	ldapTemplate.afterPropertiesSet();
 
	SearchControls sc = new SearchControls();
	sc.setSearchScope(SearchControls.SUBTREE_SCOPE);
 
	ldapTemplate.search("cn=Users", "(objectclass=group)", sc, new NameClassPairCallbackHandler() {
 
		@Override
		public void handleNameClassPair(NameClassPair nameClassPair) {
			System.out.println(nameClassPair.getName());
		}
	});
  • Write: AD Provider支援TLS。
  • Write: LDAP Provider Login with anonymous支援TLS。
  • Write: SSL with HostVerifier。
  • Write: Login LDAP with FullDN。
  • Study: Connection Pool for TLS。