use of org.ldaptive.Operation 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
*/
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 RuntimeException("Failed to establish a connection ldap. " + searchResult.getMessage());
} catch (final LdapException e) {
LOGGER.error(e.getMessage(), e);
throw Throwables.propagate(e);
} finally {
if (connection != null) {
connection.close();
}
}
}
Aggregations