use of org.ldaptive.Connection 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();
}
}
}
use of org.ldaptive.Connection in project cas by apereo.
the class LdapSpnegoKnownClientSystemsFilterAction method createConnection.
/**
* Create and open a connection to ldap
* via the given config and provider.
*
* @return the connection
* @throws LdapException the ldap exception
*/
protected Connection createConnection() throws LdapException {
LOGGER.debug("Establishing a connection...");
final Connection connection = this.connectionFactory.getConnection();
connection.open();
return connection;
}
use of org.ldaptive.Connection in project cas by apereo.
the class LdapUtils method executeAddOperation.
/**
* Execute add operation boolean.
*
* @param connectionFactory the connection factory
* @param entry the entry
* @return true/false
* @throws LdapException the ldap exception
*/
public static boolean executeAddOperation(final ConnectionFactory connectionFactory, final LdapEntry entry) throws LdapException {
try (Connection connection = createConnection(connectionFactory)) {
final AddOperation operation = new AddOperation(connection);
operation.execute(new AddRequest(entry.getDn(), entry.getAttributes()));
return true;
} catch (final LdapException e) {
LOGGER.error(e.getMessage(), e);
}
return false;
}
Aggregations