Return-Path: X-Original-To: apmail-cxf-commits-archive@www.apache.org Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 3E05ED189 for ; Mon, 6 Aug 2012 20:37:34 +0000 (UTC) Received: (qmail 9681 invoked by uid 500); 6 Aug 2012 20:37:34 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 9634 invoked by uid 500); 6 Aug 2012 20:37:34 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 9627 invoked by uid 99); 6 Aug 2012 20:37:34 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 06 Aug 2012 20:37:34 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,T_FILL_THIS_FORM_SHORT X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 06 Aug 2012 20:37:30 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 9784623889E7; Mon, 6 Aug 2012 20:36:45 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1369991 - in /cxf/trunk/distribution/src/main/release/samples/jax_rs/basic_https: README.txt pom.xml src/main/config/KeyREADME.txt src/main/java/httpsdemo/client/Client.java src/main/java/org/apache/commons/httpclient/contrib/ssl/ Date: Mon, 06 Aug 2012 20:36:45 -0000 To: commits@cxf.apache.org From: gmazza@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120806203645.9784623889E7@eris.apache.org> Author: gmazza Date: Mon Aug 6 20:36:44 2012 New Revision: 1369991 URL: http://svn.apache.org/viewvc?rev=1369991&view=rev Log: Upgraded from Commons HTTP Client to Apache HttpComponents' HTTPClient. Removed: cxf/trunk/distribution/src/main/release/samples/jax_rs/basic_https/src/main/java/org/apache/commons/httpclient/contrib/ssl/ Modified: cxf/trunk/distribution/src/main/release/samples/jax_rs/basic_https/README.txt cxf/trunk/distribution/src/main/release/samples/jax_rs/basic_https/pom.xml cxf/trunk/distribution/src/main/release/samples/jax_rs/basic_https/src/main/config/KeyREADME.txt cxf/trunk/distribution/src/main/release/samples/jax_rs/basic_https/src/main/java/httpsdemo/client/Client.java Modified: cxf/trunk/distribution/src/main/release/samples/jax_rs/basic_https/README.txt URL: http://svn.apache.org/viewvc/cxf/trunk/distribution/src/main/release/samples/jax_rs/basic_https/README.txt?rev=1369991&r1=1369990&r2=1369991&view=diff ============================================================================== --- cxf/trunk/distribution/src/main/release/samples/jax_rs/basic_https/README.txt (original) +++ cxf/trunk/distribution/src/main/release/samples/jax_rs/basic_https/README.txt Mon Aug 6 20:36:44 2012 @@ -9,40 +9,36 @@ requires client authentication so the cl credentials. The listener configuration is taken from the "ServerConfig.xml" file located under demo directory. -The client is configured to provide its certificate "CN=Wibble" and -chain stored in the Java KeyStore "certs/clientKeystore.jks" to the server. -The server authenticates the client's certificate using the truststore -"certs/commonstore.jks", which holds the Certificate Authorities' -certificates. - -Likewise the client authenticates the server's certificate "CN=Cherry" -and chain against the same trust store. Note also the usage of the -cipherSuitesFilter configuration in the configuration files, -where each party imposes different ciphersuites constraints, so that the -ciphersuite eventually negotiated during the TLS handshake is acceptable -to both sides. This may be viewed by adding a -Djavax.net.debug=all -argument to the JVM. +The client is configured to provide its certificate +from its keystore "config/clientKeystore.jks" to the server. +The server authenticates the client's certificate using its own +keystore "config/serviceKeystore.jks", which contains the +public cert of the client. The client makes HTTPS calls using +three methods: the portable Apache HttpComponents' HttpClient object, +CXF's WebClient object, and CXF's JAXRSClientFactory object. + +Likewise the client authenticates the server's certificate "CN=localhost" +using its keystore. Note also the usage of the cipherSuitesFilter +configuration in the configuration files, where each party imposes +different ciphersuites constraints, so that the ciphersuite eventually +negotiated during the TLS handshake is acceptable to both sides. +This may be viewed by adding a -Djavax.net.debug=all argument to the JVM. -But please note that it is not adviseable to store sensitive data such +But please note that it is not advisable to store sensitive data such as passwords stored in a clear text configuration file, unless the file is sufficiently protected by OS level permissions. The KeyStores may be configured programmatically so using user interaction may be employed to keep passwords from being stored in configuration files. The approach taken here is for demonstration reasons only. -NOTE: Classes AuthSSLInitializationError, AuthSSLProtocolSocketFactory, -and AuthSSLX509TrustManager are files copied from the Apache HTTP Client -project and used by the client for certificate validation. - Please review the README in the samples directory before continuing. -Building and running the demo using maven ---------------------------------------- - +Building and running the demo using Maven +----------------------------------------- From the base directory of this sample (i.e., where this README file is -located), the maven pom.xml file can be used to build and run the demo. +located), the Maven pom.xml file can be used to build and run the demo. Using either UNIX or Windows: @@ -58,4 +54,3 @@ Certificates ------------ See the src/main/config folder for the sample keys used (don't use these keys in production!) as well as scripts used for their creation. - Modified: cxf/trunk/distribution/src/main/release/samples/jax_rs/basic_https/pom.xml URL: http://svn.apache.org/viewvc/cxf/trunk/distribution/src/main/release/samples/jax_rs/basic_https/pom.xml?rev=1369991&r1=1369990&r2=1369991&view=diff ============================================================================== --- cxf/trunk/distribution/src/main/release/samples/jax_rs/basic_https/pom.xml (original) +++ cxf/trunk/distribution/src/main/release/samples/jax_rs/basic_https/pom.xml Mon Aug 6 20:36:44 2012 @@ -30,9 +30,10 @@ 2.7.0-SNAPSHOT ../.. + ${project.version} - 3.1 + 4.2.1 @@ -106,14 +107,13 @@ 2.7.0-SNAPSHOT - commons-httpclient - commons-httpclient + org.apache.httpcomponents + httpclient ${httpclient.version} org.springframework spring-context - Modified: cxf/trunk/distribution/src/main/release/samples/jax_rs/basic_https/src/main/config/KeyREADME.txt URL: http://svn.apache.org/viewvc/cxf/trunk/distribution/src/main/release/samples/jax_rs/basic_https/src/main/config/KeyREADME.txt?rev=1369991&r1=1369990&r2=1369991&view=diff ============================================================================== --- cxf/trunk/distribution/src/main/release/samples/jax_rs/basic_https/src/main/config/KeyREADME.txt (original) +++ cxf/trunk/distribution/src/main/release/samples/jax_rs/basic_https/src/main/config/KeyREADME.txt Mon Aug 6 20:36:44 2012 @@ -17,4 +17,3 @@ keytool -import -noprompt -trustcacerts # as configured in resources/ServerConfig.xml keytool -export -rfc -keystore clientKeystore.jks -alias myclientkey -file MyClient.cer -storepass cspass keytool -import -noprompt -trustcacerts -file MyClient.cer -alias myclientkey -keystore serviceKeystore.jks -storepass sspass - Modified: cxf/trunk/distribution/src/main/release/samples/jax_rs/basic_https/src/main/java/httpsdemo/client/Client.java URL: http://svn.apache.org/viewvc/cxf/trunk/distribution/src/main/release/samples/jax_rs/basic_https/src/main/java/httpsdemo/client/Client.java?rev=1369991&r1=1369990&r2=1369991&view=diff ============================================================================== --- cxf/trunk/distribution/src/main/release/samples/jax_rs/basic_https/src/main/java/httpsdemo/client/Client.java (original) +++ cxf/trunk/distribution/src/main/release/samples/jax_rs/basic_https/src/main/java/httpsdemo/client/Client.java Mon Aug 6 20:36:44 2012 @@ -20,11 +20,17 @@ package httpsdemo.client; import java.io.File; +import java.io.FileInputStream; +import java.security.KeyStore; + import javax.ws.rs.core.Response; -import org.apache.commons.httpclient.HttpClient; -import org.apache.commons.httpclient.contrib.ssl.AuthSSLProtocolSocketFactory; -import org.apache.commons.httpclient.methods.GetMethod; -import org.apache.commons.httpclient.protocol.Protocol; +import org.apache.http.HttpEntity; +import org.apache.http.HttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.conn.scheme.Scheme; +import org.apache.http.conn.ssl.SSLSocketFactory; +import org.apache.http.impl.client.DefaultHttpClient; +import org.apache.http.message.BasicHeader; import org.apache.cxf.jaxrs.client.JAXRSClientFactory; import org.apache.cxf.jaxrs.client.WebClient; import httpsdemo.common.Customer; @@ -39,42 +45,37 @@ public final class Client { private Client() { } - public static void main(String args[]) throws Exception { - - File clientKeystore = new File("src/main/config/clientKeystore.jks"); - File truststore = new File("src/main/config/clientKeystore.jks"); - - // Send HTTP GET request to query customer info - using portable HttpClient method - Protocol authhttps = new Protocol("https", - new AuthSSLProtocolSocketFactory(clientKeystore.toURI().toURL(), "cspass", - "ckpass", truststore.toURI().toURL(), "cspass"), 9000); - Protocol.registerProtocol("https", authhttps); + public static void main(String args[]) throws Exception { + String keyStoreLoc = "src/main/config/clientKeystore.jks"; + + KeyStore keyStore = KeyStore.getInstance("JKS"); + keyStore.load(new FileInputStream(keyStoreLoc), "cspass".toCharArray()); + + /* + * Send HTTP GET request to query customer info using portable HttpClient + * object from Apache HttpComponents + */ + SSLSocketFactory sf = new SSLSocketFactory(keyStore, "ckpass", keyStore); + Scheme httpsScheme = new Scheme("https", 9000, sf); System.out.println("Sending HTTPS GET request to query customer info"); - HttpClient httpclient = new HttpClient(); - GetMethod httpget = new GetMethod(BASE_SERVICE_URL + "/123"); - httpget.addRequestHeader("Accept" , "text/xml"); + DefaultHttpClient httpclient = new DefaultHttpClient(); + httpclient.getConnectionManager().getSchemeRegistry().register(httpsScheme); + HttpGet httpget = new HttpGet(BASE_SERVICE_URL + "/123"); + BasicHeader bh = new BasicHeader("Accept" , "text/xml"); + httpget.addHeader(bh); + HttpResponse response = httpclient.execute(httpget); + HttpEntity entity = response.getEntity(); + entity.writeTo(System.out); + httpclient.getConnectionManager().shutdown(); - // If Basic Authentication required could use: - /* - String authorizationHeader = "Basic " - + org.apache.cxf.common.util.Base64Utility.encode("username:password".getBytes()); - httpget.addRequestHeader("Authorization", authorizationHeader); - */ - try { - httpclient.executeMethod(httpget); - System.out.println(httpget.getResponseBodyAsString()); - } finally { - httpget.releaseConnection(); - } - /* * Send HTTP PUT request to update customer info, using CXF WebClient method * Note: if need to use basic authentication, use the WebClient.create(baseAddress, * username,password,configFile) variant, where configFile can be null if you're * not using certificates. */ - System.out.println("Sending HTTPS PUT to update customer name"); + System.out.println("\n\nSending HTTPS PUT to update customer name"); WebClient wc = WebClient.create(BASE_SERVICE_URL, CLIENT_CONFIG_FILE); Customer customer = new Customer(); customer.setId(123); @@ -87,8 +88,7 @@ public final class Client { * username,password,configFile) variant, where configFile can be null if you're * not using certificates. */ - System.out.println("\n"); - System.out.println("Sending HTTPS POST request to add customer"); + System.out.println("\n\nSending HTTPS POST request to add customer"); CustomerService proxy = JAXRSClientFactory.create(BASE_SERVICE_URL, CustomerService.class, CLIENT_CONFIG_FILE); customer = new Customer();