Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

LDAP Template search

I have tested ldapsearch in ubuntu ldapsearch -LLL -u -x -H ldaps://xx.xx.xx.xx "(uid=testName)" uid mail
This command works perfectly. Now I'm trying to do same in Java but don't know where is the problem in my code or is it right

        LdapContextSource contextSource = new LdapContextSource();
        contextSource.setUrl("ldaps://xx.xx.xx.xx:636");
        contextSource.setBase("dc=xx,dc=xx,dc=xx");

        AndFilter filter = new AndFilter();
        filter.and(new EqualsFilter("uid",username));

        LdapTemplate template = new LdapTemplate();
        template.setContextSource(contextSource);
        template.afterPropertiesSet();

        template.search("ou=people,ou=students",filter.encode(),new AttributesMapper(){
            @Override
            public Object mapFromAttributes(Attributes attrs) throws NamingException {
                return attrs.get("mail").get();
            }
        });  

Comments