Search in sources :

Example 6 with TimeLimitExceededException

use of javax.naming.TimeLimitExceededException in project ovirt-engine by oVirt.

the class SSHClient method authenticate.

/**
 * Authenticate to host.
 */
public void authenticate() throws Exception {
    log.debug("Authenticating: '{}'", this.getDisplayHost());
    try {
        AuthFuture afuture;
        if (keyPair != null) {
            afuture = session.authPublicKey(user, keyPair);
        } else if (password != null) {
            afuture = session.authPassword(user, password);
        } else {
            throw new AuthenticationException(String.format("SSH authentication failure '%1$s', no password or key", this.getDisplayHost()));
        }
        if (!afuture.await(softTimeout)) {
            throw new TimeLimitExceededException(String.format("SSH authentication timed out connecting to '%1$s'", this.getDisplayHost()));
        }
        if (!afuture.isSuccess()) {
            throw new AuthenticationException(String.format("SSH authentication to '%1$s' failed. Please verify provided credentials. %2$s", this.getDisplayHost(), keyPair == null ? "Make sure host is configured for password authentication" : "Make sure key is authorized at host"));
        }
    } catch (Exception e) {
        log.debug("Connect error", e);
        throw e;
    }
    log.debug("Authenticated: '{}'", this.getDisplayHost());
}
Also used : AuthenticationException(javax.naming.AuthenticationException) TimeLimitExceededException(javax.naming.TimeLimitExceededException) AuthFuture(org.apache.sshd.client.future.AuthFuture) AuthenticationException(javax.naming.AuthenticationException) DecoderException(org.apache.commons.codec.DecoderException) IOException(java.io.IOException) TimeLimitExceededException(javax.naming.TimeLimitExceededException)

Example 7 with TimeLimitExceededException

use of javax.naming.TimeLimitExceededException in project OpenGrok by OpenGrok.

the class LdapFacade method lookup.

/**
 * Lookups the LDAP server for content.
 *
 * @param <T> return type
 * @param dn search base for the query
 * @param filter LDAP filter for the query
 * @param attributes returning LDAP attributes
 * @param mapper mapper class implementing @code{AttributeMapper} closed
 * @param fail current count of failures
 *
 * @return results transformed with mapper or {@code null} on failure
 * @throws LdapException LDAP exception
 */
private <T> LdapSearchResult<T> lookup(String dn, String filter, String[] attributes, AttributeMapper<T> mapper, int fail) throws LdapException {
    if (errorTimestamp > 0 && errorTimestamp + interval > System.currentTimeMillis()) {
        if (!reported) {
            reported = true;
            LOGGER.log(Level.SEVERE, "LDAP server pool is still broken");
        }
        throw new LdapException("LDAP server pool is still broken");
    }
    if (fail > servers.size() - 1) {
        // did the whole rotation
        LOGGER.log(Level.SEVERE, "Tried all LDAP servers in a pool but no server works");
        errorTimestamp = System.currentTimeMillis();
        reported = false;
        WebHook hook;
        if ((hook = webHooks.getFail()) != null) {
            hook.post();
        }
        throw new LdapException("Tried all LDAP servers in a pool but no server works");
    }
    if (!isConfigured()) {
        LOGGER.log(Level.SEVERE, "LDAP is not configured");
        throw new LdapException("LDAP is not configured");
    }
    NamingEnumeration<SearchResult> namingEnum = null;
    LdapServer server = null;
    try {
        server = servers.get(actualServer);
        controls.setReturningAttributes(attributes);
        for (namingEnum = server.search(dn, filter, controls); namingEnum.hasMore(); ) {
            SearchResult sr = namingEnum.next();
            reported = false;
            if (errorTimestamp > 0) {
                errorTimestamp = 0;
                WebHook hook;
                if ((hook = webHooks.getRecover()) != null) {
                    hook.post();
                }
            }
            return new LdapSearchResult<>(sr.getNameInNamespace(), processResult(sr, mapper));
        }
    } catch (NameNotFoundException ex) {
        LOGGER.log(Level.WARNING, String.format("The LDAP name for search '%s' was not found on server %s", getSearchDescription(dn, filter, attributes), server), ex);
        throw new LdapException("The LDAP name was not found.", ex);
    } catch (SizeLimitExceededException ex) {
        LOGGER.log(Level.SEVERE, String.format("The maximum size of the LDAP result has exceeded " + "on server %s", server), ex);
        closeActualServer();
        actualServer = getNextServer();
        return lookup(dn, filter, attributes, mapper, fail + 1);
    } catch (TimeLimitExceededException ex) {
        LOGGER.log(Level.SEVERE, String.format("Time limit for LDAP operation has exceeded on server %s", server), ex);
        closeActualServer();
        actualServer = getNextServer();
        return lookup(dn, filter, attributes, mapper, fail + 1);
    } catch (CommunicationException ex) {
        LOGGER.log(Level.WARNING, String.format("Communication error received on server %s, " + "reconnecting to next server.", server), ex);
        closeActualServer();
        actualServer = getNextServer();
        return lookup(dn, filter, attributes, mapper, fail + 1);
    } catch (NamingException ex) {
        LOGGER.log(Level.SEVERE, String.format("An arbitrary LDAP error occurred on server %s " + "when searching for '%s'", server, getSearchDescription(dn, filter, attributes)), ex);
        closeActualServer();
        actualServer = getNextServer();
        return lookup(dn, filter, attributes, mapper, fail + 1);
    } finally {
        if (namingEnum != null) {
            try {
                namingEnum.close();
            } catch (NamingException e) {
                LOGGER.log(Level.WARNING, "failed to close search result enumeration");
            }
        }
    }
    return null;
}
Also used : SizeLimitExceededException(javax.naming.SizeLimitExceededException) CommunicationException(javax.naming.CommunicationException) NameNotFoundException(javax.naming.NameNotFoundException) WebHook(opengrok.auth.plugin.util.WebHook) SearchResult(javax.naming.directory.SearchResult) NamingException(javax.naming.NamingException) TimeLimitExceededException(javax.naming.TimeLimitExceededException)

Aggregations

TimeLimitExceededException (javax.naming.TimeLimitExceededException)7 IOException (java.io.IOException)5 AuthenticationException (javax.naming.AuthenticationException)3 InputStream (java.io.InputStream)2 CommunicationException (javax.naming.CommunicationException)2 NameNotFoundException (javax.naming.NameNotFoundException)2 NamingException (javax.naming.NamingException)2 DecoderException (org.apache.commons.codec.DecoderException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 OutputStream (java.io.OutputStream)1 KeyStoreException (java.security.KeyStoreException)1 AuthenticationNotSupportedException (javax.naming.AuthenticationNotSupportedException)1 ContextNotEmptyException (javax.naming.ContextNotEmptyException)1 InvalidNameException (javax.naming.InvalidNameException)1 NameAlreadyBoundException (javax.naming.NameAlreadyBoundException)1 NoPermissionException (javax.naming.NoPermissionException)1 OperationNotSupportedException (javax.naming.OperationNotSupportedException)1 ServiceUnavailableException (javax.naming.ServiceUnavailableException)1