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

  • LDAP : javax.naming.NamingException

    Hi,

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

    XML configuration for connecting to the Ldap server

    Code:
    <http use-expressions="true">
    		<intercept-url pattern="/" access="permitAll" />
    		<intercept-url pattern="/**" access="isAuthenticated()" />
    		<form-login />
    		<logout />
    </http>
    
    <ldap-server id="ldapServer" url="ldap://localhost:10389/" 	
    manager-dn="uid=admin,ou=system" manager-password="secret" />
    
    <authentication-manager>
      <ldap-authentication-provider server-ref="ldapServer"
    	user-search-base="ou=people,o=sevenSeas" 
            user-search-filter="uid={0}" />
    </authentication-manager>
    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 : '(2.5.4.50=2.5.4.3=william bush,2.5.4.11=people,2.5.4.10=sevenseas:[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)

    Code:
    @Test
    	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");
    		env.put(Context.INITIAL_CONTEXT_FACTORY,
    				"com.sun.jndi.ldap.LdapCtxFactory");
    
    		InitialLdapContext ctx = new InitialLdapContext(env, null);
    
    		NamingEnumeration results = null;
    
    		SearchControls controls = new SearchControls();
    		controls.setSearchScope(SearchControls.SUBTREE_SCOPE);
    		results = ctx.search("ou=people,o=sevenSeas", "(uid=wbush)", controls);
    
    		while (results.hasMore()) {
    			SearchResult searchResult = (SearchResult) results.next();
    			Attributes attributes = searchResult.getAttributes();
    			Attribute attr = attributes.get("cn");
    			String cn = (String) attr.get();
    			System.out.println(cn);
    		}
    	}
    A view of my ldap server looks like this,
    http://img51.imageshack.us/i/newbitmapimageib.png/

    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?

    Thanks,
    Vishwas
    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).

    Comment


    • #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

      Comment


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

        Comment

        Working...
        X