LDAP Auth Fehler

andyx1975

Aktives Mitglied
Hallo,

ich möchte eine LDAP Authentifizierung starten. Hierzu habe ich eine Connection aufgebaut, idem ich mich mit einem admin user anmelde. Ich suche den Benutzer und versuche ihn anzumelden, bekomme aber eine Fehlermeldung angezeigt (siehe unten).

Suchen des Benutzers
Java:
package com.uds.webadmin.server;

import java.util.Hashtable;

import javax.naming.AuthenticationException;
import javax.naming.Context;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext;
import javax.naming.directory.SearchControls;
import javax.naming.directory.SearchResult;

public class CLdapAuthentication
{
    public Boolean ldapLogin( String user, String pass )
    {
        
        // Admin login for searching the user
        Boolean success = false;
        String adminUser = "admin";
        String adminPassword = "admin";
        String base = "ou=extern,o=uni";
        String dn = "cn=" + adminUser + "," + base;
        String ldapURL = "ldap://papaya.de:389";

        // Setup environment for authenticating
        Hashtable<String, String> environment = new Hashtable<String, String>();
        environment.put( Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory" );
        environment.put( Context.PROVIDER_URL, ldapURL );
        environment.put( Context.SECURITY_AUTHENTICATION, "simple" );
        environment.put( Context.SECURITY_PRINCIPAL, dn );
        environment.put( Context.SECURITY_CREDENTIALS, adminPassword );

        try
        {
            // Create LDAP Context
            DirContext ctx = new InitialDirContext( environment );

            // Search the user who wants to login
            String searchFilter = "(&(objectclass=inetorgperson) (cn=" + user + "))";
            SearchControls searchControls = new SearchControls();
            searchControls.setSearchScope( SearchControls.SUBTREE_SCOPE );

            NamingEnumeration<SearchResult> results = ctx.search( "ou=usr,o=uni", searchFilter, searchControls );
            SearchResult sr = results.next();
            String userDN = sr.getName();

            System.out.println( "Found LDAP User: " + userDN );

            // if user was found...the user will be binded
            if (userDN != null)
            {
               authUser( userDN, pass);
            }
            
            ctx.close();

        }
        catch ( AuthenticationException ex )
        {
            // Authentication failed
            ex.printStackTrace();

        }
        catch ( NamingException ex )
        {
            ex.printStackTrace();
        }

        return success;

    } // End of method

}

Als Ergbnis bekomme ich Found LDAP User: cn=anstwe010,ou=a

Anmelden des gefundenen Benutzers:
Java:
private void authUser(String userName, String pass)
    {

        String base = "ou=usr,o=uni";
        String dn = userName + "," + base;
        String ldapURL = "ldap://papaya.de:636";

        // Setup environment for authenticating

        Hashtable<String, String> environment = new Hashtable<String, String>();
        environment.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
        environment.put(Context.PROVIDER_URL, ldapURL);
        environment.put(Context.SECURITY_AUTHENTICATION, "simple");
        environment.put(Context.SECURITY_PRINCIPAL, dn);
        environment.put(Context.SECURITY_CREDENTIALS, pass);

        try
        {
            DirContext authContext = new InitialDirContext(environment);
            // user is authenticated

        }
        catch (AuthenticationException ex)
        {
            // Authentication failed
            ex.printStackTrace();

        }
        catch (NamingException ex)
        {
            ex.printStackTrace();
        }
    }


Java:
javax.naming.AuthenticationException: [LDAP: error code 49 - NDS error: failed authentication (-669)]
	at com.sun.jndi.ldap.LdapCtx.mapErrorCode(LdapCtx.java:3087)
	at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:3033)
	at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2835)
	at com.sun.jndi.ldap.LdapCtx.connect(LdapCtx.java:2749)
	at com.sun.jndi.ldap.LdapCtx.<init>(LdapCtx.java:316)
	at com.sun.jndi.ldap.LdapCtxFactory.getUsingURL(LdapCtxFactory.java:193)
	at com.sun.jndi.ldap.LdapCtxFactory.getUsingURLs(LdapCtxFactory.java:211)
	at com.sun.jndi.ldap.LdapCtxFactory.getLdapCtxInstance(LdapCtxFactory.java:154)
	at com.sun.jndi.ldap.LdapCtxFactory.getInitialContext(LdapCtxFactory.java:84)
	at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:684)
	at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307)
	at javax.naming.InitialContext.init(InitialContext.java:242)
	at javax.naming.InitialContext.<init>(InitialContext.java:216)
	at javax.naming.directory.InitialDirContext.<init>(InitialDirContext.java:101)
	at com.uds.webadmin.server.CLdapAuthentication.loginUser(CLdapAuthentication.java:97)
	at com.uds.webadmin.server.CLdapAuthentication.checkLogin(CLdapAuthentication.java:56)
	at com.uds.webadmin.server.CRestLogins.getUserData(CRestLogins.java:81)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:601)
	at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
	at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:185)
	at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
	at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:288)
	at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
	at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
	at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
	at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
	at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1469)
	at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1400)
	at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1349)
	at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1339)
	at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416)
	at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537)
	at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:708)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
	at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:362)
	at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
	at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
	at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:729)
	at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
	at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
	at org.mortbay.jetty.handler.RequestLogHandler.handle(RequestLogHandler.java:49)
	at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
	at org.mortbay.jetty.Server.handle(Server.java:324)
	at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
	at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:843)
	at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:647)
	at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
	at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
	at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)
	at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488)
 

