This discussion is archived
0 Replies Latest reply: Jan 21, 2013 1:30 AM by 975391 RSS

Unable to authenticate using LDAP

975391 Newbie
Currently Being Moderated
Hello all,

I am creating a native android mobile application using JDeveloper 11.1.2.3.0 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://172.18.41.140";
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.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points