SHARE
TWEET

Untitled

a guest Dec 13th, 2016 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class LDAPTest {
  2. public static void main(String[] args) throws NamingException {
  3.     final String ldapAdServer = "ldap://ad.your-server.com:8080";
  4.     // final String ldapSearchBase =
  5.     // "dc=ad,dc=my-domain,dc=com,cn=directory manager";
  6.     final String ldapSearchBase = "cn=directory manager";
  7.     final String ldapUsername = "myLdapUsername";
  8.     final String ldapPassword = "myLdapPassword";
  9.     Hashtable<String, Object> env = new Hashtable<String, Object>();
  10.     env.put(Context.SECURITY_AUTHENTICATION, "simple");
  11.     env.put(Context.SECURITY_PRINCIPAL, ldapUsername);
  12.     env.put(Context.SECURITY_CREDENTIALS, ldapPassword);
  13.     env.put(Context.INITIAL_CONTEXT_FACTORY,
  14.             "com.sun.jndi.ldap.LdapCtxFactory");
  15.     env.put(Context.PROVIDER_URL, ldapAdServer);
  16.     LdapContext ctx = new InitialLdapContext(env, null);
  17.     String uid = "abc123";
  18.     String searchFilter = "(&(objectClass=group)(objectSid=" + uid + "))";
  19.     SearchControls searchControls = new SearchControls();
  20.     searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
  21.     NamingEnumeration<SearchResult> results = ctx.search(ldapSearchBase,
  22.             searchFilter, searchControls);
  23. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top