Verbindung Java <-> LDAP (AD)

M_vdB

Grünschnabel
Guten Tag,
ich habe aktuell folgende Problem, bei dem mir bisher auch Google nicht weiterhelfen konnte.
Es soll via Java eine Verbindung zum Acitve Directory aufgebaut werden und die dort eingetragenen Telefonnummern/Faxnummern zugehörig zu den entsprechenden Usern in ein XML ausgegeben werden.
Allerdings war es mir bisher noch nicht möglich Anfragen an das AD zu stellen, da ich entweder den LDAP-Error 0C090627 ("In order to perform this operation a successful bind must be completed on the connection" / Jedoch will ich nur eine Liste erstellen, keine Daten binden/ändern) oder aber den Error 0C90334 ("AcceptSecurityContext error")
Aktuell habe ich sowohl die Standard-JNDI/LDAP-Verbindung wie auch die Spring-LDAP Bibliothek ausprobiert, mit gleichem (leider negativem) Ergebnis.

Daher nun die Frage ob jemand von euch schon mit Java eine Verbindung ins Active Directory realisiert hat und mir helfen kann..

Vielen Dank vorab,
Michael
 
Danke für die flotte und kompetente Antwort.
Das bisherige Problem war wohl, dass ich versehentlich immer nur den cn (Common-Name) statt dem dn (Distinguished-Name) als Benutzername angegeben hatte.

Mittlerweile funktioniert zumindest der Zugriff auf das AD und die restlichen Abfragen sollte ich nun hoffentlich auch noch hinbekommen. Wenn nicht melde ich mich hier nochmal ;-)
 
Hallo kann mir bitte jemand sagen, was ich da falsch mache?
Ich möchte eine verbindung zu Edirectory.
die methode bind(tralalal) erkennt e nicht.
hab auch die ldap-2006.jar datei

Woran kann es liegen?


package edirectory;

import Sevlets.gh;
import com.novell.ldap.LDAPAttribute;
import com.novell.ldap.LDAPConnection;
import com.novell.ldap.LDAPEntry;
import com.novell.ldap.LDAPResponse;
import com.novell.ldap.LDAPResponseQueue;
import javax.security.auth.login.LoginException;
import java.io.*;
/*import org.ietf.ldap.LDAPException;
import org.ietf.ldap.LDAPResponse;
import org.ietf.ldap.LDAPResponseQueue;
import org.ietf.ldap.LDAPSearchResults;
* */
import java.lang.Object;
import org.ietf.ldap.LDAPException;

/**
*
* @author xxxx
*/
public class LDAPLoginModule extends gh.java
{
private static Object log;
private static int arg0;
private static void ldapBind(LDAPConnection connection)
throws LDAPException, UnsupportedEncodingException, com.novell.ldap.LDAPException


{
LDAPResponseQueue respQueue = connection
.bind(LDAPConnection.LDAP_V3,
"cn=xxx,ou=XXX,o=XXX", "XXXXX".getBytes(),
(org.ietf.ldap.LDAPResponseQueue) null);
LDAPResponse response = (LDAPResponse) respQueue.getResponse();
if (response.getResultCode() != LDAPException.SUCCESS) {
throw new RuntimeException("Could not bind to the eDirectory!");
}
}
}
 
Das problem habe ich behoben, meine Frage wie kann ich die daten einer person aufrufen. kann mir bitte jemand bezugnehmend dieses code eine methode schreiben
vielen dank

class LDAPLoginModule {
private static Object log;
private static int arg0;

public static void ldapBind(LDAPConnection connection)
throws LDAPException, UnsupportedEncodingException, com.novell.ldap.LDAPException


{
LDAPResponseQueue respQueue = connection.bind((int)LDAPConnection.LDAP_V3,
"cn=JEF,ou=SVC,o=ADM", "JEF45".getBytes(),
(LDAPResponseQueue) null);
LDAPResponse response = (LDAPResponse) respQueue.getResponse();
if (response.getResultCode() != LDAPException.SUCCESS) {
throw new RuntimeException("Could not bind to the eDirectory!");
}
}


public static String validateLdapPassword(String company,
String userid, String password) throws com.novell.ldap.LDAPException {
LDAPConnection ldapConnection = null;
//UserProfile
String profile = null;

try {
ldapConnection = new LDAPConnection();
// Establish connection
ldapConnection.connect("ldapxxxx.xxx.de", 000);
ldapBind(ldapConnection);

String searchFilter = "(cn=" + userid + ")";
//LDAPSearchResults results = ldapConnection.search("ou=xx,o=xx-xxx",
// LDAPConnection.SCOPE_SUB, searchFilter, null, false);
com.novell.ldap.LDAPSearchResults results = ldapConnection.search("ou=xx,o=xx-DIR",
LDAPConnection.SCOPE_SUB, searchFilter, null, false);
if (results.hasMore()) {
// User found.
LDAPEntry entry = results.next();
//LDAPAttribute passwordAttribute = new LDAPAttribute(
LDAPAttribute passwordAttribute = new LDAPAttribute(
"userPassword", password);

/*if (ldapConnection.compare(entry.getDN(), passwordAttribute)) {
profile = new DefaultUserProfile();
profile.setLoginName((String) entry.getAttribute("cn")
.getStringValue());
profile.setFullname((String) entry.getAttribute("fullName")
.getStringValue());
profile.setWikiName(((String) entry
.getAttribute("fullName").getStringValue())
.replaceAll(" ", ""));
// profile.setPassword( user.getAttribute( PASSWORD ) );
profile.setEmail((String) entry.getAttribute("mail")
.getStringValue());
log.debug(entry);
}*/
}
} catch (Exception e1) {
//log.error(e);
System.out.println("Fehler: "+e1.getMessage());
} finally {
// Close the connection
try {
if (ldapConnection != null) {
ldapConnection.disconnect();
}
} //catch (LDAPException e2)
catch(com.novell.ldap.LDAPException e2){
//log.error(e);
System.out.println("Fehler: "+e2.getMessage());
}
}
return profile;
}

private static void getBytes() {
throw new UnsupportedOperationException("Not yet implemented");
}




public static void main(String[] args) throws com.novell.ldap.LDAPException, LDAPException
{
LDAPConnection ldapConnection = null;


ldapConnection = new LDAPConnection();
// Establish connection

ldapConnection.connect("ldxxxx.xxx.de", 000);
try {
ldapBind(ldapConnection);
System.out.println("ldaBind erfolgreich");

} catch (UnsupportedEncodingException ex) {
Logger.getLogger(LDAPLoginModule.class.getName()).log(Level.SEVERE, null, ex);
}



}


}
 
Hallo,

benutzt du zum Zugriff auf LDAP eine eigene Bibliothek? Die gezeigten Beispiele verwenden JNDI zum Zugriff auf LDAP...

Zum einfachen Zugriff auf LDAP kann man das LdapTemplate von Spring LDAP (unabhängig vom Spring Framework) verwenden.

schau mal hier:
http://www.springsource.org/ldap
http://static.springsource.org/spring-ldap/docs/1.3.x/reference/html/
http://www.javaworld.com/javaworld/jw-06-2007/jw-06-springldap.html

Hier genau das was du willst:
http://www.javaworld.com/javaworld/jw-06-2007/jw-06-springldap.html?page=3

Gruß Tom
 
Zurück