use of javax.naming.ServiceUnavailableException in project tomcat by apache.
the class JNDIRealm method getPrincipal.
protected Principal getPrincipal(String username, GSSCredential gssCredential) {
JNDIConnection connection = null;
Principal principal = null;
try {
// Ensure that we have a directory context available
connection = get();
// time before giving up.
try {
// Authenticate the specified username if possible
principal = getPrincipal(connection, username, gssCredential);
} catch (CommunicationException | ServiceUnavailableException e) {
// log the exception so we know it's there.
containerLog.info(sm.getString("jndiRealm.exception.retry"), e);
// close the connection so we know it will be reopened.
close(connection);
closePooledConnections();
// open a new directory context.
connection = get();
// Try the authentication again.
principal = getPrincipal(connection, username, gssCredential);
}
// Release this context
release(connection);
// Return the authenticated Principal (if any)
return principal;
} catch (Exception e) {
// Log the problem for posterity
containerLog.error(sm.getString("jndiRealm.exception"), e);
// close the connection so we know it will be reopened.
close(connection);
closePooledConnections();
// Return "not authenticated" for this request
return null;
}
}
use of javax.naming.ServiceUnavailableException in project hbase by apache.
the class TestJMXConnectorServer method testHMConnectorServerWhenStopMaster.
/**
* This tests to validate the HMaster's ConnectorServer after unauthorised stopMaster call.
*/
@Test(timeout = 180000)
public void testHMConnectorServerWhenStopMaster() throws Exception {
conf.set(CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY, JMXListener.class.getName() + "," + MyAccessController.class.getName());
conf.setInt("master.rmi.registry.port", rmiRegistryPort);
UTIL.startMiniCluster();
admin = UTIL.getConnection().getAdmin();
// try to stop master
boolean accessDenied = false;
try {
hasAccess = false;
LOG.info("Stopping HMaster...");
admin.stopMaster();
} catch (AccessDeniedException e) {
LOG.info("Exception occured while stopping HMaster. ", e);
accessDenied = true;
}
Assert.assertTrue(accessDenied);
// Check whether HMaster JMX Connector server can be connected
JMXConnector connector = null;
try {
connector = JMXConnectorFactory.connect(JMXListener.buildJMXServiceURL(rmiRegistryPort, rmiRegistryPort));
} catch (IOException e) {
if (e.getCause() instanceof ServiceUnavailableException) {
Assert.fail("Can't connect to HMaster ConnectorServer.");
}
}
Assert.assertNotNull("JMXConnector should not be null.", connector);
connector.close();
}
use of javax.naming.ServiceUnavailableException in project tomcat70 by apache.
the class JNDIRealm method getPrincipal.
@Override
protected Principal getPrincipal(String username, GSSCredential gssCredential) {
DirContext context = null;
Principal principal = null;
try {
// Ensure that we have a directory context available
context = open();
// time before giving up.
try {
// Authenticate the specified username if possible
principal = getPrincipal(context, username, gssCredential);
} catch (CommunicationException e) {
// log the exception so we know it's there.
containerLog.info(sm.getString("jndiRealm.exception.retry"), e);
// close the connection so we know it will be reopened.
if (context != null)
close(context);
// open a new directory context.
context = open();
// Try the authentication again.
principal = getPrincipal(context, username, gssCredential);
} catch (ServiceUnavailableException e) {
// log the exception so we know it's there.
containerLog.info(sm.getString("jndiRealm.exception.retry"), e);
// close the connection so we know it will be reopened.
if (context != null)
close(context);
// open a new directory context.
context = open();
// Try the authentication again.
principal = getPrincipal(context, username, gssCredential);
}
// Release this context
release(context);
// Return the authenticated Principal (if any)
return principal;
} catch (NamingException e) {
// Log the problem for posterity
containerLog.error(sm.getString("jndiRealm.exception"), e);
// Close the connection so that it gets reopened next time
if (context != null)
close(context);
// Return "not authenticated" for this request
return null;
}
}
use of javax.naming.ServiceUnavailableException in project midpoint by Evolveum.
the class ConnIdUtil method lookForKnownCause.
private static Exception lookForKnownCause(Throwable ex, OperationResult parentResult) {
if (ex.getClass().getPackage().equals(SchemaException.class.getPackage())) {
// Common midPoint exceptions, pass through
// Those may get here from the inner calls of handle() methods from the connector.
parentResult.recordFatalError(ex.getMessage(), ex);
return (Exception) ex;
}
if (ex instanceof FileNotFoundException) {
// fix MID-2711 consider FileNotFoundException as CommunicationException
Exception newEx = new com.evolveum.midpoint.util.exception.CommunicationException(createMessageFromAllExceptions(null, ex));
parentResult.recordFatalError("File not found: " + ex.getMessage(), newEx);
return newEx;
} else if (ex instanceof NameAlreadyBoundException) {
// This is thrown by LDAP connector and may be also throw by similar
// connectors
Exception newEx = new ObjectAlreadyExistsException(createMessageFromAllExceptions(null, ex));
parentResult.recordFatalError("Object already exists: " + ex.getMessage(), newEx);
return newEx;
} else if (ex instanceof javax.naming.CommunicationException) {
// This is thrown by LDAP connector and may be also throw by similar
// connectors
Exception newEx = new CommunicationException(createMessageFromAllExceptions("Communication error", ex));
parentResult.recordFatalError("Communication error: " + ex.getMessage(), newEx);
return newEx;
} else if (ex instanceof ServiceUnavailableException) {
// In some cases (e.g. JDK 1.6.0_31) this is thrown by LDAP connector and may be also throw by similar
// connectors
Exception newEx = new CommunicationException(createMessageFromAllExceptions("Communication error", ex));
parentResult.recordFatalError("Communication error: " + ex.getMessage(), newEx);
return newEx;
} else if (ex instanceof SchemaViolationException) {
// This is thrown by LDAP connector and may be also throw by similar
// connectors
Exception newEx = new SchemaException(createMessageFromAllExceptions("Schema violation", ex));
parentResult.recordFatalError("Schema violation: " + ex.getMessage(), newEx);
return newEx;
} else if (ex instanceof javax.naming.directory.InvalidAttributeValueException) {
// This is thrown by LDAP connector and may be also throw by similar
// connectors
javax.naming.directory.InvalidAttributeValueException e = (javax.naming.directory.InvalidAttributeValueException) ex;
Exception newEx;
if (e.getExplanation().contains("unique attribute conflict")) {
newEx = new ObjectAlreadyExistsException(createMessageFromAllExceptions("Invalid attribute", ex));
} else {
newEx = new SchemaException(createMessageFromAllExceptions("Invalid attribute", ex));
}
parentResult.recordFatalError("Invalid attribute: " + ex.getMessage(), newEx);
return newEx;
} else if (ex instanceof ConnectException) {
// Buried deep in many exceptions, usually connection refused or
// similar errors
// Note: needs to be after javax.naming.CommunicationException as the
// javax.naming exception has more info (e.g. hostname)
Exception newEx = new CommunicationException(createMessageFromAllExceptions("Connect error", ex));
parentResult.recordFatalError("Connect error: " + ex.getMessage(), newEx);
return newEx;
} else if (ex instanceof SQLSyntaxErrorException) {
// Buried deep in many exceptions, usually DB schema problems of
// DB-based connectors
Exception newEx = new SchemaException(createMessageFromAllExceptions("DB syntax error", ex));
parentResult.recordFatalError("DB syntax error: " + ex.getMessage(), newEx);
return newEx;
} else if (ex instanceof SQLException) {
// Buried deep in many exceptions, usually DB connection problems
Exception newEx = new GenericFrameworkException(createMessageFromAllExceptions("DB error", ex));
parentResult.recordFatalError("DB error: " + ex.getMessage(), newEx);
return newEx;
} else if (ex instanceof NoPermissionException) {
Exception newEx = new SecurityViolationException(createMessageFromAllExceptions(null, ex));
parentResult.recordFatalError("Object not found: " + ex.getMessage(), newEx);
return newEx;
} else if (ex instanceof AttributeInUseException) {
Exception newEx = new SchemaException(createMessageFromAllExceptions(null, ex));
parentResult.recordFatalError("Attribute in use: " + ex.getMessage(), newEx);
return newEx;
} else if (ex instanceof NoSuchAttributeException) {
Exception newEx = new SchemaException(createMessageFromAllExceptions(null, ex));
parentResult.recordFatalError("No such attribute: " + ex.getMessage(), newEx);
return newEx;
} else if (ex instanceof ConnectorException && !ex.getClass().equals(ConnectorException.class)) {
// we have non generic connector exception
Exception newEx = processConnectorException((ConnectorException) ex, parentResult);
if (newEx != null) {
return newEx;
}
}
if (ex.getCause() == null) {
// found nothing
return null;
} else {
// Otherwise go one level deeper ...
return lookForKnownCause(ex.getCause(), parentResult);
}
}
use of javax.naming.ServiceUnavailableException in project hbase by apache.
the class TestJMXConnectorServer method checkConnector.
private void checkConnector() throws Exception {
// Check whether HMaster JMX Connector server can be connected
JMXConnector connector = null;
try {
connector = JMXConnectorFactory.connect(JMXListener.buildJMXServiceURL(rmiRegistryPort, rmiRegistryPort));
} catch (IOException e) {
if (e.getCause() instanceof ServiceUnavailableException) {
Assert.fail("Can't connect to ConnectorServer.");
}
}
Assert.assertNotNull("JMXConnector should not be null.", connector);
connector.close();
}
Aggregations