dcsimg
JNDI and Active Directory
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   fadel_lemine
Posted On:   Saturday, September 22, 2001 06:17 AM

I wil added a new user in my AD . I have creating a new class Utiltest ,this is my code: import javax.naming.*; import javax.naming.directory.*; import javax.naming.directory.DirContext; import java.io.File; import java.util.Hashtable; public class Utiltest implements DirContext{ String id; String dn; Attributes myAttrs = new BasicAttributes(true); Attribute oc = new BasicAttribute("objectclass"); // Attribute ouSet = new BasicAttribute("ou"); public Utiltest(String dn, String givenname,String sn, String mail,String tel,String fax){ myAttrs.put("distinguishedName",dn); oc.add("   More>>

I wil added a new user in my AD .
I have creating a new class Utiltest ,this is my code:


import javax.naming.*;
import javax.naming.directory.*;
import javax.naming.directory.DirContext;
import java.io.File;
import java.util.Hashtable;

public class Utiltest implements DirContext{
String id;
String dn;
Attributes myAttrs = new BasicAttributes(true);
Attribute oc = new BasicAttribute("objectclass");
// Attribute ouSet = new BasicAttribute("ou");


public Utiltest(String dn, String givenname,String sn,
String mail,String tel,String fax){
myAttrs.put("distinguishedName",dn);
oc.add("top");
oc.add("person");
oc.add("organizationalPerson");
oc.add("users");
/*ouSet.add("People");
ouSet.add(ou); */
String cn = givenname+" "+sn;
myAttrs.put(oc);
// myAttrs.put(ouSet);
myAttrs.put("cn",cn);
myAttrs.put("sn",sn);
myAttrs.put("givenname",givenname);
myAttrs.put("mail",mail);
myAttrs.put("telephonenumber",tel);
myAttrs.put("facsimilietelephonenumber",fax);
}

/*public Attributes getAttributes(String name) throws NamingException {
if (! name.equals("")){
throw new NameNotFoundException();
}
return myAttrs;
} */
public Attributes getAttributes(Name name) throws NamingException {
return getAttributes(name.toString());
}
public Attributes getAttributes(String name, String[] ids)
throws NamingException {
if(! name.equals(""))
throw new NameNotFoundException();
Attributes answer = new BasicAttributes(true);
Attribute target;
for (int i = 0; i < ids.length; i++){
target = myAttrs.get(ids[i]);
if (target != null){
answer.put(target);
}
}
return answer;
}
public Attributes getAttributes(Name name, String[] ids)
throws NamingException {
return getAttributes(name.toString(), ids);
}


public Object addToEnvironment(String propName, Object propVal) {return addToEnvironment( propName, propVal);}
public void bind(Name name, Object obj){}

public void bind(String name, Object obj){}


public void bind(Name name, Object obj, Attributes attrs){}

public void bind(String name, Object obj, Attributes attrs){}

public void close() {};
public Context createSubcontext(Name name) throws NamingException{

return createSubcontext(name);
}

public Context createSubcontext(String name)throws NamingException{
return createSubcontext( name);
}

public Name composeName(Name name, Name prefix) {
Name nom = new CompositeName();
return nom;
}
public String composeName(String name, String prefix) {
String nom = new String();
return nom;
}
public void destroySubcontext(Name name){}

public void destroySubcontext(String name){}

public DirContext createSubcontext(Name name, Attributes attrs)throws NamingException{
return createSubcontext(name, attrs);
}

public DirContext createSubcontext(String name, Attributes attrs)throws NamingException{
return createSubcontext(name, attrs);
}

public DirContext getSchema(Name name)throws NamingException{
return getSchema(name);
}

public DirContext getSchema(String name){
return getSchema(name);
}

public DirContext getSchemaClassDefinition(Name name){
return getSchemaClassDefinition(name);
}

public DirContext getSchemaClassDefinition(String name){
return getSchemaClassDefinition(name);
}
public Hashtable getEnvironment() {
return getEnvironment();
}
public String getNameInNamespace(){
return getNameInNamespace();
}
public NameParser getNameParser(Name name) {
return getNameParser(name);
}
public NameParser getNameParser(String name) {
return getNameParser(name);
}
public NamingEnumeration list(Name name){
return list(name);
}
public NamingEnumeration list(String name){
return list(name);
}

public NamingEnumeration listBindings(Name name){
return listBindings(name);
}

public NamingEnumeration listBindings(String name){
return listBindings(name);
}

public Object lookup(Name name){
return lookup( name) ;
}
public Object lookup(String name){ return lookup(name);}

public void modifyAttributes(Name name, int mod_op, Attributes attrs){}

public void modifyAttributes(Name name, ModificationItem[] mods){}

public void modifyAttributes(String name, int mod_op, Attributes attrs){}

public void modifyAttributes(String name, ModificationItem[] mods){}

public void rebind(Name name, Object obj, Attributes attrs){}

public void rebind(String name, Object obj, Attributes attrs){}

public NamingEnumeration search(Name name, Attributes matchingAttributes){
return search(name, matchingAttributes);
}

public NamingEnumeration search(Name name, Attributes matchingAttributes, String[] attributesToReturn){
return search(name, matchingAttributes,attributesToReturn);
}

public NamingEnumeration search(Name name, String filterExpr, Object[] filterArgs, SearchControls cons){
return search( name, filterExpr, filterArgs, cons) ;
}

public NamingEnumeration search(Name name, String filter, SearchControls cons){
return search(name, filter, cons);
}

public NamingEnumeration search(String name, Attributes matchingAttributes){
return search( name, matchingAttributes);
}

public NamingEnumeration search(String name, Attributes matchingAttributes, String[] attributesToReturn){
return search(name, matchingAttributes, attributesToReturn);
}

public NamingEnumeration search(String name, String filterExpr, Object[] filterArgs, SearchControls cons){
return search(name, filterExpr, filterArgs, cons);
}

public NamingEnumeration search(String name, String filter, SearchControls cons){
return search(name, filter, cons);
}

public Object removeFromEnvironment(String propName){
return removeFromEnvironment( propName);
}

public Object lookupLink(Name name){
return lookupLink( name);
}

public Object lookupLink(String name){
return lookupLink( name);
}

public void rebind(Name name, Object obj){}

public void rebind(String name, Object obj){}

//ject removeFromEnvironment(String propName){}

public void rename(Name oldName, Name newName){}

public void rename(String oldName, String newName){}

public void unbind(Name name){}

public void unbind(String name){}

public Attributes getAttributes(String name) throws NamingException {
if (! name.equals("")){
throw new NameNotFoundException();
}
return myAttrs;
}

}


this class implements ths DirContext interfece.
now ,i have usingthe bind methode for adding my user,this is my code:


import javax.naming.*;
import javax.naming.directory.*;

import java.util.Hashtable;

public class Bind {
public static void main(String[] args) {

// rechargement de l'environnement de l'initialisation du context
Hashtable env = new Hashtable(11);
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://digactive:389/dc=intraucad,dc=ucad,dc=sn");
env.put(Context.SECURITY_AUTHENTICATION,"simple");
env.put(Context.SECURITY_PRINCIPAL,"cn=administrateur,cn=users,dc=intraucad,dc=ucad,dc=sn"); // specify the username
env.put(Context.SECURITY_CREDENTIALS,"digactive"); // specify the password


try {
// Crée le context initial
DirContext ctx = new InitialDirContext(env);


Utiltest usr = new Utiltest("cn=styagi Sameer,ou=Essai,dc=intraucad,dc=ucad,dc=sn","styagi","Sameer",
"sameertyagi@usa.net","1236589","dgdfgg");
ctx.bind("cn=styagi Sameer,ou=Essai,dc=intraucad,dc=ucad,dc=sn", usr);

// Close the context when we're done
ctx.close();
} catch (NamingException e) {
System.out.println("Operation echouée: " + e);
}
}
}


And i have this error:

Sortie du système : Operation echouée: javax.naming.directory.NoSuchAttributeException: [LDAP: error code 16 - 00000057: LdapErr: DSID-0C090909, comment: Error in attribute conversion operation, data 0, v893
Sortie du système : ]; remaining name 'cn=styagi Sameer,ou=Essai,dc=intraucad,dc=ucad,dc=sn'

   <<Less
About | Sitemap | Contact