Announcement Announcement Module
Collapse
No announcement yet.
ldaptemplate.search ClassCastException Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    ClassCastingException resolved

    found the solution:

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

    Comment

    Working...
    X