Example usage for org.springframework.security.ldap.search FilterBasedLdapUserSearch setReturningAttributes

List of usage examples for org.springframework.security.ldap.search FilterBasedLdapUserSearch setReturningAttributes

Introduction

In this page you can find the example usage for org.springframework.security.ldap.search FilterBasedLdapUserSearch setReturningAttributes.

Prototype

public void setReturningAttributes(String[] attrs) 

Source Link

Document

Specifies the attributes that will be returned as part of the search.

Usage

From source file:fr.univlorraine.mondossierweb.config.SpringConfig.java

@Bean
public LdapUserSearch ldapUserSearch() {
    FilterBasedLdapUserSearch fbus = new FilterBasedLdapUserSearch("ou=people", "uid={0}", ldapServer());
    fbus.setReturningAttributes(getLdapAttributes());
    return fbus;// w  ww .java 2  s.  c o  m
}

From source file:fr.univlorraine.mondossierweb.config.SpringConfig.java

@Bean
public LdapUserSearch ldapEtudiantSearch() {
    FilterBasedLdapUserSearch fbus = new FilterBasedLdapUserSearch("ou=people",
            environment.getProperty("attributLdapCodEtu") + "={0}", ldapServer());
    fbus.setReturningAttributes(getLdapAttributes());
    return fbus;// w w w  .  j  a  va 2 s  .c  om
}

From source file:org.opencastproject.userdirectory.ldap.LdapUserProviderInstance.java

/**
 * Constructs an ldap user provider with the needed settings.
 * /*  w ww  . ja v a 2s  .co  m*/
 * @param pid
 *          the pid of this service
 * @param organization
 *          the organization
 * @param searchBase
 *          the ldap search base
 * @param searchFilter
 *          the ldap search filter
 * @param url
 *          the url of the ldap server
 * @param userDn
 *          the user to authenticate as
 * @param password
 *          the user credentials
 * @param roleAttributesGlob
 *          the comma separate list of ldap attributes to treat as roles
 * @param cacheSize
 *          the number of users to cache
 * @param cacheExpiration
 *          the number of minutes to cache users
 */
// CHECKSTYLE:OFF
LdapUserProviderInstance(String pid, String organization, String searchBase, String searchFilter, String url,
        String userDn, String password, String roleAttributesGlob, int cacheSize, int cacheExpiration) {
    // CHECKSTYLE:ON
    this.organization = organization;
    logger.debug("Creating LdapUserProvider instance with pid=" + pid + ", and organization=" + organization
            + ", to LDAP server at url:  " + url);

    DefaultSpringSecurityContextSource contextSource = new DefaultSpringSecurityContextSource(url);
    if (StringUtils.isNotBlank(userDn)) {
        contextSource.setPassword(password);
        contextSource.setUserDn(userDn);
        // Required so that authentication will actually be used
        contextSource.setAnonymousReadOnly(false);
    } else {
        // No password set so try to connect anonymously. 
        contextSource.setAnonymousReadOnly(true);
    }

    try {
        contextSource.afterPropertiesSet();
    } catch (Exception e) {
        throw new org.opencastproject.util.ConfigurationException("Unable to create a spring context source",
                e);
    }
    FilterBasedLdapUserSearch userSearch = new FilterBasedLdapUserSearch(searchBase, searchFilter,
            contextSource);
    userSearch.setReturningAttributes(roleAttributesGlob.split(","));
    this.delegate = new LdapUserDetailsService(userSearch);

    if (StringUtils.isNotBlank(roleAttributesGlob)) {
        LdapUserDetailsMapper mapper = new LdapUserDetailsMapper();
        mapper.setRoleAttributes(roleAttributesGlob.split(","));
        this.delegate.setUserDetailsMapper(mapper);
    }

    // Setup the caches
    cache = new MapMaker().maximumSize(cacheSize).expireAfterWrite(cacheExpiration, TimeUnit.MINUTES)
            .makeComputingMap(new Function<String, Object>() {
                public Object apply(String id) {
                    User user = loadUserFromLdap(id);
                    return user == null ? nullToken : user;
                }
            });

    registerMBean(pid);
}