Return-Path: X-Original-To: apmail-camel-issues-archive@minotaur.apache.org Delivered-To: apmail-camel-issues-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id E560610F0E for ; Fri, 23 Jan 2015 11:50:34 +0000 (UTC) Received: (qmail 87685 invoked by uid 500); 23 Jan 2015 11:50:35 -0000 Delivered-To: apmail-camel-issues-archive@camel.apache.org Received: (qmail 87643 invoked by uid 500); 23 Jan 2015 11:50:35 -0000 Mailing-List: contact issues-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list issues@camel.apache.org Received: (qmail 87535 invoked by uid 99); 23 Jan 2015 11:50:34 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 23 Jan 2015 11:50:34 +0000 Date: Fri, 23 Jan 2015 11:50:34 +0000 (UTC) From: "Julian Cable (JIRA)" To: issues@camel.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Issue Comment Deleted] (CAMEL-8272) Camel-box socks proxy implementation is incomplete MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/CAMEL-8272?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Julian Cable updated CAMEL-8272: -------------------------------- Comment: was deleted (was: {quote} Index: src/main/java/org/apache/camel/component/box/internal/BoxClientHelper.java =================================================================== --- src/main/java/org/apache/camel/component/box/internal/BoxClientHelper.java (revision 1598081) +++ src/main/java/org/apache/camel/component/box/internal/BoxClientHelper.java (working copy) @@ -36,12 +36,19 @@ import org.apache.camel.component.box.BoxConfiguration; import org.apache.camel.util.ObjectHelper; import org.apache.camel.util.jsse.SSLContextParameters; +import org.apache.http.HttpHost; import org.apache.http.client.HttpClient; import org.apache.http.conn.ClientConnectionManager; import org.apache.http.conn.scheme.Scheme; import org.apache.http.conn.scheme.SchemeRegistry; import org.apache.http.conn.ssl.SSLSocketFactory; +import org.apache.http.conn.params.ConnRoutePNames; import org.apache.http.params.HttpParams; +import org.apache.http.protocol.HttpContext; +import java.net.InetSocketAddress; +import java.net.Socket; +import java.net.Proxy; +import javax.net.ssl.SSLContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -66,7 +73,7 @@ final String userPassword = configuration.getUserPassword(); if ((authSecureStorage == null && ObjectHelper.isEmpty(userPassword)) - || ObjectHelper.isEmpty(userName) || ObjectHelper.isEmpty(clientId) || ObjectHelper.isEmpty(clientSecret)) { + || ObjectHelper.isEmpty(userName) || ObjectHelper.isEmpty(clientId) || ObjectHelper.isEmpty(clientSecret)) { throw new IllegalArgumentException( "Missing one or more required properties " + "clientId, clientSecret, userName and either authSecureStorage or userPassword"); @@ -76,13 +83,13 @@ // if set, use configured connection manager builder final BoxConnectionManagerBuilder connectionManagerBuilder = configuration.getConnectionManagerBuilder(); final BoxConnectionManagerBuilder connectionManager = connectionManagerBuilder != null - ? connectionManagerBuilder : new BoxConnectionManagerBuilder(); + ? connectionManagerBuilder : new BoxConnectionManagerBuilder(); // create REST client for BoxClient final ClientConnectionManager[] clientConnectionManager = new ClientConnectionManager[1]; final IBoxRESTClient restClient = new BoxRESTClient(connectionManager.build()) { - @SuppressWarnings("deprecation") - @Override + @SuppressWarnings("deprecation") + @Override public HttpClient getRawHttpClient() { final HttpClient httpClient = super.getRawHttpClient(); clientConnectionManager[0] = httpClient.getConnectionManager(); @@ -91,33 +98,48 @@ if (sslContextParameters == null) { sslContextParameters = new SSLContextParameters(); } - try { - final SSLSocketFactory socketFactory = new SSLSocketFactory( - sslContextParameters.createSSLContext(), - SSLSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER); - schemeRegistry.register(new Scheme("https", socketFactory, 443)); - } catch (GeneralSecurityException e) { - throw ObjectHelper.wrapRuntimeCamelException(e); - } catch (IOException e) { - throw ObjectHelper.wrapRuntimeCamelException(e); - } - - // set custom HTTP params final Map configParams = configuration.getHttpParams(); + boolean useSocksProxy = false; + HttpHost proxyHost = null; if (configParams != null && !configParams.isEmpty()) { + final Boolean socksProxy = (Boolean) configParams.get("http.route.socks-proxy"); + if(socksProxy!=null && socksProxy) { + useSocksProxy = true; + proxyHost = (HttpHost) configParams.get(ConnRoutePNames.DEFAULT_PROXY); + } + // set custom HTTP params LOG.debug("Setting {} HTTP Params", configParams.size()); final HttpParams httpParams = httpClient.getParams(); for (Map.Entry param : configParams.entrySet()) { - httpParams.setParameter(param.getKey(), param.getValue()); + // don't add proxy params if socks + if(!(useSocksProxy && (param.getKey().equals("http.route.socks-proxy") || param.getKey().equals(ConnRoutePNames.DEFAULT_PROXY)))) { + httpParams.setParameter(param.getKey(), param.getValue()); + } } + } + SSLContext sslContext = null; + try { + sslContext = sslContextParameters.createSSLContext(); + } catch (IOException e) { + throw ObjectHelper.wrapRuntimeCamelException(e); + } catch (GeneralSecurityException e) { + throw ObjectHelper.wrapRuntimeCamelException(e); + } + final SSLSocketFactory socketFactory = useSocksProxy? + new SocksSSLSocketFactory(sslContext, proxyHost) + : + new SSLSocketFactory( + sslContext, + SSLSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER); + schemeRegistry.register(new Scheme("https", socketFactory, 443)); return httpClient; } }; final BoxClient boxClient = new BoxClient(clientId, clientSecret, null, null, - restClient, configuration.getBoxConfig()); + restClient, configuration.getBoxConfig()); // enable OAuth auto-refresh boxClient.setAutoRefreshOAuth(true); @@ -135,7 +157,7 @@ } public static void getOAuthToken(BoxConfiguration configuration, CachedBoxClient cachedBoxClient) - throws AuthFatalFailureException, BoxRestException, BoxServerException, InterruptedException { + throws AuthFatalFailureException, BoxRestException, BoxServerException, InterruptedException { final BoxClient boxClient = cachedBoxClient.getBoxClient(); synchronized (boxClient) { @@ -169,7 +191,7 @@ final Exception ex = listener.getException(); if (ex != null) { throw new RuntimeCamelException(String.format("Login error for %s: %s", - cachedBoxClient, ex.getMessage()), ex); + cachedBoxClient, ex.getMessage()), ex); } } @@ -188,7 +210,7 @@ } public static void shutdownBoxClient(BoxConfiguration configuration, CachedBoxClient cachedBoxClient) - throws BoxServerException, BoxRestException, AuthFatalFailureException { + throws BoxServerException, BoxRestException, AuthFatalFailureException { final BoxClient boxClient = cachedBoxClient.getBoxClient(); synchronized (boxClient) { @@ -217,7 +239,7 @@ } private static void revokeOAuthToken(BoxConfiguration configuration, CachedBoxClient cachedBoxClient) - throws BoxServerException, BoxRestException, AuthFatalFailureException { + throws BoxServerException, BoxRestException, AuthFatalFailureException { final BoxClient boxClient = cachedBoxClient.getBoxClient(); synchronized (boxClient) { @@ -228,7 +250,7 @@ // revoke OAuth token boxClient.getOAuthManager().revokeOAuth(boxClient.getAuthData().getAccessToken(), - configuration.getClientId(), configuration.getClientSecret()); + configuration.getClientId(), configuration.getClientSecret()); // notify the OAuthListener of revoked token cachedBoxClient.getListener().onRefresh(null); @@ -237,4 +259,20 @@ } } } + static class SocksSSLSocketFactory extends SSLSocketFactory { + HttpHost proxyHost; + + public SocksSSLSocketFactory(SSLContext sslContext, HttpHost proxyHost) { + super(sslContext, SSLSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER); + this.proxyHost = proxyHost; + } + + @Override + public Socket createSocket(final HttpContext context) throws IOException { + InetSocketAddress socksaddr = new InetSocketAddress(proxyHost.getHostName(), proxyHost.getPort()); + Proxy proxy = new Proxy(Proxy.Type.SOCKS, socksaddr); + return new Socket(proxy); + } + + } } {quote} ) > Camel-box socks proxy implementation is incomplete > -------------------------------------------------- > > Key: CAMEL-8272 > URL: https://issues.apache.org/jira/browse/CAMEL-8272 > Project: Camel > Issue Type: Bug > Affects Versions: 2.14.1 > Environment: any > Reporter: Julian Cable > > org.apache.camel.component.box.internal.LoginAuthFlowUI looks for http.route.socks-proxy and sets up a socks proxy for the webClient > org.apache.camel.component.box.internal.BoxClientHelper just passes the httpParams on to the underlying HttpClient but the box api uses a vanilla DefaultHttpClient which doesn't talk SOCKS. > The attached patch adds socks proxy support to the main restful box transactions. -- This message was sent by Atlassian JIRA (v6.3.4#6332)