DefaultLdapUsernameToDnMapper.java :  » J2EE » spring-ide_2.3.0 » org » springframework » security » ldap » Java Open Source

Java Open Source » J2EE » spring ide_2.3.0 
spring ide_2.3.0 » org » springframework » security » ldap » DefaultLdapUsernameToDnMapper.java
package org.springframework.security.ldap;

import org.springframework.ldap.core.DistinguishedName;

/**
 * This implementation appends a name component to the <tt>userDnBase</tt> context using the
 * <tt>usernameAttributeName</tt> property. So if the <tt>uid</tt> attribute is used to store the username, and the
 * base DN is <tt>cn=users</tt> and we are creating a new user called "sam", then the DN will be
 * <tt>uid=sam,cn=users</tt>.
 *
 * @author Luke Taylor
 * @version $Id: DefaultLdapUsernameToDnMapper.java 2338 2007-12-06 00:13:42Z luke_t $
 */
public class DefaultLdapUsernameToDnMapper implements LdapUsernameToDnMapper {
    private String userDnBase;
    private String usernameAttribute;

   /**
    * @param userDnBase the base name of the DN
    * @param usernameAttribute the attribute to append for the username component.
    */
    public DefaultLdapUsernameToDnMapper(String userDnBase, String usernameAttribute) {
        this.userDnBase = userDnBase;
        this.usernameAttribute = usernameAttribute;
    }

    /**
     * Assembles the Distinguished Name that should be used the given username.
     */
    public DistinguishedName buildDn(String username) {
        DistinguishedName dn = new DistinguishedName(userDnBase);

        dn.add(usernameAttribute, username);

        return dn;
    }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.