Search in sources :

Example 1 with LdapQuery

use of org.springframework.ldap.query.LdapQuery in project Gatekeeper by FINRAOS.

the class GatekeeperOpenLDAPAuthorizationService method loadUser.

protected GatekeeperUserEntry loadUser(String userName) {
    logger.info("Loading info for " + userName);
    LdapQuery query = LdapQueryBuilder.query().base(ldapProperties.getUsersBase()).countLimit(1).searchScope(SearchScope.SUBTREE).attributes(ldapUserId, ldapUserDn, ldapUserEmail, ldapUserName).where("objectClass").is(ldapObjectClass).and(ldapUserId).is(userName);
    List<GatekeeperUserEntry> subjects = ldapTemplate.search(query, getAttributesMapper());
    if (subjects != null && subjects.size() > 0) {
        return subjects.get(0);
    // check to see if account is test account (only if testUsersBase is provided)
    } else if (ldapProperties.getTestUsersBase() != null) {
        query = LdapQueryBuilder.query().base(ldapProperties.getTestUsersBase()).countLimit(1).searchScope(SearchScope.SUBTREE).attributes(ldapUserId, ldapUserDn, ldapUserEmail, ldapUserName).where("objectCategory").is(ldapObjectClass).and(ldapUserId).is(userName);
        subjects = ldapTemplate.search(query, getAttributesMapper());
        // return null;
        if (subjects != null && subjects.size() > 0) {
            return subjects.get(0);
        }
    }
    return null;
}
Also used : GatekeeperUserEntry(org.finra.gatekeeper.common.services.user.model.GatekeeperUserEntry) LdapQuery(org.springframework.ldap.query.LdapQuery)

Example 2 with LdapQuery

use of org.springframework.ldap.query.LdapQuery in project kylo by Teradata.

the class LdapGroupList method getAllGroups.

public void getAllGroups(LdapTemplate ldapTemplate, String groupBaseDnPattern) {
    try {
        groupInfo = new ArrayList<>();
        LdapQuery query = query().base(groupBaseDnPattern);
        groupInfo = ldapTemplate.list(query.base());
    } catch (NamingException e) {
        log.error("Unable to Groups from LDAP " + e.getMessage());
        throw new RuntimeException(e);
    }
}
Also used : NamingException(org.springframework.ldap.NamingException) LdapQuery(org.springframework.ldap.query.LdapQuery)

Example 3 with LdapQuery

use of org.springframework.ldap.query.LdapQuery in project gravitee-management-rest-api by gravitee-io.

the class LdapIdentityLookup method search.

@Override
public Collection<User> search(String query) {
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    try {
        Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
        Filter classFilter = new EqualsFilter("objectclass", environment.getProperty("user-search-objectclass", LDAP_DEFAULT_OBJECT_CLASS));
        Filter queryFilter = new OrFilter().or(new WhitespaceWildcardsFilter(LDAP_ATTRIBUTE_COMMONNAME, query)).or(new EqualsFilter(LDAP_ATTRIBUTE_USERID, query));
        LdapQuery ldapQuery = LdapQueryBuilder.query().base(baseDn).countLimit(20).timeLimit(5000).searchScope(SearchScope.SUBTREE).attributes(LDAP_ATTRIBUTE_GIVENNAME, LDAP_ATTRIBUTE_SURNAME, LDAP_ATTRIBUTE_MAIL, LDAP_ATTRIBUTE_DISPLAYNAME).filter(new AndFilter().and(classFilter).and(queryFilter));
        return ldapTemplate.search(ldapQuery, USER_CONTEXT_MAPPER);
    } catch (LimitExceededException lee) {
        LOGGER.info("Too much results while searching for [" + query + "]. Returns an empty list.");
        return Collections.emptyList();
    } finally {
        Thread.currentThread().setContextClassLoader(classLoader);
    }
}
Also used : LimitExceededException(org.springframework.ldap.LimitExceededException) LdapQuery(org.springframework.ldap.query.LdapQuery)

Example 4 with LdapQuery

use of org.springframework.ldap.query.LdapQuery in project spring-boot by spring-projects.

the class DataLdapTestIntegrationTests method testRepository.

@Test
void testRepository() {
    LdapQuery ldapQuery = LdapQueryBuilder.query().where("cn").is("Bob Smith");
    Optional<ExampleEntry> entry = this.exampleRepository.findOne(ldapQuery);
    assertThat(entry.isPresent()).isTrue();
    assertThat(entry.get().getDn()).isEqualTo(LdapUtils.newLdapName("cn=Bob Smith,ou=company1,c=Sweden,dc=spring,dc=org"));
    assertThat(this.ldapTemplate.findOne(ldapQuery, ExampleEntry.class).getDn()).isEqualTo(LdapUtils.newLdapName("cn=Bob Smith,ou=company1,c=Sweden,dc=spring,dc=org"));
}
Also used : LdapQuery(org.springframework.ldap.query.LdapQuery) Test(org.junit.jupiter.api.Test)

Example 5 with LdapQuery

use of org.springframework.ldap.query.LdapQuery in project spring-boot by spring-projects.

the class DataLdapTestWithIncludeFilterIntegrationTests method testService.

@Test
void testService() {
    LdapQuery ldapQuery = LdapQueryBuilder.query().where("cn").is("Will Smith");
    assertThat(this.service.hasEntry(ldapQuery)).isFalse();
}
Also used : LdapQuery(org.springframework.ldap.query.LdapQuery) Test(org.junit.jupiter.api.Test)

Aggregations

LdapQuery (org.springframework.ldap.query.LdapQuery)6 Test (org.junit.jupiter.api.Test)2 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 GatekeeperUserEntry (org.finra.gatekeeper.common.services.user.model.GatekeeperUserEntry)1 LimitExceededException (org.springframework.ldap.LimitExceededException)1 NamingException (org.springframework.ldap.NamingException)1