Posted By:
Natasha_Juneja
Posted On:
Friday, June 25, 2004 10:56 AM
Hi all, I am using a JNDI code to connect to MS Active Directory. I am able to connect using an anonymous connection. I want to be able to retrieve a users attributes once connected. Say the user in AD is located as : omd.comOwnitmortgageOperationsDevelopmentNatasha Junejas. Here's the code: /* * Created on Jun 24, 2004 */ package com.omd.LDAPTest; //JNDI packagaes used import javax.naming.*; import javax.naming.directory.*; import java.util.Hashtable; /** * @author Natasha Juneja * This program tries to connect to the LDAP Service Provider * that
More>>
Hi all,
I am using a JNDI code to connect to MS Active Directory.
I am able to connect using an anonymous connection.
I want to be able to retrieve a users attributes once connected.
Say the user in AD is located as :
omd.comOwnitmortgageOperationsDevelopmentNatasha Junejas.
Here's the code:
/*
* Created on Jun 24, 2004
*/
package com.omd.LDAPTest;
//JNDI packagaes used
import javax.naming.*;
import javax.naming.directory.*;
import java.util.Hashtable;
/**
* @author Natasha Juneja
* This program tries to connect to the LDAP Service Provider
* that you provide in the PROVIDER_URL using JNDI API.
*/
public class LDAPTest {
public static String INITCTX = "com.sun.jndi.ldap.LdapCtxFactory";
public static String MY_HOST = "ldap://Coload01:389";
public static void main(String[] args) {
Hashtable env = new Hashtable(11);
env.put(Context.INITIAL_CONTEXT_FACTORY, INITCTX);
env.put(Context.PROVIDER_URL, MY_HOST);
env.put(Context.SECURITY_AUTHENTICATION, "none");
try {
DirContext ctx = new InitialDirContext(env);
System.out.println("Authentication Success");
Attributes attrs = ctx.getAttributes("omd.com/Ownitmortgage/Operations/Development/Natasha Junejas");
ctx.close();
} catch (AuthenticationException e) {
System.out.println("Authentication failed");
e.printStackTrace();
} catch (NamingException ne) {
System.out.println("Something went wrong");
ne.printStackTrace();
}
}
}
The program throws an :
InvalidNameException.
Any ideas ??
Thanks,
<<Less