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();
}
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;
}
Aggregations