Search in sources :

Example 1 with CreateException

use of org.mule.runtime.api.lifecycle.CreateException in project mule by mulesoft.

the class TlsConfigurationTestCase method testExceptionOnInvalidKeyAlias.

@Test
public void testExceptionOnInvalidKeyAlias() throws Exception {
    URL keystoreUrl = getClass().getClassLoader().getResource("serverKeystore");
    File keystoreFile = new File(keystoreUrl.toURI());
    TlsConfiguration config = new TlsConfiguration(keystoreFile.getAbsolutePath());
    config.setKeyStorePassword("mulepassword");
    config.setKeyPassword("mulepassword");
    config.setKeyAlias("this_key_does_not_exist_in_the_keystore");
    try {
        config.initialise(false, JSSE_NAMESPACE);
    } catch (CreateException ce) {
        assertTrue(ce.getCause() instanceof IllegalStateException);
    }
}
Also used : TlsConfiguration(org.mule.runtime.core.privileged.security.tls.TlsConfiguration) File(java.io.File) CreateException(org.mule.runtime.api.lifecycle.CreateException) URL(java.net.URL) Test(org.junit.Test)

Example 2 with CreateException

use of org.mule.runtime.api.lifecycle.CreateException in project mule by mulesoft.

the class TlsConfiguration method createTrustStore.

private KeyStore createTrustStore() throws CreateException {
    trustStorePassword = null == trustStorePassword ? "" : trustStorePassword;
    KeyStore trustStore;
    try {
        trustStore = KeyStore.getInstance(trustStoreType);
        InputStream is = IOUtils.getResourceAsStream(trustStoreName, getClass());
        if (null == is) {
            throw new FileNotFoundException("Failed to load truststore from classpath or local file: " + trustStoreName);
        }
        trustStore.load(is, trustStorePassword.toCharArray());
    } catch (Exception e) {
        throw new CreateException(failedToLoad("TrustStore: " + trustStoreName), e, this);
    }
    return trustStore;
}
Also used : InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) KeyStore(java.security.KeyStore) TlsIndirectKeyStore(org.mule.runtime.core.privileged.security.TlsIndirectKeyStore) TlsDirectKeyStore(org.mule.runtime.core.privileged.security.TlsDirectKeyStore) CreateException(org.mule.runtime.api.lifecycle.CreateException) KeyStoreException(java.security.KeyStoreException) CreateException(org.mule.runtime.api.lifecycle.CreateException) GeneralSecurityException(java.security.GeneralSecurityException) KeyManagementException(java.security.KeyManagementException) FileNotFoundException(java.io.FileNotFoundException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException)

Example 3 with CreateException

use of org.mule.runtime.api.lifecycle.CreateException in project mule by mulesoft.

the class TlsConfiguration method initTrustManagerFactory.

private void initTrustManagerFactory() throws CreateException {
    if (null == trustStoreName && revocationCheck == null) {
        return;
    }
    Boolean revocationEnabled = revocationCheck != null;
    // Revocation checking is only supported for PKIX algorithm
    if (revocationEnabled && !REVOCATION_KEYSTORE_ALGORITHM.equalsIgnoreCase(trustManagerAlgorithm)) {
        String errorText = formatInvalidCrlAlgorithm(getTrustManagerAlgorithm());
        throw new CreateException(createStaticMessage(errorText), this);
    }
    try {
        KeyStore trustStore = trustStoreName != null ? createTrustStore() : null;
        trustManagerFactory = TrustManagerFactory.getInstance(trustManagerAlgorithm);
        if (revocationEnabled) {
            ManagerFactoryParameters tmfParams = revocationCheck.configFor(trustStore, getDefaultCaCerts());
            trustManagerFactory.init(tmfParams);
        } else {
            trustManagerFactory.init(trustStore);
        }
    } catch (Exception e) {
        throw new CreateException(failedToLoad("Trust Manager (" + trustManagerAlgorithm + ")"), e, this);
    }
}
Also used : CreateException(org.mule.runtime.api.lifecycle.CreateException) KeyStore(java.security.KeyStore) TlsIndirectKeyStore(org.mule.runtime.core.privileged.security.TlsIndirectKeyStore) TlsDirectKeyStore(org.mule.runtime.core.privileged.security.TlsDirectKeyStore) ManagerFactoryParameters(javax.net.ssl.ManagerFactoryParameters) KeyStoreException(java.security.KeyStoreException) CreateException(org.mule.runtime.api.lifecycle.CreateException) GeneralSecurityException(java.security.GeneralSecurityException) KeyManagementException(java.security.KeyManagementException) FileNotFoundException(java.io.FileNotFoundException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException)

