[jboss-cvs] JBossAS SVN: r74043 - trunk/testsuite/src/main/org/jboss/test/security/service.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Jun 3 18:21:05 EDT 2008
Author: mmoyses
Date: 2008-06-03 18:21:05 -0400 (Tue, 03 Jun 2008)
New Revision: 74043
Modified:
trunk/testsuite/src/main/org/jboss/test/security/service/HttpsClient.java
Log:
JBAS-5532
Modified: trunk/testsuite/src/main/org/jboss/test/security/service/HttpsClient.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/security/service/HttpsClient.java 2008-06-03 22:19:42 UTC (rev 74042)
+++ trunk/testsuite/src/main/org/jboss/test/security/service/HttpsClient.java 2008-06-03 22:21:05 UTC (rev 74043)
@@ -23,24 +23,24 @@
import java.io.File;
import java.io.FileOutputStream;
+import java.io.IOException;
import java.io.InputStream;
-import java.io.IOException;
-import java.net.JarURLConnection;
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
import java.net.Socket;
import java.net.URL;
-import java.net.HttpURLConnection;
-import java.net.MalformedURLException;
-import java.security.Provider;
+import java.security.Provider;
import java.security.Security;
import java.util.StringTokenizer;
-import java.util.jar.JarEntry;
-import java.util.jar.JarFile;
+
import javax.net.ssl.SSLSocketFactory;
+import org.jboss.invocation.http.interfaces.Util;
import org.jboss.logging.Logger;
import org.jboss.system.ServiceMBeanSupport;
-import org.jboss.invocation.http.interfaces.Util;
import org.jboss.test.util.SecurityProviderUtil;
+import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.plugins.vfs.VirtualFileURLConnection;
/** A test mbean service that reads input from an https url passed in
to its readURL method.
@@ -48,14 +48,13 @@
@author Scott.Stark at jboss.org
@version $Revision$
*/
-public class HttpsClient extends ServiceMBeanSupport
- implements HttpsClientMBean
+public class HttpsClient extends ServiceMBeanSupport implements HttpsClientMBean
{
// Constants -----------------------------------------------------
// Attributes ----------------------------------------------------
private boolean addedHttpsHandler;
-
+
private boolean addedJSSEProvider;
// Static --------------------------------------------------------
@@ -76,20 +75,21 @@
try
{
String reply = internalReadURL(urlString);
- log.debug("readURL -> "+reply);
+ log.debug("readURL -> " + reply);
return reply;
}
- catch(Throwable e)
+ catch (Throwable e)
{
log.error("Failed to readURL", e);
- throw new IOException("Failed to readURL, ex="+e.getMessage());
+ throw new IOException("Failed to readURL, ex=" + e.getMessage());
}
}
+
private String internalReadURL(String urlString) throws Exception
{
- log.debug("Creating URL from string: "+urlString);
+ log.debug("Creating URL from string: " + urlString);
URL url = new URL(urlString);
- log.debug("Created URL object from string, protocol="+url.getProtocol());
+ log.debug("Created URL object from string, protocol=" + url.getProtocol());
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
/* Override the host verifier so we can use a test server cert with
a hostname that may not match the https url hostname.
@@ -97,13 +97,13 @@
System.setProperty("org.jboss.security.ignoreHttpsHost", "true");
Util.configureHttpsHostVerifier(conn);
- log.debug("Connecting to URL: "+url);
+ log.debug("Connecting to URL: " + url);
byte[] buffer = new byte[1024];
int length = conn.getContentLength();
- log.debug("ContentLength: "+length);
+ log.debug("ContentLength: " + length);
InputStream is = conn.getInputStream();
StringBuffer reply = new StringBuffer();
- while( (length = is.read(buffer)) > 0 )
+ while ((length = is.read(buffer)) > 0)
reply.append(new String(buffer, 0, length));
log.debug("Done, closing streams");
is.close();
@@ -118,24 +118,24 @@
{
new URL("https://www.https.test");
}
- catch(MalformedURLException e)
+ catch (MalformedURLException e)
{
// Install the default JSSE security provider
Provider provider = SecurityProviderUtil.getJSSEProvider();
log.debug("Adding " + provider.getName());
-
+
addedJSSEProvider = Security.addProvider(provider) != -1;
if (addedJSSEProvider)
{
log.debug("Added " + provider.getName());
- }
-
+ }
+
addedHttpsHandler = false;
// Install the JSSE https handler if it has not already been added
String protocolHandler = SecurityProviderUtil.getProtocolHandlerName();
String handlers = System.getProperty("java.protocol.handler.pkgs");
- if( handlers == null || handlers.indexOf(protocolHandler ) < 0 )
+ if (handlers == null || handlers.indexOf(protocolHandler) < 0)
{
handlers += "|" + protocolHandler;
log.debug("Adding https handler to java.protocol.handler.pkgs");
@@ -147,49 +147,49 @@
// Install the trust store
ClassLoader loader = Thread.currentThread().getContextClassLoader();
URL keyStoreURL = loader.getResource("META-INF/tst.keystore");
- if( keyStoreURL == null )
+ if (keyStoreURL == null)
throw new IOException("Failed to find resource tst.keystore");
- if( keyStoreURL.getProtocol().equals("jar") )
+ if (keyStoreURL.getProtocol().equals("vfszip"))
{
- JarURLConnection conn = (JarURLConnection) keyStoreURL.openConnection();
- JarFile jar = conn.getJarFile();
- JarEntry entry = jar.getJarEntry("META-INF/tst.keystore");
- InputStream is = jar.getInputStream(entry);
+ VirtualFileURLConnection conn = (VirtualFileURLConnection) keyStoreURL.openConnection();
+ VirtualFile vf = conn.getVirtualFile();
+ InputStream is = vf.openStream();
File tmp = File.createTempFile("tst-", ".keystore");
tmp.deleteOnExit();
FileOutputStream fos = new FileOutputStream(tmp);
byte[] buffer = new byte[1024];
int bytes;
- while( (bytes = is.read(buffer)) > 0 )
+ while ((bytes = is.read(buffer)) > 0)
fos.write(buffer, 0, bytes);
fos.close();
is.close();
keyStoreURL = tmp.toURL();
}
- log.debug("Setting javax.net.ssl.trustStore to: "+keyStoreURL.getPath());
+ log.debug("Setting javax.net.ssl.trustStore to: " + keyStoreURL.getPath());
System.setProperty("javax.net.ssl.trustStore", keyStoreURL.getPath());
}
+
protected void stopService() throws Exception
{
if (addedJSSEProvider)
- {
+ {
Provider provider = SecurityProviderUtil.getJSSEProvider();
String name = provider.getName();
log.debug("Removing " + name);
Security.removeProvider(name);
- }
+ }
- if( addedHttpsHandler == true )
+ if (addedHttpsHandler == true)
{
log.debug("Removing https handler from java.protocol.handler.pkgs");
- String protocolHandler = SecurityProviderUtil.getProtocolHandlerName();
+ String protocolHandler = SecurityProviderUtil.getProtocolHandlerName();
String handlers = System.getProperty("java.protocol.handler.pkgs");
StringTokenizer tokenizer = new StringTokenizer(handlers, "|");
StringBuffer buffer = new StringBuffer();
- while( tokenizer.hasMoreTokens() )
+ while (tokenizer.hasMoreTokens())
{
String handler = tokenizer.nextToken();
- if( handler.equals(protocolHandler) == false )
+ if (handler.equals(protocolHandler) == false)
{
buffer.append('|');
buffer.append(handler);
@@ -204,7 +204,9 @@
class DebugSSLSocketFactory extends SSLSocketFactory
{
SSLSocketFactory factoryDelegate;
+
Logger theLog;
+
DebugSSLSocketFactory(SSLSocketFactory factoryDelegate, Logger theLog)
{
this.factoryDelegate = factoryDelegate;
@@ -213,51 +215,50 @@
public Socket createSocket(java.net.InetAddress host, int port) throws java.io.IOException
{
- theLog.debug("createSocket, host="+host+", port="+port);
+ theLog.debug("createSocket, host=" + host + ", port=" + port);
Socket s = factoryDelegate.createSocket(host, port);
- theLog.debug("created socket="+s);
+ theLog.debug("created socket=" + s);
return s;
}
- public Socket createSocket(String host, int port)
- throws java.io.IOException, java.net.UnknownHostException
+ public Socket createSocket(String host, int port) throws java.io.IOException, java.net.UnknownHostException
{
- theLog.debug("createSocket, host="+host+", port="+port);
+ theLog.debug("createSocket, host=" + host + ", port=" + port);
Socket s = factoryDelegate.createSocket(host, port);
- theLog.debug("created socket="+s);
+ theLog.debug("created socket=" + s);
return s;
}
- public Socket createSocket(Socket socket, String host, int port, boolean autoClose)
- throws java.io.IOException
+ public Socket createSocket(Socket socket, String host, int port, boolean autoClose) throws java.io.IOException
{
- theLog.debug("createSocket, socket="+socket+", host="+host+", port="+port);
+ theLog.debug("createSocket, socket=" + socket + ", host=" + host + ", port=" + port);
Socket s = factoryDelegate.createSocket(socket, host, port, autoClose);
- theLog.debug("created socket="+s);
+ theLog.debug("created socket=" + s);
return s;
}
public Socket createSocket(java.net.InetAddress host, int port, java.net.InetAddress clientAddress, int clientPort)
- throws java.io.IOException
+ throws java.io.IOException
{
- theLog.debug("createSocket, host="+host+", port="+port+", clientAddress="+clientAddress+", clientPort="+clientPort);
+ theLog.debug("createSocket, host=" + host + ", port=" + port + ", clientAddress=" + clientAddress
+ + ", clientPort=" + clientPort);
Socket s = factoryDelegate.createSocket(host, port, clientAddress, clientPort);
- theLog.debug("created socket="+s);
+ theLog.debug("created socket=" + s);
return s;
}
public Socket createSocket(String host, int port, java.net.InetAddress clientAddress, int clientPort)
- throws java.io.IOException, java.net.UnknownHostException
+ throws java.io.IOException, java.net.UnknownHostException
{
- theLog.debug("createSocket, host="+host+", port="+port+", addr="+clientAddress);
+ theLog.debug("createSocket, host=" + host + ", port=" + port + ", addr=" + clientAddress);
Socket s = factoryDelegate.createSocket(host, port, clientAddress, clientPort);
- theLog.debug("created socket="+s);
+ theLog.debug("created socket=" + s);
return s;
}
public String[] getDefaultCipherSuites()
{
- return factoryDelegate.getDefaultCipherSuites();
+ return factoryDelegate.getDefaultCipherSuites();
}
public String[] getSupportedCipherSuites()
More information about the jboss-cvs-commits
mailing list