JNDI (LDAP Active directory Windows 2000 Server)
Estoy accediendo por JNDI con el proveedor LDAP de sun, a un servidor Windows 2000 Server, tengo un Active directorio con la siguiente jerarquia.
(DN) Server2002.compañia.com
(OU) Usuarios
(CN) Sergio SLM. lopez Montalban
El tema esta en que cuando recupero las propiedades del objeto Sergio me dice que
son todas Null, cuando en realidad si que tengo
valores en las propiedades, ¿Alguien me puede dar
una pista porque me pasa esto?
aqui va uno de los muchos codigos que utilizado para acceder al Active directory Windows
package ldap001;
import java.util.Hashtable;
import java.util.Enumeration;
import javax.naming.*;
import javax.naming.directory.*;
class Getattrs {
public static void main(String[] args) {
Hashtable env = new Hashtable(5, 0.75f);
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL,
"ldap://192.168.2.400:389");
env.put(Context.SECURITY_AUTHENTICATION,"none");
try {
DirContext ctx = new InitialDirContext(env);
String[] attrs = new String[4];
attrs[ 0 ] = "cn";
attrs[ 1 ] = "sn";
attrs[ 2 ] = "mail";
attrs[ 3 ] = "telephonenumber";
Attributes result = ctx.getAttributes ("cn=PCJAP03, cn=Computers, c=server2002,dc=compañia, dc=es", null);
if (result == null) {
System.out.println(Env.ENTRYDN +
"has none of the specified attributes.");
} else {
Attribute attr = result.get("cn");
if (attr != null) {
System.out.println("Full name:" );
for (NamingEnumeration vals = attr.getAll();
vals.hasMoreElements();
System.out.println("t" + vals.nextElement()));
}
attr = result.get("sn");
if (attr != null) {
System.out.println("Last name (surname):" );
for (NamingEnumeration vals = attr.getAll();
vals.hasMoreElements();
System.out.println("t" + vals.nextElement()));
}
attr = result.get("mail");
if (attr != null) {
System.out.println("Email address:" );
for (NamingEnumeration vals = attr.getAll();
vals.hasMoreElements();
System.out.println("t" + vals.nextElement()));
}
attr = result.get("telephonenumber");
if (attr != null) {
System.out.println("Telephone number:" );
for (NamingEnumeration vals = attr.getAll();
vals.hasMoreElements();
System.out.println("t" + vals.nextElement()));
}
}
} catch (NamingException e) {
System.err.println("Getattrs example failed.");
e.printStackTrace();
}
}
}
Muchas gracias
(DN) Server2002.compañia.com
(OU) Usuarios
(CN) Sergio SLM. lopez Montalban
El tema esta en que cuando recupero las propiedades del objeto Sergio me dice que
son todas Null, cuando en realidad si que tengo
valores en las propiedades, ¿Alguien me puede dar
una pista porque me pasa esto?
aqui va uno de los muchos codigos que utilizado para acceder al Active directory Windows
package ldap001;
import java.util.Hashtable;
import java.util.Enumeration;
import javax.naming.*;
import javax.naming.directory.*;
class Getattrs {
public static void main(String[] args) {
Hashtable env = new Hashtable(5, 0.75f);
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL,
"ldap://192.168.2.400:389");
env.put(Context.SECURITY_AUTHENTICATION,"none");
try {
DirContext ctx = new InitialDirContext(env);
String[] attrs = new String[4];
attrs[ 0 ] = "cn";
attrs[ 1 ] = "sn";
attrs[ 2 ] = "mail";
attrs[ 3 ] = "telephonenumber";
Attributes result = ctx.getAttributes ("cn=PCJAP03, cn=Computers, c=server2002,dc=compañia, dc=es", null);
if (result == null) {
System.out.println(Env.ENTRYDN +
"has none of the specified attributes.");
} else {
Attribute attr = result.get("cn");
if (attr != null) {
System.out.println("Full name:" );
for (NamingEnumeration vals = attr.getAll();
vals.hasMoreElements();
System.out.println("t" + vals.nextElement()));
}
attr = result.get("sn");
if (attr != null) {
System.out.println("Last name (surname):" );
for (NamingEnumeration vals = attr.getAll();
vals.hasMoreElements();
System.out.println("t" + vals.nextElement()));
}
attr = result.get("mail");
if (attr != null) {
System.out.println("Email address:" );
for (NamingEnumeration vals = attr.getAll();
vals.hasMoreElements();
System.out.println("t" + vals.nextElement()));
}
attr = result.get("telephonenumber");
if (attr != null) {
System.out.println("Telephone number:" );
for (NamingEnumeration vals = attr.getAll();
vals.hasMoreElements();
System.out.println("t" + vals.nextElement()));
}
}
} catch (NamingException e) {
System.err.println("Getattrs example failed.");
e.printStackTrace();
}
}
}
Muchas gracias