Active Directory LDAP LOGIN 체크(JAVA)
회사생활2013. 2. 22. 00:26
728x90
public static boolean isLdapLogin(String userId, String userPw) throws Exception{
boolean isAuthenticated = false;
DirContext ctx = null;
Properties props = new Properties();
props.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
props.setProperty(Context.PROVIDER_URL, "ldap://"+ldapServer);
props.setProperty(Context.SECURITY_PRINCIPAL,"cn="+userId+baseDN);
props.setProperty(Context.SECURITY_CREDENTIALS,userPw);
try {
ctx = new InitialDirContext(props);
isAuthenticated = true;
System.out.println("[isLdapLogin]LDAP_CERT_TRUE:"+userId);
} catch (NamingException e) {
System.out.println("[isLdapLogin]LDAP_CERT_FALSE:"+userId);
}finally{
try {
if (null != ctx){
ctx.close();
}
} catch (Exception e2) {
//log.error(e2.toString());
}
}
return isAuthenticated;
}
}
AD에 대한 정보는 여기서 확인을~~
http://en.wikipedia.org/wiki/Active_Directory728x90
댓글 영역