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