Example usage for org.springframework.security.ldap SpringSecurityLdapTemplate setSearchControls

List of usage examples for org.springframework.security.ldap SpringSecurityLdapTemplate setSearchControls

Introduction

In this page you can find the example usage for org.springframework.security.ldap SpringSecurityLdapTemplate setSearchControls.

Prototype

public void setSearchControls(SearchControls searchControls) 

Source Link

Document

Sets the search controls which will be used for search operations by the template.

Usage

From source file:com.orangeleap.common.security.OrangeLeapLdapUserSearch.java

/**
 * Return the LdapUserDetails containing the user's information
 *
 * @param username the username to search for.
 * @return An LdapUserDetails object containing the details of the located user's directory entry
 * @throws UsernameNotFoundException if no matching entry is found.
 */// w w  w  .  j  av a2  s  .  c o  m
public DirContextOperations searchForUser(String username, String site) {
    SpringSecurityLdapTemplate template = new SpringSecurityLdapTemplate(contextSource);

    template.setSearchControls(searchControls);

    try {
        String searchBase = "o=" + site;
        return template.searchForSingleEntry(searchBase, searchFilter, new String[] { username });

    } catch (IncorrectResultSizeDataAccessException notFound) {
        if (notFound.getActualSize() == 0) {
            throw new UsernameNotFoundException("User " + username + " not found in directory.", username);
        }
        // Search should never return multiple results if properly configured, so just rethrow
        throw notFound;
    }
}

From source file:com.orangeleap.common.security.OrangeLeapLdapUserSearch.java

/**
 * Return the LdapUserDetails containing the user's information
 *
 * @param username the username to search for.
 * @return An LdapUserDetails object containing the details of the located user's directory entry
 * @throws UsernameNotFoundException if no matching entry is found.
 *//*from   w w  w.j  av a  2s  .c om*/
public DirContextOperations searchForUser(String username) {
    SpringSecurityLdapTemplate template = new SpringSecurityLdapTemplate(contextSource);

    template.setSearchControls(searchControls);

    try {

        String[] filterArgs;
        String aSearchBase;

        if (username.indexOf("@") > -1) {
            String[] split = username.split("@");
            filterArgs = new String[] { split[0] };
            aSearchBase = "o=" + split[1];
        } else {
            filterArgs = new String[] { username };
            aSearchBase = searchBase;
        }

        return template.searchForSingleEntry(aSearchBase, searchFilter, filterArgs);

    } catch (IncorrectResultSizeDataAccessException notFound) {
        if (notFound.getActualSize() == 0) {
            throw new UsernameNotFoundException("User " + username + " not found in directory.", username);
        }
        // Search should never return multiple results if properly configured, so just rethrow
        throw notFound;
    }
}

From source file:org.springframework.security.ldap.search.FilterBasedLdapUserSearch.java

/**
 * Return the LdapUserDetails containing the user's information
 *
 * @param username the username to search for.
 *
 * @return An LdapUserDetails object containing the details of the located user's
 * directory entry/*from  www .j  a  va  2s . co  m*/
 *
 * @throws UsernameNotFoundException if no matching entry is found.
 */
@Override
public DirContextOperations searchForUser(String username) {
    if (logger.isDebugEnabled()) {
        logger.debug("Searching for user '" + username + "', with user search " + this);
    }

    SpringSecurityLdapTemplate template = new SpringSecurityLdapTemplate(contextSource);

    template.setSearchControls(searchControls);

    try {

        return template.searchForSingleEntry(searchBase, searchFilter, new String[] { username });

    } catch (IncorrectResultSizeDataAccessException notFound) {
        if (notFound.getActualSize() == 0) {
            throw new UsernameNotFoundException("User " + username + " not found in directory.");
        }
        // Search should never return multiple results if properly configured, so just
        // rethrow
        throw notFound;
    }
}