Announcement Announcement Module
Collapse
No announcement yet.
[LDAP: error code 34 - invalid DN] on LdapTemplate.search Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • [LDAP: error code 34 - invalid DN] on LdapTemplate.search

    I made LDAP authentication for my project and it works well.(3.1.0.RELEASE)
    But I did not get to recive additional information about the LDAP user.
    I keep getting an error: [LDAP: error code 34 - invalid DN].
    spring-security.xml:
    Code:
    <beans:beans xmlns="http://www.springframework.org/schema/security"
        xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
                            http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                            http://www.springframework.org/schema/security
                            http://www.springframework.org/schema/security/spring-security-3.1.xsd">
    ...
        <ldap-server url="ldap://ldap.andri.com:389/dc=andri,dc=com" />
    
        <authentication-manager>
            <authentication-provider ref='jtwAuthProvider' />
            <ldap-authentication-provider
                group-search-filter="member={0}" user-search-base="ou=Addressbook"
                user-search-filter="uid={0}" />
        </authentication-manager>
    
        <beans:bean id="jtwAuthProvider"
            class="org.springframework.security.ldap.authentication.LdapAuthenticationProvider">
            <beans:constructor-arg>
                <beans:bean
                    class="org.springframework.security.ldap.authentication.BindAuthenticator">
                    <beans:constructor-arg ref="contextSource" />
                    <beans:property name="userSearch">
                        <beans:bean id="userSearch"
                            class="org.springframework.security.ldap.search.FilterBasedLdapUserSearch">
                            <beans:constructor-arg index="0"
                                value="ou=Addressbook,dc=ldap,dc=andri,dc=com" />
                            <beans:constructor-arg index="1"
                                value="userPrincipalName={0}" />
                            <beans:constructor-arg index="2"
                                ref="contextSource" />
                        </beans:bean>
                    </beans:property>
                </beans:bean>
            </beans:constructor-arg>
        </beans:bean>
    
        <beans:bean id="contextSource"
            class="org.springframework.security.ldap.DefaultSpringSecurityContextSource">
            <beans:constructor-arg value="ldap://ldap.andri.com:389" />
            <beans:property name="userDn"
                value="cn=LDAPaccess,ou=Special,dc=ldap,dc=andri,dc=com" />
            <beans:property name="password" value="GfGTgFD" />
        </beans:bean>
    
    </beans:beans>
    Login controller:
    Code:
    ...
    LdapTemplate template;
    
    @Autowired
    public void setTemplate(LdapContextSource contextSource) {
        template = new LdapTemplate(contextSource);
    }
    ...
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/books", method = RequestMethod.GET)
    public String books(ModelMap model, Principal principal)
            throws BookServiceException {
    
        class UserAttributesMapper implements AttributesMapper {
    
            @Override
            public Object mapFromAttributes(Attributes attributes)
                    throws NamingException {
                Map<String, String> map = new HashMap<String, String>();
                String fullname = (String) attributes.get("displayName").get();
                String email = (String) attributes.get("mail").get();
                String title = (String) attributes.get("title").get();
    
                map.put("fullname", fullname);
                map.put("email", email);
                map.put("title", title);
                return map;
            }
        }
    
        Map<String, String> results = new HashMap<String, String>();
        String objectClass = "samAccountName=" + principal.getName();
    
        LinkedList<Map<String, String>> list = (LinkedList<Map<String, String>>) template
                .search("ou=Addressbook,dc=andri,dc=com", objectClass,
                        new UserAttributesMapper());
        results = list.get(0);
        model.addAttribute("userinfo", results.toString());
        return "books";
    }
    I tried using different DN: "ou=Addressbook,dc=andri,dc=com" "cn=aartemenko,ou=Addressbook,dc=andri,dc=com" "dc=andri,dc=com" "" "cn=aartemenko,ou=Special,dc=andri,dc=com" etc

    But the result is the same. What am I doing wrong?

  • #2
    Error text:
    Code:
    javax.naming.InvalidNameException: [LDAP: error code 34 - invalid DN]
    	at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:3028)
    	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.ldap.InitialLdapContext.<init>(InitialLdapContext.java:153)
    	at org.springframework.ldap.core.support.LdapContextSource.getDirContextInstance(LdapContextSource.java:43)
    	at org.springframework.ldap.core.support.AbstractContextSource.createContext(AbstractContextSource.java:254)
    	at org.springframework.ldap.core.support.AbstractContextSource.getContext(AbstractContextSource.java:106)
    	at org.springframework.ldap.core.support.AbstractContextSource.getReadOnlyContext(AbstractContextSource.java:125)
    	at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:287)
    	at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:259)
    	at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:571)
    	at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:556)
    	at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:411)
    	at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:431)
    	at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:451)
    	at com.exadel.library.controller.BooksController.books(BooksController.java:94)
    	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 org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:212)
    	at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)
    	at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)
    	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)
    	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)
    	at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
    	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:900)
    	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:827)
    	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
    	at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:311)
    	at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:116)
    	at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
    	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
    	at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
    	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
    	at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:101)
    	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
    	at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
    	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
    	at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
    	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
    	at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
    	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
    	at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:150)
    	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
    	at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:182)
    	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
    	at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
    	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
    	at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
    	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
    	at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:173)
    	at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
    	at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
    	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
    	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
    	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
    	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    	at java.lang.Thread.run(Thread.java:722)

    Comment


    • #3
      Sorry, it realy stupid. It was mistake in LDAPaccess cn.

      Comment

      Working...
      X