Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static DirContext getDirContext() {
- Hashtable<String, String> env = new Hashtable<>();
- env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
- env.put(Context.PROVIDER_URL, "ldap://" + serverIpAddress + ":" + Integer.toString(serverLdapPort));
- env.put(Context.SECURITY_AUTHENTICATION, "simple");
- env.put(Context.SECURITY_PRINCIPAL, connectionUsername + "@" + serverDomain);
- env.put(Context.SECURITY_CREDENTIALS, connectionPassword);
- try {
- return new InitialDirContext(env);
- } catch (NamingException e) {
- return null;
- }
- }
- public static boolean authenticate(String username, String password) {
- connectionUsername = username;
- connectionPassword = password;
- DirContext dirContext = getDirContext();
- if (dirContext != null) {
- closeDirContext(dirContext);
- return true;
- } else {
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement