Alachisoft.NCache.Common.Util.SecurityUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of nc-common Show documentation
Show all versions of nc-common Show documentation
Internal package of Alachisoft.
package Alachisoft.NCache.Common.Util;
import javax.naming.Context;
import javax.naming.NamingException;
import javax.naming.ldap.InitialLdapContext;
import javax.naming.ldap.LdapContext;
import java.util.Hashtable;
public class SecurityUtil {
public static boolean AuthorizeUserNamePassword(String domain, String userName, String password, String port) {
boolean isAdministrator = false;
if (userName == null && password == null) {
isAdministrator = false;
}
try {
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.SECURITY_AUTHENTICATION, "Simple");
//it can be something that you use for windows login
//it can also be
env.put(Context.SECURITY_PRINCIPAL, userName);
env.put(Context.SECURITY_CREDENTIALS, password);
//in following property we specify ldap protocol and connection url.
//generally the port is 389
env.put(Context.PROVIDER_URL, domain + ":" + port);
LdapContext ctx = new InitialLdapContext(env, null);
isAdministrator = true;
} catch (NamingException nex) {
isAdministrator = false;
}
return isAdministrator;
}
}