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

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

Introduction

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

Prototype

public void setSearchSubtree(boolean searchSubtree) 

Source Link

Document

If true then searches the entire subtree as identified by context, if false (the default) then only searches the level identified by the context.

Usage

From source file:com.evolveum.midpoint.web.boot.LdapSecurityConfig.java

@ConditionalOnProperty("auth.ldap.search.pattern")
@Bean/*from www. j av a 2 s . c o m*/
public FilterBasedLdapUserSearch userSearch() {
    FilterBasedLdapUserSearch search = new FilterBasedLdapUserSearch("", ldapSearchPattern, contextSource());
    search.setSearchSubtree(searchSubtree);
    return search;
}

From source file:org.artifactory.addon.CoreAddonsImpl.java

@Override
public List<FilterBasedLdapUserSearch> getLdapUserSearches(ContextSource ctx, LdapSetting settings) {
    SearchPattern searchPattern = settings.getSearch();
    String searchBase = searchPattern.getSearchBase();
    if (searchBase == null) {
        searchBase = "";
    }//from   w  w  w.j a va 2 s  .c o  m
    ArrayList<FilterBasedLdapUserSearch> result = new ArrayList<>();
    FilterBasedLdapUserSearch userSearch = new FilterBasedLdapUserSearch(searchBase,
            searchPattern.getSearchFilter(), (BaseLdapPathContextSource) ctx);
    userSearch.setSearchSubtree(searchPattern.isSearchSubTree());
    result.add(userSearch);
    return result;
}

From source file:org.apache.atlas.web.security.AtlasADAuthenticationProvider.java

private Authentication getADBindAuthentication(Authentication authentication) {
    try {//  ww w  .j  a  va2s. c o m
        String userName = authentication.getName();
        String userPassword = "";
        if (authentication.getCredentials() != null) {
            userPassword = authentication.getCredentials().toString();
        }

        LdapContextSource ldapContextSource = new DefaultSpringSecurityContextSource(adURL);
        ldapContextSource.setUserDn(adBindDN);
        ldapContextSource.setPassword(adBindPassword);
        ldapContextSource.setReferral(adReferral);
        ldapContextSource.setCacheEnvironmentProperties(true);
        ldapContextSource.setAnonymousReadOnly(false);
        ldapContextSource.setPooled(true);
        ldapContextSource.afterPropertiesSet();

        if (adUserSearchFilter == null || adUserSearchFilter.trim().isEmpty()) {
            adUserSearchFilter = "(sAMAccountName={0})";
        }
        FilterBasedLdapUserSearch userSearch = new FilterBasedLdapUserSearch(adBase, adUserSearchFilter,
                ldapContextSource);
        userSearch.setSearchSubtree(true);

        BindAuthenticator bindAuthenticator = new BindAuthenticator(ldapContextSource);
        bindAuthenticator.setUserSearch(userSearch);
        bindAuthenticator.afterPropertiesSet();

        LdapAuthenticationProvider ldapAuthenticationProvider = new LdapAuthenticationProvider(
                bindAuthenticator);

        if (userName != null && userPassword != null && !userName.trim().isEmpty()
                && !userPassword.trim().isEmpty()) {
            final List<GrantedAuthority> grantedAuths = getAuthorities(userName);
            final UserDetails principal = new User(userName, userPassword, grantedAuths);
            final Authentication finalAuthentication = new UsernamePasswordAuthenticationToken(principal,
                    userPassword, grantedAuths);
            authentication = ldapAuthenticationProvider.authenticate(finalAuthentication);
            if (groupsFromUGI) {
                authentication = getAuthenticationWithGrantedAuthorityFromUGI(authentication);
            }
            return authentication;
        } else {
            LOG.error("AD Authentication Failed userName or userPassword is null or empty");
            return null;
        }
    } catch (Exception e) {
        LOG.error("AD Authentication Failed:", e);
        return null;
    }
}

From source file:org.apache.atlas.web.security.AtlasLdapAuthenticationProvider.java

private Authentication getLdapBindAuthentication(Authentication authentication) {
    try {//from w  w w .j a va 2s  . com
        if (isDebugEnabled) {
            LOG.debug("==> AtlasLdapAuthenticationProvider getLdapBindAuthentication");
        }
        String userName = authentication.getName();
        String userPassword = "";
        if (authentication.getCredentials() != null) {
            userPassword = authentication.getCredentials().toString();
        }

        LdapContextSource ldapContextSource = getLdapContextSource();

        DefaultLdapAuthoritiesPopulator defaultLdapAuthoritiesPopulator = getDefaultLdapAuthoritiesPopulator(
                ldapContextSource);

        if (ldapUserSearchFilter == null || ldapUserSearchFilter.trim().isEmpty()) {
            ldapUserSearchFilter = "(uid={0})";
        }

        FilterBasedLdapUserSearch userSearch = new FilterBasedLdapUserSearch(ldapBase, ldapUserSearchFilter,
                ldapContextSource);
        userSearch.setSearchSubtree(true);

        BindAuthenticator bindAuthenticator = getBindAuthenticator(userSearch, ldapContextSource);

        LdapAuthenticationProvider ldapAuthenticationProvider = new LdapAuthenticationProvider(
                bindAuthenticator, defaultLdapAuthoritiesPopulator);

        if (userName != null && userPassword != null && !userName.trim().isEmpty()
                && !userPassword.trim().isEmpty()) {
            final List<GrantedAuthority> grantedAuths = getAuthorities(userName);
            final UserDetails principal = new User(userName, userPassword, grantedAuths);
            final Authentication finalAuthentication = new UsernamePasswordAuthenticationToken(principal,
                    userPassword, grantedAuths);
            authentication = ldapAuthenticationProvider.authenticate(finalAuthentication);
            if (groupsFromUGI) {
                authentication = getAuthenticationWithGrantedAuthorityFromUGI(authentication);
            }
            return authentication;
        } else {
            LOG.error(
                    "LDAP Authentication::userName or userPassword is null or empty for userName " + userName);
        }
    } catch (Exception e) {
        LOG.error(" getLdapBindAuthentication LDAP Authentication Failed:", e);
    }
    if (isDebugEnabled) {
        LOG.debug("<== AtlasLdapAuthenticationProvider getLdapBindAuthentication");
    }
    return authentication;
}

From source file:org.madsonic.ldap.MadsonicLdapBindAuthenticator.java

/**
 * Creates the delegate {@link BindAuthenticator}.
 *///from ww w. ja va2s.  c o m
private synchronized void createDelegate() {

    // Only create it if necessary.
    if (delegateAuthenticator == null || authenticatorTimestamp < settingsService.getSettingsChanged()) {

        LdapContextSource contextSource = new LdapContextSource();
        contextSource.setReferral("follow");
        contextSource.setUrl(settingsService.getLdapUrl());

        String managerDn = settingsService.getLdapManagerDn();
        String managerPassword = settingsService.getLdapManagerPassword();
        if (StringUtils.isNotEmpty(managerDn) && StringUtils.isNotEmpty(managerPassword)) {
            contextSource.setUserDn(managerDn);
            contextSource.setPassword(managerPassword);
        }

        FilterBasedLdapUserSearch userSearch = new FilterBasedLdapUserSearch("",
                settingsService.getLdapSearchFilter(), contextSource);
        userSearch.setSearchSubtree(true);
        userSearch.setDerefLinkFlag(true);

        delegateAuthenticator = new BindAuthenticator(contextSource);
        delegateAuthenticator.setUserSearch(userSearch);

        authenticatorTimestamp = settingsService.getSettingsChanged();
    }
}