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
2. J'ai configurer les paramètres de sécurité
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3 ucdata-path ./ucdata include ./schema/core.schema include ./schema/java.schema
Voici mon code:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4 database bdb suffix "o=jndi" rootdn "cn=admin,o=jndi" rootpw admin
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).
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 public class Ldap { /** * @param args */ public static void main(String[] args) { try { Hashtable env = new Hashtable(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, "ldap://localhost/o=jndi"); env.put(Context.SECURITY_AUTHENTICATION, "simple"); env.put(Context.SECURITY_PRINCIPAL, "cn=admin,o=jndi"); env.put(Context.SECURITY_CREDENTIALS, "admin"); DirContext ctx = new InitialDirContext(env); //ctx.bind("cn=number", new Integer(10)); //Object o = ctx.lookup("number"); ctx.close(); } catch (NamingException e) { e.printStackTrace(); } } }
Mais lorsque j'essaye de faire un binding une exception est déclenchée:
J'attends votre aide.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11 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)
Cordialement.
Partager