Search in sources :

Example 11 with ServiceUnavailableException

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;
    }
}
Also used : CommunicationException(javax.naming.CommunicationException) ServiceUnavailableException(javax.naming.ServiceUnavailableException) Principal(java.security.Principal) URISyntaxException(java.net.URISyntaxException) NamingException(javax.naming.NamingException) AuthenticationException(javax.naming.AuthenticationException) LifecycleException(org.apache.catalina.LifecycleException) KeyManagementException(java.security.KeyManagementException) ServiceUnavailableException(javax.naming.ServiceUnavailableException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) NameNotFoundException(javax.naming.NameNotFoundException) PartialResultException(javax.naming.PartialResultException) IOException(java.io.IOException) InvalidNameException(javax.naming.InvalidNameException) CommunicationException(javax.naming.CommunicationException)

Example 12 with ServiceUnavailableException

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();
}
Also used : AccessDeniedException(org.apache.hadoop.hbase.security.AccessDeniedException) JMXConnector(javax.management.remote.JMXConnector) IOException(java.io.IOException) ServiceUnavailableException(javax.naming.ServiceUnavailableException) Test(org.junit.Test)

Example 13 with ServiceUnavailableException

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;
    }
}
Also used : CommunicationException(javax.naming.CommunicationException) NamingException(javax.naming.NamingException) InitialDirContext(javax.naming.directory.InitialDirContext) DirContext(javax.naming.directory.DirContext) ServiceUnavailableException(javax.naming.ServiceUnavailableException) Principal(java.security.Principal)

Example 14 with ServiceUnavailableException

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);
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) GenericFrameworkException(com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) SQLException(java.sql.SQLException) FileNotFoundException(java.io.FileNotFoundException) SQLSyntaxErrorException(java.sql.SQLSyntaxErrorException) ServiceUnavailableException(javax.naming.ServiceUnavailableException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) AttributeInUseException(javax.naming.directory.AttributeInUseException) NoSuchAttributeException(javax.naming.directory.NoSuchAttributeException) RemoteWrappedException(org.identityconnectors.framework.impl.api.remote.RemoteWrappedException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) FileNotFoundException(java.io.FileNotFoundException) GenericFrameworkException(com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ServiceUnavailableException(javax.naming.ServiceUnavailableException) SystemException(com.evolveum.midpoint.util.exception.SystemException) SchemaViolationException(javax.naming.directory.SchemaViolationException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) NoPermissionException(javax.naming.NoPermissionException) PolicyViolationException(com.evolveum.midpoint.util.exception.PolicyViolationException) SQLSyntaxErrorException(java.sql.SQLSyntaxErrorException) EncryptionException(com.evolveum.midpoint.prism.crypto.EncryptionException) SQLException(java.sql.SQLException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) ConnectException(java.net.ConnectException) NameAlreadyBoundException(javax.naming.NameAlreadyBoundException) NoSuchAttributeException(javax.naming.directory.NoSuchAttributeException) NameAlreadyBoundException(javax.naming.NameAlreadyBoundException) NoPermissionException(javax.naming.NoPermissionException) SchemaViolationException(javax.naming.directory.SchemaViolationException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) ConnectException(java.net.ConnectException) AttributeInUseException(javax.naming.directory.AttributeInUseException)

Example 15 with ServiceUnavailableException

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();
}
Also used : JMXConnector(javax.management.remote.JMXConnector) IOException(java.io.IOException) ServiceUnavailableException(javax.naming.ServiceUnavailableException)

Aggregations

ServiceUnavailableException (javax.naming.ServiceUnavailableException)17 NamingException (javax.naming.NamingException)9 IOException (java.io.IOException)7 URISyntaxException (java.net.URISyntaxException)5 JMXConnector (javax.management.remote.JMXConnector)4 AuthenticationException (javax.naming.AuthenticationException)4 InvalidNameException (javax.naming.InvalidNameException)4 NameNotFoundException (javax.naming.NameNotFoundException)4 File (java.io.File)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 ConnectException (java.net.ConnectException)3 Properties (java.util.Properties)3 CommunicationException (javax.naming.CommunicationException)3 InitialContext (javax.naming.InitialContext)3 OperationNotSupportedException (javax.naming.OperationNotSupportedException)3 CommandLine (org.apache.commons.cli.CommandLine)3 CommandLineParser (org.apache.commons.cli.CommandLineParser)3 Options (org.apache.commons.cli.Options)3 ParseException (org.apache.commons.cli.ParseException)3 PosixParser (org.apache.commons.cli.PosixParser)3