Announcement Announcement Module
No announcement yet.
Do login and get User attributes Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Do login and get User attributes

    Hi to all,
    I'm a new user.
    I have a lot of problem to create a Java code to do a login action and get all from into a LDAP.
    It's one week and I found only yesterday a Java code to do a login
     public List<User> login(String userName, String password) throws LdapException {
            List<User> list = null;
            if (!ldapTemplate.authenticate(logInFilterBase, "(cn=" + userName + ")", password)) {
                throw new GseLdapException("Error: user not authenticated!");
            } else {
                AndFilter filter = new AndFilter();
                filter.and(new EqualsFilter("objectclass", "myPersonDef")).and(new EqualsFilter("cn", userName));
                list =, filter.encode(), new AttributesMapper() {
                    public Object mapFromAttributes(Attributes atrbts) throws NamingException {
                        throw new UnsupportedOperationException("Not supported yet.");
                System.out.println("list: " + list.size());
                System.out.println("first element: " + list.get(0).getFirstUserInfo());
            return list;
    I must use inject proprieties because I don't know how and when the LDAP will change.

    To get all user info I must have an injection from servlet-context.xml to create an AttributeMapper, like I do with te ldapTemplate:
    <bean id="ldapTemplate" class="org.springframework.ldap.core.LdapTemplate">
            <property name="contextSource" ref="contextSource" />
        <bean id="ldapOperationsBean" class="com.palla.ldap.operation.impl.LdapOperationsImpl" >
            <property name="ldapTemplate" ref="ldapTemplate"/>
            <property name="logInFilterBase" value="dc=example,dc=com"/>
    Anyone can help me?
    Ask me all you want

    I read this page and other manual/tutorial, but if you give me other example is better because I had problem with some code get from the page before.
    Last edited by Palla; Mar 4th, 2013, 05:24 AM.

  • #2
    Ok, now I haven't problems.
    I just changed connections info into the xml.
    I changed localhost with my ip or with and now run.

    Is it possible ldap protocol can't resolve "ldap://localhost:<port>"?