Advertisement
Guest User

Untitled

a guest
Sep 9th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. private static DirContext getDirContext() {
  2. Hashtable<String, String> env = new Hashtable<>();
  3. env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
  4. env.put(Context.PROVIDER_URL, "ldap://" + serverIpAddress + ":" + Integer.toString(serverLdapPort));
  5. env.put(Context.SECURITY_AUTHENTICATION, "simple");
  6. env.put(Context.SECURITY_PRINCIPAL, connectionUsername + "@" + serverDomain);
  7. env.put(Context.SECURITY_CREDENTIALS, connectionPassword);
  8. try {
  9. return new InitialDirContext(env);
  10. } catch (NamingException e) {
  11. return null;
  12. }
  13. }
  14.  
  15.  
  16. public static boolean authenticate(String username, String password) {
  17. connectionUsername = username;
  18. connectionPassword = password;
  19. DirContext dirContext = getDirContext();
  20. if (dirContext != null) {
  21. closeDirContext(dirContext);
  22. return true;
  23. } else {
  24. return false;
  25. }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement