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