I will try to use the SSL+User+Password methods.
Keep going...
The intelligent web technology course work has been posted to the modules. oh...
package
com.test.LDAP;
//import com.sun.org.apache.xerces.internal.impl.dv.util.Base64;
import
com.sun.org.apache.xerces.internal.impl.dv.util.*;
import
javax.naming.*;
import
javax.naming.directory.*;
import
java.security.MessageDigest;
import
java.security.NoSuchAlgorithmException;
import
java.util.Hashtable;
import
java.util.logging.Level;
import
java.util.logging.Logger;
/**
* Demonstrates how to create an initial context to an LDAP server
* using anonymous authentication (i.e. none).
*
* usage: java None
*/
class
LDAPTest {
public static void main(String[] args) {
System.
out.println("hello");
// Set up environment for creating initial context
Hashtable<String, Object> env =
new Hashtable<String, Object>(11);
env.put(Context.
INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
// env.put(Context.PROVIDER_URL, "ldap://localhost:389/o=JNDITutorial");
env.put(Context.
PROVIDER_URL, "ldap://10.52.1.246:389/o=RGU");
// Use anonymous authentication
env.put(Context.
SECURITY_AUTHENTICATION, "none");
try {
// Create initial context
DirContext ctx =
new InitialDirContext(env);
System.
out.println("authentication succeed");
ctx.close();
}
catch (javax.naming.AuthenticationException e){
System.
out.println("authentication failed");
e.printStackTrace();
}
catch (Exception e){
System.
out.println("unknown error");
e.printStackTrace();
}
}
}
No comments:
Post a Comment