next up previous
Next: 10.2.7 Accumulate commURIs from Up: 10.2 SIP Previous: 10.2.5 Binding Anonymously to

10.2.6 Binding with a User DN to an LDAP Server

The following code shows how to bind to the LDAP server with a User DN. This is executed in Step 5 of Figure [*].

public static boolean Binding(String LDAPAdd, String US_DN,

    String US_PWD)

{

    /* Hostname */

    String HOST = LDAPAdd.toString();

    /* User DN */

    String USR_DN = US_DN.toString();

    /* Password entered by the User */

    String USR_PW=US_PWD.toString();

    Hashtable env = new Hashtable();

    /* Setting the environment with User DN, Password and

        LDAP address specified by the user */

    env.put(Context.INITIAL_CONTEXT_FACTORY,

        "com.sun.jndi.ldap.LdapCtxFactory");

    env.put(Context.PROVIDER_URL, HOST.toString()+":389");

    env.put(Context.SECURITY_AUTHENTICATION,"simple");

    env.put(Context.SECURITY_PRINCIPAL, USR_DN);

    env.put(Context.SECURITY_CREDENTIALS, USR_PW);

    try

    {

        /* Create the directory context with the above

            set of credentials created */

        DirContext ctx = new InitialDirContext(env);

        return true;

    }

    catch (NamingException e)

    {

        System.out.println("Problem getting attribute in

            Binding - " + e.getMessage());

        return false;

    }

}


next up previous
Next: 10.2.7 Accumulate commURIs from Up: 10.2 SIP Previous: 10.2.5 Binding Anonymously to

Video Middleware Cookbook
Questions and Comments : Cookbook Editors