Announcement Announcement Module
Collapse
No announcement yet.
Do login and get User attributes Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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
    Code:
     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 = ldapTemplate.search(DistinguishedName.EMPTY_PATH, 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:
    Code:
    <bean id="ldapTemplate" class="org.springframework.ldap.core.LdapTemplate">
            <property name="contextSource" ref="contextSource" />
        </bean>
        <bean id="ldapOperationsBean" class="com.palla.ldap.operation.impl.LdapOperationsImpl" >
            <property name="ldapTemplate" ref="ldapTemplate"/>
            <property name="logInFilterBase" value="dc=example,dc=com"/>
            
        </bean>
    Anyone can help me?
    Ask me all you want

    P.S.
    I read this page http://static.springsource.org/sprin...tml/index.html 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, 06: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 127.0.0.1 and now run.

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

    Comment

    Working...
    X