leccher
25-06-2009, 10:47
Ciao a tutti,
ho installato OpenLDAP v 2.4.16 (l'ultima attualmente) su un OpenSolaris 10.9 (non dovrebbe centrare nulla ma metto per completezza). Il demone parte con questa semplice configurazione
________________________________
...
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
________________________________
Devo creare degli utenti che poi devono autenticarsi tramite 'sto LDAP. Per fare delle prove, ho creato una semplice classe Client in Java prendendo spunto da un esempio offerto da JavaStaff.it. Usando un browser LDAP vedo gli utenti creati ma non capisco come mai non riesco a farli autenticare.
Ecco cosa uso per provare.
________________________________
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();
}
}
}
________________________________
Come detto, la crazione va in OK (ou=users c'è xché preconfigurato con apposito semplicissimo ldif, il problema non è lì), ma l'autenticazione mi da un errore 49
LDAP: error code 49 - Invalid Credentials
Qualcuno sa dirmi dove sta l'errore. Grazie in anticipo
ho installato OpenLDAP v 2.4.16 (l'ultima attualmente) su un OpenSolaris 10.9 (non dovrebbe centrare nulla ma metto per completezza). Il demone parte con questa semplice configurazione
________________________________
...
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
________________________________
Devo creare degli utenti che poi devono autenticarsi tramite 'sto LDAP. Per fare delle prove, ho creato una semplice classe Client in Java prendendo spunto da un esempio offerto da JavaStaff.it. Usando un browser LDAP vedo gli utenti creati ma non capisco come mai non riesco a farli autenticare.
Ecco cosa uso per provare.
________________________________
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();
}
}
}
________________________________
Come detto, la crazione va in OK (ou=users c'è xché preconfigurato con apposito semplicissimo ldif, il problema non è lì), ma l'autenticazione mi da un errore 49
LDAP: error code 49 - Invalid Credentials
Qualcuno sa dirmi dove sta l'errore. Grazie in anticipo