Results 1 to 2 of 2

Thread: ldaptemplate.search ClassCastException

  1. #1

    Default ldaptemplate.search ClassCastException

    Hi,

    I am getting ClassCastException when i carry out an ldap search over an anonymous context source. it works fine when i use an authenticated context source. I have attached the code below,

    your help is very much appreciated.

    Code:
     LdapContextSource contextSource = new LdapContextSource();
            contextSource.setAnonymousReadOnly(true);
            contextSource.setUrl(hostUrl);
            contextSource.setBase(base);
            contextSource.setPooled(false);
            contextSource.setBaseEnvironmentProperties(new HashMap());        
            contextSource.afterPropertiesSet();
    
    ldapTemplate   = new LdapTemplate(contextSource);
    p = (Person)ldapTemplate.search(Constants.LDAP_USER_DN, filter.encode(),
                                                        new ContextMapper(){
                                public Object mapFromContext(Object ctx) {
                                    DirContextOperations    context = (DirContextOperations)ctx;
                                    System.out.println(context.getDn());                                 
                                    return new Person(context.getAttributes());
                                }
                            });
    Note: the print statement is printing the context Dn successfully.

  2. #2

    Smile ClassCastingException resolved

    found the solution:

    ldapTemplate.search returns java.util.LinkedList instead of the object I have expected.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •