Search in sources :

Example 6 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)

Example 7 with LdapQuery

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

the class GatekeeperOpenLDAPAuthorizationService method loadUserMemberships.

protected Set<String> loadUserMemberships(String userName) {
    Pattern cnPattern = Pattern.compile("cn=([- _A-Za-z0-9]+)", Pattern.CASE_INSENSITIVE);
    logger.info("Checking Memberships for " + userName);
    Set<String> memberships = new HashSet<>();
    String memberof = "memberOf";
    LdapQuery query = LdapQueryBuilder.query().base(ldapProperties.getUsersBase()).countLimit(1000).searchScope(SearchScope.SUBTREE).attributes(memberof).where("objectClass").is(ldapObjectClass).and(ldapUserId).is(userName);
    LinkedList<String[]> subjects = (LinkedList<String[]>) ldapTemplate.search(query, new OpenLdapMembershipsMapper());
    if (subjects == null || subjects.size() == 0) {
        if (ldapProperties.getTestUsersBase() != null) {
            query = LdapQueryBuilder.query().base(ldapProperties.getTestUsersBase()).countLimit(1000).searchScope(SearchScope.SUBTREE).attributes("memberOf").where("objectClass").is(ldapObjectClass).and(ldapUserId).is(userName);
            subjects = (LinkedList<String[]>) ldapTemplate.search(query, new OpenLdapMembershipsMapper());
        }
    }
    HashSet<String> extracted = new HashSet<>();
    Arrays.asList(subjects.getFirst()).forEach(item -> {
        Matcher m = cnPattern.matcher(item);
        if (m.find()) {
            extracted.add(m.group(1));
        }
    });
    return extracted;
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) LdapQuery(org.springframework.ldap.query.LdapQuery)

Aggregations

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