use of org.ldaptive.SearchOperation in project cas by apereo.
the class LdapUtils method executeSearchOperation.
/**
* Execute search operation.
*
* @param connectionFactory the connection factory
* @param baseDn the base dn
* @param filter the filter
* @param binaryAttributes the binary attributes
* @param returnAttributes the return attributes
* @return the response
* @throws LdapException the ldap exception
*/
public static Response<SearchResult> executeSearchOperation(final ConnectionFactory connectionFactory, final String baseDn, final SearchFilter filter, final String[] binaryAttributes, final String[] returnAttributes) throws LdapException {
try (Connection connection = createConnection(connectionFactory)) {
final SearchOperation searchOperation = new SearchOperation(connection);
final SearchRequest request = LdapUtils.newLdaptiveSearchRequest(baseDn, filter, binaryAttributes, returnAttributes);
request.setReferralHandler(new SearchReferralHandler());
return searchOperation.execute(request);
}
}
use of org.ldaptive.SearchOperation in project cas by apereo.
the class LdapSpnegoKnownClientSystemsFilterAction method executeSearchForSpnegoAttribute.
/**
* Searches the ldap instance for the attribute value.
*
* @param remoteIp the remote ip
* @return true/false
*/
@SneakyThrows
protected boolean executeSearchForSpnegoAttribute(final String remoteIp) {
Connection connection = null;
final String remoteHostName = getRemoteHostName(remoteIp);
LOGGER.debug("Resolved remote hostname [{}] based on ip [{}]", remoteHostName, remoteIp);
try {
connection = createConnection();
final Operation searchOperation = new SearchOperation(connection);
this.searchRequest.getSearchFilter().setParameter(0, remoteHostName);
LOGGER.debug("Using search filter [{}] on baseDn [{}]", this.searchRequest.getSearchFilter().format(), this.searchRequest.getBaseDn());
final Response<SearchResult> searchResult = searchOperation.execute(this.searchRequest);
if (searchResult.getResultCode() == ResultCode.SUCCESS) {
return processSpnegoAttribute(searchResult);
}
throw new IllegalArgumentException("Failed to establish a connection ldap. " + searchResult.getMessage());
} finally {
if (connection != null) {
connection.close();
}
}
}
Aggregations