Hi gusy , i have been encountering with one issue.
Anybody knows about how to check connection with LDAP server (C#) using only such parameters:
-Server name
- full domain
- port
In Java enviroment,i have created such helper class (it perform such verivication as i described above):
public class LdapHelper
{
public static boolean loginLDAP(String loginName, String password, String ldapServer, String ldapPort, String ldapDomainName)
throws Exception
{
final LDAPAuthenticate ldapAuthenticate = LDAPAuthenticate.getInstance();
ldapAuthenticate.init(
"ldap",
ldapServer,
ldapPort,
ldapDomainName
);
return ldapAuthenticate.loginUser( loginName, password );
}
public static void logoutLdap() throws Exception
{
final LDAPAuthenticate ldapAuthenticate = LDAPAuthenticate.getInstance();
ldapAuthenticate.logout();
}
public static boolean checkLdapServer(String serverName, String fullDomainName, String port)
{
return LDAPAuthenticate.getInstance().checkLdapServer(
serverName,
fullDomainName,
port
);
}
public static boolean loginSimple(String loginName, String password, String serverName, String fullDomainName, String port,
String base) throws Exception
{
Hashtable authEnv = new Hashtable( 11 );
String dn = "uid=" + loginName + "," + base;
String ldapURL = "ldap://" + serverName + "." + fullDomainName.toUpperCase() + ":" + port;
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 );
DirContext authContext = new InitialDirContext( authEnv );
System.out.println( "Authentication Success!" );
return true;
}
}
All answers and suggestions are acceptable =)
Well i be more precious, i need to check in LDAP context such string , see below:
"LDAP://" + ldapServer + "."+DomainName.trim() + ":" + port.trim() + "/"