Example 4 with CreateException

use of org.mule.runtime.api.lifecycle.CreateException in project mule by mulesoft.

the class DefaultSchedulerMessageSource method start.

@Override
public synchronized void start() throws MuleException {
    if (started) {
        return;
    }
    try {
        // The initialization phase if handled by the scheduler
        schedulingJob = withContextClassLoader(muleContext.getExecutionClassLoader(), () -> scheduler.schedule(pollingExecutor, () -> run()));
        this.started = true;
    } catch (Exception ex) {
        this.stop();
        throw new CreateException(failedToScheduleWork(), ex, this);
    }
}
Also used : CreateException(org.mule.runtime.api.lifecycle.CreateException) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) CreateException(org.mule.runtime.api.lifecycle.CreateException) MuleException(org.mule.runtime.api.exception.MuleException) MessagingException(org.mule.runtime.core.internal.exception.MessagingException)

Example 5 with CreateException

use of org.mule.runtime.api.lifecycle.CreateException in project mule by mulesoft.

the class TlsConfiguration method initKeyManagerFactory.

private void initKeyManagerFactory() throws CreateException {
    if (logger.isDebugEnabled()) {
        logger.debug("initialising key manager factory from keystore data");
    }
    KeyStore tempKeyStore;
    try {
        tempKeyStore = loadKeyStore();
        checkKeyStoreContainsAlias(tempKeyStore);
    } catch (Exception e) {
        throw new CreateException(failedToLoad("KeyStore: " + keyStoreName), e, this);
    }
    try {
        keyManagerFactory = KeyManagerFactory.getInstance(getKeyManagerAlgorithm());
        keyManagerFactory.init(tempKeyStore, keyPassword.toCharArray());
    } catch (Exception e) {
        throw new CreateException(failedToLoad("Key Manager"), e, this);
    }
}
Also used : KeyStore(java.security.KeyStore) TlsIndirectKeyStore(org.mule.runtime.core.privileged.security.TlsIndirectKeyStore) TlsDirectKeyStore(org.mule.runtime.core.privileged.security.TlsDirectKeyStore) CreateException(org.mule.runtime.api.lifecycle.CreateException) KeyStoreException(java.security.KeyStoreException) CreateException(org.mule.runtime.api.lifecycle.CreateException) GeneralSecurityException(java.security.GeneralSecurityException) KeyManagementException(java.security.KeyManagementException) FileNotFoundException(java.io.FileNotFoundException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException)

Aggregations

CreateException (org.mule.runtime.api.lifecycle.CreateException)5 FileNotFoundException (java.io.FileNotFoundException)3 IOException (java.io.IOException)3 GeneralSecurityException (java.security.GeneralSecurityException)3 KeyManagementException (java.security.KeyManagementException)3 KeyStore (java.security.KeyStore)3 KeyStoreException (java.security.KeyStoreException)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 TlsDirectKeyStore (org.mule.runtime.core.privileged.security.TlsDirectKeyStore)3 TlsIndirectKeyStore (org.mule.runtime.core.privileged.security.TlsIndirectKeyStore)3 File (java.io.File)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1 ManagerFactoryParameters (javax.net.ssl.ManagerFactoryParameters)1 Test (org.junit.Test)1 MuleException (org.mule.runtime.api.exception.MuleException)1 InitialisationException (org.mule.runtime.api.lifecycle.InitialisationException)1 MessagingException (org.mule.runtime.core.internal.exception.MessagingException)1 TlsConfiguration (org.mule.runtime.core.privileged.security.tls.TlsConfiguration)1