這是本文件的舊版!
LDAP with Spring API
Articles
- Simple Authentication SSL and StartTLS
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()); } });