2 Replies Latest reply on Jan 21, 2013 12:48 PM by Frank Nimphius-Oracle

    Unable to authenticate using LDAP

      Hello all,

      I am creating a native android mobile application using JDeveloper and require LDAP binding for authentication. But when I am writing the method for it, an error is occuring which says that *"Type DirContext not found"* . Even the import statement *"import javax.naming.directory.DirContext;"* is also giving the same error. Please help.

      The code I have written is as follows :

      *public static DirContext getDirContext(String pinUid, String pinPwd) {*

      DirContext ctx1 = null;
      String LdapUrl = "ldap://";
      String LdapPort = "3060";
      String username = "cn=" + pinUid + ",cn=Users,dc=tcs,dc=com";
      System.out.println("username: " + username);
      *try {*
      Hashtable env = new Hashtable(5);
      env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
      env.put(Context.PROVIDER_URL, LdapUrl + ":" + LdapPort);
      env.put(Context.SECURITY_AUTHENTICATION, "simple");
      env.put(Context.SECURITY_PRINCIPAL, username);
      env.put(Context.SECURITY_CREDENTIALS, pinPwd);

      System.out.println("UNAME" + username);
      System.out.println("PWD" + pinPwd);

      ctx1 = new InitialDirContext(env);
      System.out.println("The directory context has been created");
      flag = 1;
      *} catch (Exception e) {*
      System.out.println("Failed to create the directory context" + e.toString());
      flag = 0;
      System.out.println("Flag is" + flag);

      return ctx1;

      Thanks in advance.