Hallo,
I'm using OpenSolaris communty 10.9 and I had needed to install an OpenLDAP 
from openldap.org. Everithing without any special configuration.

Now I have my ldap demon on, using the following configuration parameter:
________________________________
...
include         /usr/local/etc/openldap/schema/core.schema
include         /usr/local/etc/openldap/schema/cosine.schema
include         /usr/local/etc/openldap/schema/inetorgperson.schema
include         /usr/local/etc/openldap/schema/java.schema
...
pidfile         /usr/local/var/run/slapd.pid
argsfile        /usr/local/var/run/slapd.args
...
database        bdb
suffix          "dc=customer,dc=project,dc=com"
rootdn          "cn=Admin,dc=customer,dc=project,dc=com"
...
rootpw          mypwd
...
directory       /usr/local/var/openldap-data
...
index   objectClass     eq
...
access to attrs=userPassword
    by users read
    by self write
________________________________

I have to use openldap just to autenticate my users on a webapp using java.
Follow the rows shows my sample client testing creation and than login of a 
test user; the login goes in error giving me a 49 ldap error (invalid 
credentials)
(the creation work so the ou=users exists as preloaded using a ldif file, the 
problem is not in creation but in login).
________________________________
import javax.naming.*;
import javax.naming.directory.*;

import java.util.Hashtable;

/**
 * Demonstrates how to create an initial context to an LDAP server
 * using simple authentication.
 */

class SimpleLdapClient {
        static String dcbase="dc=customer,dc=project,dc=com";
        static String base = "ou=users,"+dcbase;
        static String ldapurl="ldap://10.220.22.107:389";;
        
        public static void main(String[] args) {
                try{
                create("test");
                login("test");
                }catch(Exception ex){
                        ex.printStackTrace();
                }
        }
        
        public static void create(String str){
                Hashtable env = new Hashtable();
                env.put(Context.INITIAL_CONTEXT_FACTORY, 
"com.sun.jndi.ldap.LdapCtxFactory");
                env.put(Context.PROVIDER_URL, ldapurl);
                env.put(Context.SECURITY_PRINCIPAL, "cn=Admin,"+dcbase);
                env.put(Context.SECURITY_CREDENTIALS, "mypwd");
                    
                try {
                  DirContext ctx = new InitialDirContext(env);
                  //Creazione attributi utente:
                  Attribute objClasses = new BasicAttribute("objectclass");
                  objClasses.add("top");
                  objClasses.add("person");
                  objClasses.add("inetOrgPerson");
                  Attribute cn = new BasicAttribute("cn", str);
                  Attribute sn = new BasicAttribute("sn", str);
                  Attribute uid = new BasicAttribute("uid", str+"."+str);
                  Attribute userPassword = new 
BasicAttribute("userPassword",str);
                  
                  Attributes attributi = new BasicAttributes();
                  attributi.put(objClasses);
                  attributi.put(cn);
                  attributi.put(sn);
                  attributi.put(uid);
                  attributi.put(userPassword);

                  ctx.createSubcontext("cn="+str+","+base, attributi);
                  
                }
                catch (NameAlreadyBoundException nabe){
                  System.err.println("DN already exists!");
                  nabe.printStackTrace();
                }
                catch (Exception e){
                  e.printStackTrace();
                }
        }
        
        public static void login(String str) throws Exception{
                Hashtable authEnv = new Hashtable();
                String userName = str+"."+str;
                String dn = "uid="+userName+","+base;

                
authEnv.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
                authEnv.put(Context.PROVIDER_URL, ldapurl);
                authEnv.put(Context.SECURITY_AUTHENTICATION, "simple");
                authEnv.put(Context.SECURITY_PRINCIPAL, dn);
                authEnv.put(Context.SECURITY_CREDENTIALS, str);

                try {
                        DirContext authContext = new InitialDirContext(authEnv);
                        System.out.println("Authentication Success!");
                } catch (AuthenticationException authEx) {
                        System.out.println("Authentication failed!");
                        authEx.printStackTrace();
                } catch (NamingException namEx) {
                        System.out.println("Something went wrong!");
                        namEx.printStackTrace();
                }
        }
}
________________________________

Please, help me understand what wrong.
Tnx.
-- 
This message posted from opensolaris.org
_______________________________________________
storage-discuss mailing list
[email protected]
http://mail.opensolaris.org/mailman/listinfo/storage-discuss

Reply via email to