andyx1975

Aktives Mitglied
ja klar...ich suche schon den halben morgen danach... so wirklich was gefunden habe ich leider nicht :-( Danke ich schau mir das Framwork mal an.

Gruß
Andy
 

AlexSpritze

Bekanntes Mitglied
Ja, die LDAP-Fehlermeldungen sind eigentlich Murks.

Kannst du die Methoden zeigen, die hier erwähnt werden?

Code:
    at com.uds.webadmin.server.CLdapAuthentication.loginUser(CLdapAuthentication.java:97)
    at com.uds.webadmin.server.CLdapAuthentication.checkLogin(CLdapAuthentication.java:56)
    at com.uds.webadmin.server.CRestLogins.getUserData(CRestLogins.java:81)
 

GGK_01

Bekanntes Mitglied
ist zwar etwas spät, da ich aber über ein ähnliches Problem mit derselben Fehlermeldung gestolpert:

überprüfe, ob die von dir angegebenen Werte der baseDN wirklich stimmen..

GGK
 
Zuletzt bearbeitet:

andyx1975

Aktives Mitglied
Hallo,

ich weiss mittlerweile auch nicht mehr was die Ursache war... aber das Problem wurde bereits behoben. Trotzdem viellen Dank für dein Feedback!!!

Gruß
Andy
 
Ähnliche Java Themen
  Titel Forum Antworten Datum
S LDAP JAAS oder Servlet Allgemeines EE 0
Mike90 Nutzerrolle aus LDAP Verzeichnis abrufen Allgemeines EE 5
J LDAP via JNDI Allgemeines EE 13
J LDAP und AD Allgemeines EE 2
B Tomcat JNDI-Realm - LDAP mit Windows testen? Allgemeines EE 2
F FORM Auth in JBoss für User mit falscher Rolle ? Allgemeines EE 2
S Tomcat-Auth. in JSF? Allgemeines EE 6
D Fehler wegen Rest-Schnittstelle Allgemeines EE 4
A JPA Fehler beim JPA-Projekt Allgemeines EE 12
pkm "Unable to cache bundle"-Fehler bei Apache Karaf Allgemeines EE 0
H JWebUnit Fehler: java.lang.NoClassDefFoundError: org/apache/regexp/RESyntaxException Allgemeines EE 24
mor16Euro Servlet Fehler code: The requested resource is not available Allgemeines EE 7
M Servlet Fehler beim Start der Serveranwendung Allgemeines EE 3
N Fehler 403 bei Sessiontimeout mit <security-constraint> Allgemeines EE 0
Q Fehler InitialContext.lookup Allgemeines EE 3
J Fehler beim deployen von seam 2.2.2-Projekt Allgemeines EE 9
Ezra BIRT - Report erzeugt Fehler Allgemeines EE 26
JimPanse Tomcat Fehler nach redeploy Allgemeines EE 5
Z OSGi Implementierung - Fehler bei Import Package Allgemeines EE 9
H fehler beim deployen von ear file Allgemeines EE 2
E Fehler bei SQL Abfrage MAX Allgemeines EE 10
M Fehler bei Javamail Session mit Glassfish 3 Allgemeines EE 3
C WebStart Fehler nach update auf Java 1.6 Allgemeines EE 2
A jsf: Servlet aufrufen, wie geht das? web.xml Fehler? Allgemeines EE 13
M Fehler in JSF Anwendung Allgemeines EE 4
J Konvertierungs-Fehler: Wert ''{0}'' für Modell ''{1}'' Allgemeines EE 10
N Jboss als Dienst -> Fehler 1053 Allgemeines EE 1
G Fehler, wenn <f:view> Tag als Startseite Allgemeines EE 2
R auf der Suche nach dem Fehler,Sessions + Arrays Allgemeines EE 4
K Datatable Löschen Fehler Allgemeines EE 6
A Problem / Fehler beim Einbinden einer Klasse in ein JSP Allgemeines EE 20
G JSTL Fehler Allgemeines EE 2
F Fehler beim deployen von jsp und servlet Allgemeines EE 7
F Buildscript Fehler weblogic/Deployer Allgemeines EE 2
T Jsp die mehrere Servlets aufruft erzeugt Fehler Allgemeines EE 10
M Fehler aufruf von Index.html Allgemeines EE 7
K [Sun AppServer 8.1] Fehler beim deployen Allgemeines EE 12
M EJB Fehler Allgemeines EE 2

Ähnliche Java Themen

Neue Themen


Oben