Discussione: [JAVA] LDAP
View Single Post
Old 11-08-2006, 15:08   #1
orpheus
Member
 
Iscritto dal: Apr 2004
Messaggi: 252
[JAVA] LDAP

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

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:

Codice:
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
orpheus è offline   Rispondi citando il messaggio o parte di esso