Ombitious_Developper
Messages postés2333Date d'inscriptionsamedi 28 février 2004StatutMembreDernière intervention26 juillet 2013
-
12 mai 2008 à 16:34
indiana_jules
Messages postés750Date d'inscriptionmardi 9 mars 2004StatutMembreDernière intervention23 décembre 2008
-
13 mai 2008 à 09:00
Salut tous:
Je suis en train essayer de faire marcher un programme qui utilises l'API JNDI.
Malheureusement, rien ne marche.
Je travaille avec OpenLDAP, j'ai configuré le fichier slapd.conf:
1. J'ai ajouter le schéma de java
<!-- BEGIN TEMPLATE: bbcode_code -->
Code :
<!--[if !IE]><--><!----><!--[endif]--><!--[if IE]>
<![endif]-->ucdata-path ./ucdata
include ./schema/core.schema
include ./schema/java.schema
<!-- END TEMPLATE: bbcode_code -->2. J'ai configurer les paramètres de sécurité
<!-- BEGIN TEMPLATE: bbcode_code -->
<!-- END TEMPLATE: bbcode_code -->Lorsque je mets les appels aux
méthodes bind() et lookup() en commentaires le programme ne produit
aucune exception. (ceci dit que le Context est créé avec succès).
Mais lorsque j'essaye de faire un binding une exception est déclenchée:
<!-- BEGIN TEMPLATE: bbcode_code -->
Code :
<!--[if !IE]><--><!----><!--[endif]--><!--[if IE]>
<![endif]-->javax.naming.NameNotFoundException: [LDAP: error code 32 - No Such Object]; remaining name 'cn=number'
at com.sun.jndi.ldap.LdapCtx.mapErrorCode(Unknown Source)
at com.sun.jndi.ldap.LdapCtx.processReturnCode(Unknown Source)
at com.sun.jndi.ldap.LdapCtx.processReturnCode(Unknown Source)
at com.sun.jndi.ldap.LdapCtx.c_bind(Unknown Source)
at com.sun.jndi.ldap.LdapCtx.c_bind(Unknown Source)
at com.sun.jndi.toolkit.ctx.ComponentContext.p_bind(Unknown Source)
at com.sun.jndi.toolkit.ctx.PartialCompositeContext.bind(Unknown Source)
at com.sun.jndi.toolkit.ctx.PartialCompositeContext.bind(Unknown Source)
at javax.naming.InitialContext.bind(Unknown Source)
at com.ttn.jndi.Ldap.main(Ldap.java:33)
<!-- END TEMPLATE: bbcode_code -->J'attends votre aide.
2) Ensuite, dans mon code, j'accédais au LDAP de la manière suivante :
try {
System.out.println("Connexion au serveur LDAP pour insertion de notre ConcatInt");
Hashtable<String, String> env = new Hashtable<String, String>();
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://localhost:389/dc=julien-ldap,dc=roche");
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, "cn=ldap-admin,dc=julien-ldap,dc=roche");
env.put(Context.SECURITY_CREDENTIALS, "secret");
DirContext dircontext = new InitialDirContext(env);
System.out.println("Connexion au LDAP faite");
System.out.println("Nous insérons nos éléments");
dircontext.rebind("cn=concatintimpl", new ConcatIntImpl());
Attributes attributes = new BasicAttributes(true);
Attribute attribut = new BasicAttribute("testDeChamp");
attribut.add("Je remplis mon champ");
attributes.put(attribut);
dircontext.rebind("cn=test,cn=concatintimpl", new String("Coucou"));
System.out.println("Serveur démarré");
Scanner scanner = new Scanner(System.in);
System.out.println("Appuyez sur entrée pour quitter le programme");
scanner.nextLine();
Ombitious_Developper
Messages postés2333Date d'inscriptionsamedi 28 février 2004StatutMembreDernière intervention26 juillet 201339 12 mai 2008 à 22:01
Salut:
Merci, pour ta réponse. Tout marche bien, jusqu'à cette instruction:
dircontext.rebind("cn= concatintimpl", new ConcatIntImpl());
Est ce que ConcatIntImpl est une classe ordinaire qui implémente l'interface Serializable?
Comme je n'est pas la déclaration de la classe ConcatIntImpl, j'ai fait les changements suivants:
dircontext.rebind("cn=bean", new Bean());
Avec:
public class Bean implements Serializable {
}
J'ai obtenu cette exception:
javax.naming.directory.InvalidAttributeIdentifierException: [LDAP: error code 17 - javaSerializedData: attribute type undefined]; remaining name 'cn =bean'
at com.sun.jndi.ldap.LdapCtx.mapErrorCode(Unknown Source)
at com.sun.jndi.ldap.LdapCtx.processReturnCode(Unknown Source)
at com.sun.jndi.ldap.LdapCtx.processReturnCode(Unknown Source)
at com.sun.jndi.ldap.LdapCtx.c_bind(Unknown Source)
at com.sun.jndi.ldap.LdapCtx.c_rebind(Unknown Source)
at com.sun.jndi.ldap.LdapCtx.c_rebind(Unknown Source)
at com.sun.jndi.toolkit.ctx.ComponentContext.p_rebind(Unknown Source)
at com.sun.jndi.toolkit.ctx.PartialCompositeContext.rebind(Unknown Source)
at com.sun.jndi.toolkit.ctx.PartialCompositeContext.rebind(Unknown Source)
at javax.naming.InitialContext.rebind(Unknown Source)
at jndi.JndiSample.main(JndiSample.java:42)
Normalement, l'attribut "concatintimpl" n'est pas encore définit.