Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- String userName = "John P R-Asst General Manager";
- String passWord = "asdfgh123";
- String base ="OU=SOU,DC=example,DC=com";
- String dn = "cn=" + userName + "," + base;
- String ldapURL = "ldap://mdsdc3.example.com:389";
- authEnv.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
- authEnv.put(Context.PROVIDER_URL, ldapURL);
- authEnv.put(Context.SECURITY_AUTHENTICATION, "simple");
- authEnv.put(Context.SECURITY_PRINCIPAL, dn);
- authEnv.put(Context.SECURITY_CREDENTIALS, password);
- try {
- DirContext authContext = new InitialDirContext(authEnv);
- return true;
- } catch (NamingException namEx) {
- return false;
- }
- try
- {
- // Set up the environment for creating the initial context
- Hashtable<String, String> env = new Hashtable<String, String>();
- env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
- env.put(Context.PROVIDER_URL, "ldap://ldap_server:389");
- //
- env.put(Context.SECURITY_AUTHENTICATION, "simple");
- env.put(Context.SECURITY_PRINCIPAL, "domain\user"); //we have 2 \ because it's a escape char
- env.put(Context.SECURITY_CREDENTIALS, "test");
- // Create the initial context
- DirContext ctx = new InitialDirContext(env);
- boolean result = ctx != null;
- if(ctx != null)
- ctx.close();
- return result;
- }
- catch (Exception e)
- {
- return false;
- }
- String ldapURL = "ldap://mdsdc3.example.com:389/DC=example,DC=com";
- env.put(Context.SECURITY_PRINCIPAL, "Zeus");
- env.put(Context.SECURITY_CREDENTIALS, "Z3usP@55");
- env.put(Context.PROVIDER_URL, "ldap://athena.local:389");
- String deecee = "DC=athena,DC=local";
- LdapContext context = new InitialLdapContext(env, null);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement