dcsimg
Please help What is this error ?? where my i wrong. I just want to retireve the User Name from the Active Directory using JNDI and Tomcat 3.3
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   rajesh_francis
Posted On:   Thursday, March 25, 2004 03:08 AM

Please help >> What is this error ?? where my i wrong. I just want to retireve the User Name from the Active Directory using JNDI and Tomcat 3.3 Problem getting attribute: javax.naming.InvalidNameException: cn=Woods, Anthony (HQ), ou=Silverdale, ou=sews-e: [LDAP: error code 34 - 0000208F: NameErr: DSID-031001B6, problem 2006 (BAD_NAME), data 8350, best match of: 'cn=Woods, Anthony (HQ), ou=Silverdale, ou=sews-e,dc=sews-e,dc=com' ]; remaining name 'cn=Woods, Anthony , ou=Silverdale, ou=sews-e' My code try { env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, "ldap://ukhqits002/dc=sews-e,dc=com"); }    More>>

Please help >> What is this error ?? where my i wrong. I just want to retireve the User Name from the Active Directory using JNDI and Tomcat 3.3



Problem getting attribute:

javax.naming.InvalidNameException: cn=Woods, Anthony (HQ), ou=Silverdale, ou=sews-e: [LDAP: error code 34 - 0000208F: NameErr: DSID-031001B6, problem 2006 (BAD_NAME), data 8350, best match of: 'cn=Woods, Anthony (HQ), ou=Silverdale, ou=sews-e,dc=sews-e,dc=com' ]; remaining name 'cn=Woods, Anthony , ou=Silverdale, ou=sews-e'



My code

try { env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://ukhqits002/dc=sews-e,dc=com");
} catch(Exception ex)
{
out.print("erroe in first para-----"+ex);
}


try {
// Create the initial directory context DirContext ctx = new InitialDirContext(env); //String userLogon = userName.substring(DOMAIN_NAME.length() +1); //System.out.println(userLogon); // Ask for all attributes of the object Attributes attrs = ctx.getAttributes("cn=francir, ou=Silverdale, ou=sews-e"); // Find the surname ("sn") and print it out.println("sn: " + attrs.get("sn").get()); // Close the context when we're done ctx.close(); } catch (NamingException e) { out.println("Problem getting attribute: " + e); }


Your advice is highly appreciated.

Rajesh

   <<Less

Re: Please help What is this error ?? where my i wrong. I just want to retireve the User Name from the Active Directory using JNDI and Tomcat 3.3

Posted By:   dinesh_pandey  
Posted On:   Thursday, April 8, 2004 12:02 AM







New Page 1




import java.util.*;

import javax.naming.*;

import javax.naming.directory.*;

import javax.security.auth.*;

import javax.security.auth.callback.*;

import javax.security.auth.login.*;

import javax.security.auth.login.*;

import javax.security.auth.spi.*;



public class TestConnection {



public static void main(String arg[]) {



if(arg.length<4){

System.out.println("Please give username,password, ldap, port.");

System.out.println("java TestConnection ajain@secfindia.com anoop ldap 389");



return;

}





Hashtable env = new Hashtable(); 



if(arg.length<4){

System.out.println("Please give USERNAME, PASSWORD, LDAP, PORT.");

System.out.println("java TestConnection ajain@secfindia.com anoop ldap 389");



return;

}





String ldapUrl = arg[2]+ "://10.1.11.125:"+ arg[3];



System.out.println("LDAP URL: "+ ldapUrl);



env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); 

env.put(Context.PROVIDER_URL, ldapUrl); 



String strUser=arg[0];

String strPwd = arg[1];





//For SIMPLE Test

env.put(Context.SECURITY_AUTHENTICATION, "simple"); // Create the initial context 

env.put(Context.SECURITY_PRINCIPAL, strUser);

env.put(Context.SECURITY_CREDENTIALS, strPwd); 





try { 

System.out.println("1. Is it binding.................."); 

DirContext ctx = new InitialDirContext(env); 

System.out.println("2. Is it binding.................."); 



NamingEnumeration contentsEnum = ctx.list("CN=Users, DC=bees,DC=org "); 



// Working perfect- lists the contents of 'Users' directory

while (contentsEnum.hasMore()){

NameClassPair ncp = (NameClassPair) contentsEnum.next();

String userName = ncp.getName(); 

System.out.println("User: "+userName); 

}



}

catch(Exception e){

e.printStackTrace();

}

}

}





About | Sitemap | Contact