orpheus
11-08-2006, 14:08
Ciao a tutti,
devo effettuare una connessione a una directory LDAP per recuperare il valore di un particolare attributo.
Per fare questo ho scaricato jldap, inoltre da openldap ho scaricato il server ldap per fare le prove.
questo è il mio codice
public String loadX509CertificateFromLDAP(String certLDAPPath) throws UnsupportedEncodingException, LDAPException{
String cert = null;
LDAPUrl ldapUrl;
LDAPConnection lc = new LDAPConnection();
try {
ldapUrl = new LDAPUrl( certLDAPPath);
LDAPSearchResults searchResults = lc.search( ldapUrl );
while ( searchResults.hasMore()) {
LDAPEntry nextEntry = searchResults.next();
System.out.println("\n" + nextEntry.getDN());
LDAPAttributeSet attributeSet = nextEntry.getAttributeSet();
Iterator allAttributes = attributeSet.iterator();
if (allAttributes.hasNext())
System.out.println(" Attribute(s): ");
while(allAttributes.hasNext()) {
LDAPAttribute attribute =
(LDAPAttribute)allAttributes.next();
String attributeName = attribute.getName();
Enumeration allValues = attribute.getStringValues();
while(allValues.hasMoreElements()) {
String value = (String) allValues.nextElement();
System.out.println(" " + attributeName
+ ": " + value);
cert = value;
}
}
}
}
catch( MalformedURLException e ) {
System.out.println("MalformedURL exception");
e.printStackTrace();
}
catch( LDAPException e ) {
System.out.println("LDAP exception");
e.printStackTrace();
}
return cert;
}
Il problema è il seguente appena tento di fare la connessione mi parte quest'eccezione:
LDAPException: Connection closed by the application disconnecting (91) Connect Error
at com.novell.ldap.Connection.destroyClone(Unknown Source)
at com.novell.ldap.LDAPConnection.disconnect(Unknown Source)
at com.novell.ldap.LDAPConnection.disconnect(Unknown Source)
at com.novell.ldap.LDAPConnection.search(Unknown Source)
at com.novell.ldap.LDAPConnection.search(Unknown Source)
E' la prima volta che lavoro su queste cose e non capisco se il problema è nel codice oppure ci sono delle impostazioni da configurare nel server
Ogni aiuto/suggerimento è ben accetto
devo effettuare una connessione a una directory LDAP per recuperare il valore di un particolare attributo.
Per fare questo ho scaricato jldap, inoltre da openldap ho scaricato il server ldap per fare le prove.
questo è il mio codice
public String loadX509CertificateFromLDAP(String certLDAPPath) throws UnsupportedEncodingException, LDAPException{
String cert = null;
LDAPUrl ldapUrl;
LDAPConnection lc = new LDAPConnection();
try {
ldapUrl = new LDAPUrl( certLDAPPath);
LDAPSearchResults searchResults = lc.search( ldapUrl );
while ( searchResults.hasMore()) {
LDAPEntry nextEntry = searchResults.next();
System.out.println("\n" + nextEntry.getDN());
LDAPAttributeSet attributeSet = nextEntry.getAttributeSet();
Iterator allAttributes = attributeSet.iterator();
if (allAttributes.hasNext())
System.out.println(" Attribute(s): ");
while(allAttributes.hasNext()) {
LDAPAttribute attribute =
(LDAPAttribute)allAttributes.next();
String attributeName = attribute.getName();
Enumeration allValues = attribute.getStringValues();
while(allValues.hasMoreElements()) {
String value = (String) allValues.nextElement();
System.out.println(" " + attributeName
+ ": " + value);
cert = value;
}
}
}
}
catch( MalformedURLException e ) {
System.out.println("MalformedURL exception");
e.printStackTrace();
}
catch( LDAPException e ) {
System.out.println("LDAP exception");
e.printStackTrace();
}
return cert;
}
Il problema è il seguente appena tento di fare la connessione mi parte quest'eccezione:
LDAPException: Connection closed by the application disconnecting (91) Connect Error
at com.novell.ldap.Connection.destroyClone(Unknown Source)
at com.novell.ldap.LDAPConnection.disconnect(Unknown Source)
at com.novell.ldap.LDAPConnection.disconnect(Unknown Source)
at com.novell.ldap.LDAPConnection.search(Unknown Source)
at com.novell.ldap.LDAPConnection.search(Unknown Source)
E' la prima volta che lavoro su queste cose e non capisco se il problema è nel codice oppure ci sono delle impostazioni da configurare nel server
Ogni aiuto/suggerimento è ben accetto