use of org.apache.camel.util.jsse.SSLContextParameters 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.SSLContextParameters in project camel by apache.
the class RestletComponent method addServerIfNecessary.
protected void addServerIfNecessary(RestletEndpoint endpoint) throws Exception {
String key = buildKey(endpoint);
Server server;
synchronized (servers) {
server = servers.get(key);
if (server == null) {
server = createServer(endpoint);
component.getServers().add(server);
// Add any Restlet server parameters that were included
Series<Parameter> params = server.getContext().getParameters();
if ("https".equals(endpoint.getProtocol())) {
SSLContextParameters scp = endpoint.getSslContextParameters();
if (endpoint.getSslContextParameters() == null) {
throw new InvalidParameterException("Need to specify the SSLContextParameters option here!");
}
setupServerWithSSLContext(params, scp);
}
if (getControllerDaemon() != null) {
params.add("controllerDaemon", getControllerDaemon().toString());
}
if (getControllerSleepTimeMs() != null) {
params.add("controllerSleepTimeMs", getControllerSleepTimeMs().toString());
}
if (getInboundBufferSize() != null) {
params.add("inboundBufferSize", getInboundBufferSize().toString());
}
if (getMinThreads() != null) {
params.add("minThreads", getMinThreads().toString());
}
if (getMaxThreads() != null) {
params.add("maxThreads", getMaxThreads().toString());
}
if (getLowThreads() != null) {
params.add("lowThreads", getLowThreads().toString());
}
if (getMaxQueued() != null) {
params.add("maxQueued", getMaxQueued().toString());
}
if (getMaxConnectionsPerHost() != null) {
params.add("maxConnectionsPerHost", getMaxConnectionsPerHost().toString());
}
if (getMaxTotalConnections() != null) {
params.add("maxTotalConnections", getMaxTotalConnections().toString());
}
if (getOutboundBufferSize() != null) {
params.add("outboundBufferSize", getOutboundBufferSize().toString());
}
if (getPersistingConnections() != null) {
params.add("persistingConnections", getPersistingConnections().toString());
}
if (getPipeliningConnections() != null) {
params.add("pipeliningConnections", getPipeliningConnections().toString());
}
if (getThreadMaxIdleTimeMs() != null) {
params.add("threadMaxIdleTimeMs", getThreadMaxIdleTimeMs().toString());
}
if (getUseForwardedForHeader() != null) {
params.add("useForwardedForHeader", getUseForwardedForHeader().toString());
}
if (getReuseAddress() != null) {
params.add("reuseAddress", getReuseAddress().toString());
}
LOG.debug("Setting parameters: {} to server: {}", params, server);
server.getContext().setParameters(params);
servers.put(key, server);
LOG.debug("Added server: {}", key);
server.start();
}
}
}
use of org.apache.camel.util.jsse.SSLContextParameters in project camel by apache.
the class SalesforceComponent method doStart.
@Override
protected void doStart() throws Exception {
if (loginConfig == null) {
if (ObjectHelper.isNotEmpty(password)) {
loginConfig = new SalesforceLoginConfig(loginUrl, clientId, clientSecret, userName, password, lazyLogin);
} else if (ObjectHelper.isNotEmpty(refreshToken)) {
loginConfig = new SalesforceLoginConfig(loginUrl, clientId, clientSecret, refreshToken, lazyLogin);
} else if (ObjectHelper.isNotEmpty(keystore)) {
loginConfig = new SalesforceLoginConfig(loginUrl, clientId, userName, keystore, lazyLogin);
} else {
throw new IllegalArgumentException("Cannot define a login configuration, the component configuration" + " does not contain `password`, `refreshToken` or `keystore` parameters. Specifying one of those" + " determines the type of authentication performed.");
}
LOG.debug("Created login configuration: {}", loginConfig);
} else {
LOG.debug("Using shared login configuration: {}", loginConfig);
}
// create a Jetty HttpClient if not already set
if (null == httpClient) {
if (config != null && config.getHttpClient() != null) {
httpClient = config.getHttpClient();
} else {
// set ssl context parameters if set
final SSLContextParameters contextParameters = sslContextParameters != null ? sslContextParameters : new SSLContextParameters();
final SslContextFactory sslContextFactory = new SslContextFactory();
sslContextFactory.setSslContext(contextParameters.createSSLContext(getCamelContext()));
httpClient = new SalesforceHttpClient(sslContextFactory);
// default settings, use httpClientProperties to set other properties
httpClient.setConnectTimeout(CONNECTION_TIMEOUT);
}
}
// set HTTP client parameters
if (httpClientProperties != null && !httpClientProperties.isEmpty()) {
IntrospectionSupport.setProperties(getCamelContext().getTypeConverter(), httpClient, new HashMap<String, Object>(httpClientProperties));
}
// set HTTP proxy settings
if (this.httpProxyHost != null && httpProxyPort != null) {
Origin.Address proxyAddress = new Origin.Address(this.httpProxyHost, this.httpProxyPort);
ProxyConfiguration.Proxy proxy;
if (isHttpProxySocks4) {
proxy = new Socks4Proxy(proxyAddress, isHttpProxySecure);
} else {
proxy = new HttpProxy(proxyAddress, isHttpProxySecure);
}
if (httpProxyIncludedAddresses != null && !httpProxyIncludedAddresses.isEmpty()) {
proxy.getIncludedAddresses().addAll(httpProxyIncludedAddresses);
}
if (httpProxyExcludedAddresses != null && !httpProxyExcludedAddresses.isEmpty()) {
proxy.getExcludedAddresses().addAll(httpProxyExcludedAddresses);
}
httpClient.getProxyConfiguration().getProxies().add(proxy);
}
if (this.httpProxyUsername != null && httpProxyPassword != null) {
ObjectHelper.notEmpty(httpProxyAuthUri, "httpProxyAuthUri");
ObjectHelper.notEmpty(httpProxyRealm, "httpProxyRealm");
final Authentication authentication;
if (httpProxyUseDigestAuth) {
authentication = new DigestAuthentication(new URI(httpProxyAuthUri), httpProxyRealm, httpProxyUsername, httpProxyPassword);
} else {
authentication = new BasicAuthentication(new URI(httpProxyAuthUri), httpProxyRealm, httpProxyUsername, httpProxyPassword);
}
httpClient.getAuthenticationStore().addAuthentication(authentication);
}
// support restarts
if (this.session == null) {
this.session = new SalesforceSession(getCamelContext(), httpClient, httpClient.getTimeout(), loginConfig);
}
// set session before calling start()
httpClient.setSession(this.session);
// start the Jetty client to initialize thread pool, etc.
httpClient.start();
// login at startup if lazyLogin is disabled
if (!loginConfig.isLazyLogin()) {
ServiceHelper.startService(session);
}
if (packages != null && packages.length > 0) {
// parse the packages to create SObject name to class map
classMap = parsePackages();
LOG.info("Found {} generated classes in packages: {}", classMap.size(), Arrays.asList(packages));
} else {
// use an empty map to avoid NPEs later
LOG.warn("Missing property packages, getSObject* operations will NOT work");
classMap = new HashMap<String, Class<?>>(0);
}
if (subscriptionHelper != null) {
ServiceHelper.startService(subscriptionHelper);
}
}
use of org.apache.camel.util.jsse.SSLContextParameters in project camel by apache.
the class RestApiIntegrationTest method testRetry.
@Test
public void testRetry() throws Exception {
final SalesforceComponent sf = context().getComponent("salesforce", SalesforceComponent.class);
final String accessToken = sf.getSession().getAccessToken();
final SslContextFactory sslContextFactory = new SslContextFactory();
sslContextFactory.setSslContext(new SSLContextParameters().createSSLContext(context));
final HttpClient httpClient = new HttpClient(sslContextFactory);
httpClient.setConnectTimeout(60000);
httpClient.start();
final String uri = sf.getLoginConfig().getLoginUrl() + "/services/oauth2/revoke?token=" + accessToken;
final Request logoutGet = httpClient.newRequest(uri).method(HttpMethod.GET).timeout(1, TimeUnit.MINUTES);
final ContentResponse response = logoutGet.send();
assertEquals(HttpStatus.OK_200, response.getStatus());
testGetGlobalObjects();
}
use of org.apache.camel.util.jsse.SSLContextParameters in project camel by apache.
the class RestApiIntegrationTest method testRetryFailure.
@Test
public void testRetryFailure() throws Exception {
final SalesforceComponent sf = context().getComponent("salesforce", SalesforceComponent.class);
final String accessToken = sf.getSession().getAccessToken();
final SslContextFactory sslContextFactory = new SslContextFactory();
sslContextFactory.setSslContext(new SSLContextParameters().createSSLContext(context));
final HttpClient httpClient = new HttpClient(sslContextFactory);
httpClient.setConnectTimeout(60000);
httpClient.start();
final String uri = sf.getLoginConfig().getLoginUrl() + "/services/oauth2/revoke?token=" + accessToken;
final Request logoutGet = httpClient.newRequest(uri).method(HttpMethod.GET).timeout(1, TimeUnit.MINUTES);
final ContentResponse response = logoutGet.send();
assertEquals(HttpStatus.OK_200, response.getStatus());
// set component config to bad password to cause relogin attempts to fail
final String password = sf.getLoginConfig().getPassword();
sf.getLoginConfig().setPassword("bad_password");
try {
testGetGlobalObjects();
fail("Expected CamelExecutionException!");
} catch (final CamelExecutionException e) {
if (e.getCause() instanceof SalesforceException) {
final SalesforceException cause = (SalesforceException) e.getCause();
assertEquals("Expected 400 on authentication retry failure", HttpStatus.BAD_REQUEST_400, cause.getStatusCode());
} else {
fail("Expected SalesforceException!");
}
} finally {
// reset password and retries to allow other tests to pass
sf.getLoginConfig().setPassword(password);
}
}
Aggregations