Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.util.Hashtable;

import javax.naming.Context;
import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext;

public class Main {
    public static void main(String[] argv) throws Exception {

        String url = "ldap://localhost/o=JNDITutorial";
        Hashtable<String, String> env = new Hashtable<String, String>();
        env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
        env.put(Context.PROVIDER_URL, url);
        env.put(Context.SECURITY_AUTHENTICATION, "simple");
        env.put(Context.SECURITY_PRINCIPAL, "userDN");
        env.put(Context.SECURITY_CREDENTIALS, "secret");

        DirContext ctx = new InitialDirContext(env);
    }
}