Search in sources :

Example 1 with Operation

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();
        }
    }
}
Also used : SearchOperation(org.ldaptive.SearchOperation) Connection(org.ldaptive.Connection) SearchResult(org.ldaptive.SearchResult) SearchOperation(org.ldaptive.SearchOperation) Operation(org.ldaptive.Operation) LdapException(org.ldaptive.LdapException)

Aggregations

Connection (org.ldaptive.Connection)1 LdapException (org.ldaptive.LdapException)1 Operation (org.ldaptive.Operation)1 SearchOperation (org.ldaptive.SearchOperation)1 SearchResult (org.ldaptive.SearchResult)1