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:02 AM

I wil added style="mso-spacerun: yes">  a new user in my AD . I have creating a new class Utiltest ,this is my code:   style="mso-spacerun: yes">  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{    lang=   More>>








I wil added
style="mso-spacerun: yes"> 
a new user in my AD .



I have creating a
new class Utiltest ,this is my code:



 




style="mso-spacerun: yes"> 
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{



  
lang="EN-GB" style="mso-ansi-language:EN-GB">String id;




style="mso-spacerun: yes">  
String dn;




style="mso-spacerun: yes">  
Attributes myAttrs = new
BasicAttributes(true);




style="mso-spacerun: yes">  
Attribute oc = new
BasicAttribute("objectclass");




style="mso-spacerun: yes"> 
// Attribute ouSet = new
BasicAttribute("ou");



 



 




style="mso-spacerun: yes"> 
public Utiltest(String dn, String givenname,String
sn,




style="mso-spacerun: yes">
             
String
mail,String tel,String fax){




style="mso-spacerun: yes">     
myAttrs.put("distinguishedName",dn);




style="mso-spacerun: yes">     
oc.add("top");




style="mso-spacerun: yes">     
oc.add("person");




style="mso-spacerun: yes">     
oc.add("organizationalPerson");




style="mso-spacerun: yes">     
oc.add("users");




style="mso-spacerun: yes">     
/*ouSet.add("People");




style="mso-spacerun: yes">   

yes">  
ouSet.add(ou);
*/




style="mso-spacerun: yes">     
String cn =
givenname+" "+sn;




style="mso-spacerun: yes">     
myAttrs.put(oc);




style="mso-spacerun: yes">    
// myAttrs.put(ouSet);




style="mso-spacerun: yes">     
myAttrs.put("cn",cn);




style="mso-spacerun: yes">     
myAttrs.put("sn",sn);




style="mso-spacerun: yes">     
myAttrs.put("givenname",givenname);




style="mso-spacerun: yes">     
myAttrs.put("mail",mail);




style="mso-spacerun: yes">     
myAttrs.put("telephonenumber",tel);




style="mso-spacerun: yes">     
myAttrs.put("facsimilietelephonenumber",fax);




style="mso-spacerun: yes">  
}



 




style="mso-spacerun: yes"> 
/*public Attributes getAttributes(String name)
throws NamingException {




style="mso-spacerun: yes">     
if (!
name.equals("")){




style="mso-spacerun: yes">        
throw
new NameNotFoundException();




style="mso-spacerun: yes">     
}




style="mso-spacerun: yes">     
return myAttrs;




style="mso-spacerun: yes">  
}   */




style="mso-spacerun: yes"> 
public Attributes getAttributes(Name name) throws
NamingException {




style="mso-spacerun: yes">     
return
getAttributes(name.toString());




style="mso-spacerun: yes">  
}




style="mso-spacerun: yes"> 
public Attributes getAttributes(String name,
String[] ids)




style="mso-spacerun: yes">
                                           
throws
NamingException {




style="mso-spacerun: yes">     
if(!
name.equals(""))




style="mso-spacerun: yes">        
throw
new NameNotFoundException();




style="mso-spacerun: yes">     
Attributes answer = new
BasicAttributes(true);




style="mso-spacerun: yes">     
Attribute target;




style="mso-spacerun: yes">     
for (int i = 0; i <
ids.length; i++){




style="mso-spacerun: yes">        
target =
myAttrs.get(ids[i]);




style="mso-spacerun: yes">        
if
(target != null){




style="mso-spacerun: yes">
           
answer.put(target);




style="mso-spacerun: yes">        
}




style="mso-spacerun: yes">     
}




style="mso-spacerun: yes">     
return answer;




style="mso-spacerun: yes">  
}




style="mso-spacerun: yes"> 
public Attributes getAttributes(Name name, String[]
ids)




style="mso-spacerun: yes">
                                             
throws
NamingException {




style="mso-spacerun: yes">     
return
getAttributes(name.toString(), ids);




style="mso-spacerun: yes">  
}



 



 




style="mso-spacerun: yes"> 
public Object addToEnvironment(String propName,
Object propVal) {return addToEnvironment( propName,   propVal);}




style="mso-spacerun: yes"> 
public void bind(Name name, Object obj){}



 




style="mso-spacerun: yes"> 
public void bind(String name, Object obj){}



 



 




style="mso-spacerun: yes"> 
public void bind(Name name, Object obj, Attributes
attrs){}



 




style="mso-spacerun: yes"> 
public void bind(String name, Object obj,
Attributes attrs){}



 




style="mso-spacerun: yes"> 
public void close() {};




style="mso-spacerun: yes"> 
public Context createSubcontext(Name name) throws
NamingException{



 




style="mso-spacerun: yes">       
return
style="mso-spacerun:
yes"> 
createSubcontext(name);




style="mso-spacerun: yes">        
}



 




style="mso-spacerun: yes"> 
public Context createSubcontext(String name)throws
NamingException{




style="mso-spacerun: yes">       
return
style="mso-spacerun:
yes"> 
createSubcontext( name);




style="mso-spacerun: yes">       
}



 




style="mso-spacerun: yes"> 
public Name composeName(Name name, Name prefix) {




style="mso-spacerun: yes">       
Name nom = new
CompositeName();




style="mso-spacerun: yes">        
return
nom;




style="mso-spacerun: yes">       
}




style="mso-spacerun: yes"> 
public String composeName(String name, String
prefix) {




style="mso-spacerun: yes">       
String nom =
new String();




style="mso-spacerun: yes">        
return
nom;




style="mso-spacerun: yes">       
}




style="mso-spacerun: yes"> 
public void destroySubcontext(Name name){}



 




style="mso-spacerun: yes"> 
public void destroySubcontext(String name){}



 




style="mso-spacerun: yes"> 
public DirContext createSubcontext(Name name,
Attributes attrs)throws NamingException{




style="mso-spacerun: yes">         
return
createSubcontext(name,   attrs);




style="mso-spacerun: yes">         
}



 




style="mso-spacerun: yes"> 
public DirContext createSubcontext(String name,
Attributes attrs)throws NamingException{




style="mso-spacerun: yes">        
return
createSubcontext(name,   attrs);




style="mso-spacerun: yes">       
}



 




style="mso-spacerun: yes"> 
public DirContext getSchema(Name name)throws
NamingException{




style="mso-spacerun: yes">       
return
getSchema(name);




style="mso-spacerun: yes">       
}



 




style="mso-spacerun: yes"> 
public DirContext getSchema(String name){




style="mso-spacerun: yes">        
return
getSchema(name);




style="mso-spacerun: yes">        
}



 




style="mso-spacerun: yes"> 
public DirContext getSchemaClassDefinition(Name
name){




style="mso-spacerun: yes">        
return
getSchemaClassDefinition(name);




style="mso-spacerun: yes">       
}



 




style="mso-spacerun: yes"> 
public DirContext getSchemaClassDefinition(String
name){




style="mso-spacerun: yes">       
return
getSchemaClassDefinition(name);




style="mso-spacerun: yes">       
}




style="mso-spacerun: yes"> 
public Hashtable getEnvironment() {




style="mso-spacerun: yes">       
return
getEnvironment();




style="mso-spacerun: yes">       
}




style="mso-spacerun: yes"> 
public String getNameInNamespace(){




style="mso-spacerun: yes"> 

yes">      
return
getNameInNamespace();




style="mso-spacerun: yes">       
}




style="mso-spacerun: yes"> 
public NameParser getNameParser(Name name) {




style="mso-spacerun: yes">       
return
style="mso-spacerun:
yes"> 
getNameParser(name);




style="mso-spacerun: yes">       
}




style="mso-spacerun: yes"> 
public NameParser getNameParser(String name) {




style="mso-spacerun: yes">       
return
getNameParser(name);




style="mso-spacerun: yes">        
}




style="mso-spacerun: yes"> 
public NamingEnumeration list(Name name){




style="mso-spacerun: yes">       
return
list(name);




style="mso-spacerun: yes">       
}




style="mso-spacerun: yes"> 
public NamingEnumeration list(String name){




style="mso-spacerun: yes">       
return
list(name);




style="mso-spacerun: yes">        
}



 




style="mso-spacerun: yes"> 
public NamingEnumeration listBindings(Name name){




style="mso-spacerun: yes">         
return
style="mso-spacerun:
yes"> 
listBindings(name);




style="mso-spacerun: yes">         
}



 




style="mso-spacerun: yes"> 
public NamingEnumeration listBindings(String name){




style="mso-spacerun: yes">       
return
style="mso-spacerun:
yes"> 
listBindings(name);




style="mso-spacerun: yes">       
}



 




style="mso-spacerun: yes"> 
public Object lookup(Name name){




style="mso-spacerun: yes">         
return
style="mso-spacerun:
yes"> 
lookup( name) ;




style="mso-spacerun: yes">          
}




style="mso-spacerun: yes"> 
public Object lookup(String name){ return
lookup(name);}



 




style="mso-spacerun: yes"> 
public void modifyAttributes(Name name, int mod_op,
Attributes attrs){}



 




style="mso-spacerun: yes"> 
public void modifyAttributes(Name name,
ModificationItem[] mods){}



 




style="mso-spacerun: yes"> 
public void modifyAttributes(String name, int
mod_op, Attributes attrs){}



 




style="mso-spacerun: yes"> 
public void modifyAttributes(String name,
ModificationItem[] mods){}



 




style="mso-spacerun: yes"> 
public void rebind(Name name, Object obj,
Attributes attrs){}



 




style="mso-spacerun: yes"> 
public void rebind(String name, Object obj,
Attributes attrs){}



 




style="mso-spacerun: yes"> 
public NamingEnumeration search(Name name,
Attributes matchingAttributes){




style="mso-spacerun: yes">         
return
search(name, matchingAttributes);




style="mso-spacerun: yes">         
}



 




style="mso-spacerun: yes"> 
public NamingEnumeration search(Name name,
Attributes matchingAttributes, String[] attributesToReturn){




style="mso-spacerun: yes">         
return
search(name, matchingAttributes,attributesToReturn);




style="mso-spacerun: yes">         
}



 




style="mso-spacerun: yes"> 
public NamingEnumeration search(Name name, String
filterExpr, Object[] filterArgs, SearchControls cons){




style="mso-spacerun: yes">          
return
search( name, filterExpr,   filterArgs, cons) ;




style="mso-spacerun: yes">
            
}



 




style="mso-spacerun: yes"> 
public NamingEnumeration search(Name name, String
filter, SearchControls cons){




style="mso-spacerun: yes">
            
return
search(name,   filter,
style="mso-spacerun: yes"> 
cons);




style="mso-spacerun: yes">
            
}



 




style="mso-spacerun: yes"> 
public NamingEnumeration search(String name,
Attributes matchingAttributes){




style="mso-spacerun: yes">
           
return search(
name, matchingAttributes);




style="mso-spacerun: yes">
           
}



 




style="mso-spacerun: yes"> 
public NamingEnumeration search(String name,
Attributes matchingAttributes, String[] attributesToReturn){




style="mso-spacerun: yes">
            
return
search(name,   matchingAttributes,
style="mso-spacerun: yes"> 
attributesToReturn);




style="mso-spacerun: yes">
            
}



 




style="mso-spacerun: yes"> 
public NamingEnumeration search(String name, String
filterExpr, Object[] filterArgs, SearchControls cons){




style="mso-spacerun: yes">         
return
search(name,   filterExpr, filterArgs,
style="mso-spacerun: yes"> 
cons);




style="mso-spacerun: yes">         
}



 




style="mso-spacerun: yes"> 
public NamingEnumeration search(String name, String
filter, SearchControls cons){




style="mso-spacerun: yes">        
return
search(name,   filter,
style="mso-spacerun: yes"> 
cons);




style="mso-spacerun: yes">        
}



 




style="mso-spacerun: yes"> 
public Object removeFromEnvironment(String
propName){




style="mso-spacerun: yes">        
return
removeFromEnvironment( propName);




style="mso-spacerun: yes">        
}



 




style="mso-spacerun: yes"> 
public Object lookupLink(Name name){




style="mso-spacerun: yes">          
return
lookupLink( name);




style="mso-spacerun: yes">
            
}



 




style="mso-spacerun: yes"> 
public Object lookupLink(String name){




style="mso-spacerun: yes">         
return
lookupLink( name);




style="mso-spacerun: yes">        
}



 




style="mso-spacerun: yes"> 
public void rebind(Name name, Object obj){}



 




style="mso-spacerun: yes"> 
public   void
rebind(String name, Object obj){}



 




style="mso-spacerun: yes"> 
//ject removeFromEnvironment(String propName){}



 




style="mso-spacerun: yes"> 
public void rename(Name oldName, Name newName){}



 




style="mso-spacerun: yes"> 
public void rename(String oldName, String
newName){}



 




style="mso-spacerun: yes"> 
public void unbind(Name name){}



 




style="mso-spacerun: yes"> 
public void unbind(String name){}



 




style="mso-spacerun: yes"> 
public Attributes getAttributes(String name) throws
NamingException {




style="mso-spacerun: yes">     
if (!
name.equals("")){




style="mso-spacerun: yes">        
throw
new NameNotFoundException();




style="mso-spacerun: yes">     
}




style="mso-spacerun: yes">     
return myAttrs;




style="mso-spacerun: yes">  
}



 




style="mso-spacerun: yes">  
}



 



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
{




style="mso-spacerun: yes">   
public static void main(String[] args)
{



 




style="mso-ansi-language:EN-GB">
                       
//
rechargement de l'environnement de l'initialisation du context




           

lang="EN-GB" style="mso-ansi-language:EN-GB">Hashtable env = new Hashtable(11);




style="mso-tab-count:1">
           
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");




style="mso-tab-count:1">
           
env.put(Context.PROVIDER_URL,
"ldap://digactive:389/dc=intraucad,dc=ucad,dc=sn");




style="mso-spacerun: yes"> 
env.put(Context.SECURITY_AUTHENTICATION,"simple");




style="mso-spacerun: yes"> 
env.put(Context.SECURITY_PRINCIPAL,"cn=administrateur,cn=users,dc=intraucad,dc=ucad,dc=sn");
// specify the username




style="mso-spacerun: yes"> 
env.put(Context.SECURITY_CREDENTIALS,"digactive");
// specify the password



 



 




style="mso-tab-count:1">
           
try {




           

style="mso-spacerun: yes">   
// Crée le context initial




           

style="mso-spacerun: yes">   
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);



 




           

style="mso-spacerun: yes">   

style="mso-ansi-language:
EN-GB">// Close the context when we're done




style="mso-tab-count:1">
           

style="mso-spacerun: yes">   
ctx.close();




style="mso-tab-count:1">
           
} catch
(NamingException e) {




style="mso-tab-count:1">
           

style="mso-spacerun: yes">   

style="mso-ansi-language:DE">System.out.println("Operation echouée: " + e);




style="mso-tab-count:1">
           

lang="EN-GB" style="mso-ansi-language:EN-GB">}




style="mso-spacerun: yes">   
}



}



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