diff --git a/.gitignore b/.gitignore index 1ebf457..a27360a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ target/ *.iml .idea/ +etc/config/twitter.properties + diff --git a/etc/config/twitter-template.properties b/etc/config/twitter-template.properties new file mode 100644 index 0000000..c72a770 --- /dev/null +++ b/etc/config/twitter-template.properties @@ -0,0 +1,14 @@ +## Copy this file to etc/config/twitter.properties and provide +## user-specific values so tests can successfully access twitter +## APIs. + +# Access Token Username (as shown on API settings page; case-sensitive for tests) +twitter.user= +# Application API Key +twitter.oauth.consumerKey= +# Application API secret +twitter.oauth.consumerSecret= +# Access Token +twitter.oauth.accessToken= +# Acccess Token Secret +twitter.oauth.secretToken= diff --git a/pom.xml b/pom.xml index e67fa4e..c604791 100644 --- a/pom.xml +++ b/pom.xml @@ -341,6 +341,25 @@ maven-deploy-plugin 2.8.1 + + org.codehaus.mojo + properties-maven-plugin + 1.0-alpha-2 + + + initialize + + read-project-properties + + + + etc/config/twitter.properties + + true + + + + diff --git a/src/main/java/groovyx/net/http/AuthConfig.java b/src/main/java/groovyx/net/http/AuthConfig.java index e62204a..894fc79 100644 --- a/src/main/java/groovyx/net/http/AuthConfig.java +++ b/src/main/java/groovyx/net/http/AuthConfig.java @@ -139,19 +139,50 @@ public void ntlm( String host, int port, String user, String pass, String workst public void certificate( String certURL, String password ) throws GeneralSecurityException, IOException { - KeyStore keyStore = KeyStore.getInstance( KeyStore.getDefaultType() ); + certificate( certURL, password, "jks" ); + } + + /** + * Sets a certificate to be used for SSL authentication. See + * {@link Class#getResource(String)} for how to get a URL from a resource + * on the classpath. + * @param certURL URL to a keystore where the certificate is stored. + * @param password password to decrypt the keystore + * @param keyStoreType the type of keystore (e.g. JKS, PKCS12) containing the certificate + */ + public void certificate( String certURL, String password, String keyStoreType ) + throws GeneralSecurityException, IOException { + + if (keyStoreType == null) { + keyStoreType = KeyStore.getDefaultType(); + } + KeyStore keyStore = KeyStore.getInstance( keyStoreType ); InputStream jksStream = new URL(certURL).openStream(); try { keyStore.load( jksStream, password.toCharArray() ); } finally { jksStream.close(); } + certificate( keyStore, password ); + } + + /** + * Provide a Keystore containing the certificate to be used for + * SSL authentication. This method moves the responsibility of + * loading the certificates to the application, allowing access + * to custom Keystore types such as SmartCard access or other + * proprietary forms. + * @param keyStore the keystore containing the authentication certificate + * @param password password to decrypt the keystore + */ + public void certificate( KeyStore keyStore, String password ) + throws GeneralSecurityException, IOException { SSLSocketFactory ssl = new SSLSocketFactory(keyStore, password); ssl.setHostnameVerifier( SSLSocketFactory.STRICT_HOSTNAME_VERIFIER ); builder.getClient().getConnectionManager().getSchemeRegistry() .register( new Scheme("https", ssl, 443) ); } - + /** *

OAuth sign all requests. Note that this currently does not * wait for a WWW-Authenticate challenge before sending the