Announcement Announcement Module
No announcement yet.
LDAP : javax.naming.NamingException Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • LDAP : javax.naming.NamingException


    I am using Spring Security (3.0.5) to connect to an LDAP server (ApacheDS).

    XML configuration for connecting to the Ldap server

    <http use-expressions="true">
    		<intercept-url pattern="/" access="permitAll" />
    		<intercept-url pattern="/**" access="isAuthenticated()" />
    		<form-login />
    		<logout />
    <ldap-server id="ldapServer" url="ldap://localhost:10389/" 	
    manager-dn="uid=admin,ou=system" manager-password="secret" />
      <ldap-authentication-provider server-ref="ldapServer"
            user-search-filter="uid={0}" />
    When trying to login by specifying a valid username and password (wbush & password, refer image for ldap browser view), I get the following error

    Reason: Uncategorized exception occured during LDAP processing; nested exception is javax.naming.NamingException: [LDAP: error code 80 - OTHER: failed for SearchRequest baseDn : '' filter : '( bush,,[9223372036854775807])' scope : whole subtree typesOnly : false Size Limit : no limit Time Limit : no limit Deref Aliases : deref Always attributes : 'cn', 'objectclass', 'javaserializeddata', 'javaclassname', 'javafactory', 'javacodebase', 'javareferenceaddress', 'javaclassnames', 'javaremotelocation' : -1]; remaining name ''
    I do not get any useful logs, relevent log snippet is as follows

    Apr 7, 2011 8:16:25 PM org.springframework.ldap.core.LdapTemplate assureReturnObjFlagSet
    INFO: The returnObjFlag of supplied SearchControls is not set but a ContextMapper is used - setting flag to true

    Access log
    0:0:0:0:0:0:0:1 - - [07/Apr/2011:20:16:15 +0530] "GET /ldapsample/products/1 HTTP/1.1" 302 -
    0:0:0:0:0:0:0:1 - - [07/Apr/2011:20:16:15 +0530] "GET /ldapsample/spring_security_login HTTP/1.1" 200 554
    0:0:0:0:0:0:0:1 - - [07/Apr/2011:20:16:15 +0530] "GET /favicon.ico HTTP/1.1" 404 1247
    0:0:0:0:0:0:0:1 - - [07/Apr/2011:20:16:25 +0530] "POST /ldapsample/j_spring_security_check HTTP/1.1" 302 -
    0:0:0:0:0:0:0:1 - - [07/Apr/2011:20:16:25 +0530] "GET /ldapsample/spring_security_login?login_error HTTP/1.1" 200 1303
    0:0:0:0:0:0:0:1 - - [07/Apr/2011:20:16:25 +0530] "GET /favicon.ico HTTP/1.1" 404 1247
    Normal working java program which does what I require (login to ldap server as admin and then check for a registered user based on username)

    	public void ldapAuthenticationIsSuccessful() throws Exception {
    		Hashtable<String, String> env = new Hashtable<String, String>();
    		env.put(Context.SECURITY_AUTHENTICATION, "simple");
    		env.put(Context.SECURITY_PRINCIPAL, "uid=admin,ou=system");
    		env.put(Context.PROVIDER_URL, "ldap://localhost:10389/");
    		env.put(Context.SECURITY_CREDENTIALS, "secret");
    		InitialLdapContext ctx = new InitialLdapContext(env, null);
    		NamingEnumeration results = null;
    		SearchControls controls = new SearchControls();
    		results ="ou=people,o=sevenSeas", "(uid=wbush)", controls);
    		while (results.hasMore()) {
    			SearchResult searchResult = (SearchResult);
    			Attributes attributes = searchResult.getAttributes();
    			Attribute attr = attributes.get("cn");
    			String cn = (String) attr.get();
    A view of my ldap server looks like this,

    I have doubly verifies that the supplied ldap server credentials and the username and password of the user being searched for a correct (I have tried searching for the same user with an ldap browser and it works)

    Any Idea what I am missing?

    Last edited by vishwas; Apr 7th, 2011, 09:57 AM.

  • #2
    Please post the contextual debug log, stack trace (if any) and the equivalent java code which works (see this FAQ).


    • #3
      Originally posted by Luke Taylor View Post
      Please post the contextual debug log, stack trace (if any) and the equivalent java code which works (see this FAQ).
      Thanks Luke,

      I have updated the question with required details


      • #4
        Hello, vishwas, Could you solve the problem?