use of org.apache.camel.util.jsse.KeyStoreParameters in project camel by apache.
the class NettySSLContextParametersTest method createRegistry.
@Override
protected JndiRegistry createRegistry() throws Exception {
KeyStoreParameters ksp = new KeyStoreParameters();
ksp.setResource(this.getClass().getClassLoader().getResource("keystore.jks").toString());
ksp.setPassword("changeit");
KeyManagersParameters kmp = new KeyManagersParameters();
kmp.setKeyPassword("changeit");
kmp.setKeyStore(ksp);
TrustManagersParameters tmp = new TrustManagersParameters();
tmp.setKeyStore(ksp);
// NOTE: Needed since the client uses a loose trust configuration when no ssl context
// is provided. We turn on WANT client-auth to prefer using authentication
SSLContextServerParameters scsp = new SSLContextServerParameters();
scsp.setClientAuthentication(ClientAuthentication.WANT.name());
SSLContextParameters sslContextParameters = new SSLContextParameters();
sslContextParameters.setKeyManagers(kmp);
sslContextParameters.setTrustManagers(tmp);
sslContextParameters.setServerParameters(scsp);
JndiRegistry registry = super.createRegistry();
registry.bind("sslContextParameters", sslContextParameters);
return registry;
}
use of org.apache.camel.util.jsse.KeyStoreParameters in project camel by apache.
the class SalesforceSession method generateJwtAssertion.
String generateJwtAssertion() {
final long utcPlusWindow = Clock.systemUTC().millis() / 1000 + JWT_CLAIM_WINDOW;
final StringBuilder claim = new StringBuilder().append("{\"iss\":\"").append(config.getClientId()).append("\",\"sub\":\"").append(config.getUserName()).append("\",\"aud\":\"").append(config.getLoginUrl()).append("\",\"exp\":\"").append(utcPlusWindow).append("\"}");
final StringBuilder token = new StringBuilder(JWT_HEADER).append('.').append(Base64.getUrlEncoder().encodeToString(claim.toString().getBytes(StandardCharsets.UTF_8)));
final KeyStoreParameters keyStoreParameters = config.getKeystore();
keyStoreParameters.setCamelContext(camelContext);
try {
final KeyStore keystore = keyStoreParameters.createKeyStore();
final Enumeration<String> aliases = keystore.aliases();
String alias = null;
while (aliases.hasMoreElements()) {
String tmp = aliases.nextElement();
if (keystore.isKeyEntry(tmp)) {
if (alias == null) {
alias = tmp;
} else {
throw new IllegalArgumentException("The given keystore `" + keyStoreParameters.getResource() + "` contains more than one key entry, expecting only one");
}
}
}
PrivateKey key = (PrivateKey) keystore.getKey(alias, keyStoreParameters.getPassword().toCharArray());
Signature signature = Signature.getInstance(JWT_SIGNATURE_ALGORITHM);
signature.initSign(key);
signature.update(token.toString().getBytes(StandardCharsets.UTF_8));
byte[] signed = signature.sign();
token.append('.').append(Base64.getUrlEncoder().encodeToString(signed));
} catch (IOException | GeneralSecurityException e) {
throw new IllegalStateException(e);
}
return token.toString();
}
use of org.apache.camel.util.jsse.KeyStoreParameters in project camel by apache.
the class SalesforceJwtBearerTokenFlowIntegrationTest method createCamelContext.
@Override
protected CamelContext createCamelContext() throws Exception {
final CamelContext camelContext = super.createCamelContext();
final SalesforceComponent salesforce = new SalesforceComponent();
final Properties properties = LoginConfigHelper.testLoginProperties();
salesforce.setClientId(properties.getProperty("clientId"));
salesforce.setUserName(properties.getProperty("userName"));
salesforce.setLoginUrl(properties.getProperty("loginUrl"));
KeyStoreParameters keystore = new KeyStoreParameters();
keystore.setResource(properties.getProperty("keystore.resource"));
keystore.setType(properties.getProperty("keystore.type"));
keystore.setPassword(properties.getProperty("keystore.password"));
salesforce.setKeystore(keystore);
camelContext.addComponent("salesforce", salesforce);
return camelContext;
}
use of org.apache.camel.util.jsse.KeyStoreParameters in project camel by apache.
the class FileToFtpsExplicitSSLWithClientAuthAndSSLContextParametersTest method createRegistry.
@Override
protected JndiRegistry createRegistry() throws Exception {
KeyStoreParameters ksp = new KeyStoreParameters();
ksp.setResource("server.jks");
ksp.setPassword("password");
KeyManagersParameters kmp = new KeyManagersParameters();
kmp.setKeyPassword("password");
kmp.setKeyStore(ksp);
TrustManagersParameters tmp = new TrustManagersParameters();
tmp.setKeyStore(ksp);
SSLContextParameters sslContextParameters = new SSLContextParameters();
sslContextParameters.setSecureSocketProtocol("SSL");
sslContextParameters.setKeyManagers(kmp);
sslContextParameters.setTrustManagers(tmp);
JndiRegistry registry = super.createRegistry();
registry.bind("sslContextParameters", sslContextParameters);
return registry;
}
use of org.apache.camel.util.jsse.KeyStoreParameters in project camel by apache.
the class FileToFtpsExplicitTLSWithClientAuthAndSSLContextParametersTest method createRegistry.
@Override
protected JndiRegistry createRegistry() throws Exception {
KeyStoreParameters ksp = new KeyStoreParameters();
ksp.setResource("server.jks");
ksp.setPassword("password");
KeyManagersParameters kmp = new KeyManagersParameters();
kmp.setKeyPassword("password");
kmp.setKeyStore(ksp);
TrustManagersParameters tmp = new TrustManagersParameters();
tmp.setKeyStore(ksp);
SSLContextParameters sslContextParameters = new SSLContextParameters();
sslContextParameters.setSecureSocketProtocol("TLS");
sslContextParameters.setKeyManagers(kmp);
sslContextParameters.setTrustManagers(tmp);
JndiRegistry registry = super.createRegistry();
registry.bind("sslContextParameters", sslContextParameters);
return registry;
}
Aggregations