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());
}
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;
}
Aggregations