Using custom SSLSocketFactory
aznan Jan 16, 2013 12:04 PMHi!
I have a web service that uses a custom SSLSocketFactory that accepts all certificates, as described here: http://stackoverflow.com/questions/1219208/is-it-possible-to-get-java-to-ignore-the-trust-store-and-just-accept-whatever
When the web service was previously running on JBoss 4.2.3, the SocketFactory was packaged in a jar in the server's lib folder and the jar was added to java.class.path in the startup script.
Now I'm migrating to JBoss 7.0.1 and I've made a global module out of the jar. I am able to access the class from within the web servce, but it will not load as a SSLSocketFactory.
To illustrate the problem this is a mockup of my custom socket factory:
package com.mycompany;
import javax.net.ssl.*;
import java.io.IOException;
import java.net.*;
public class MySocketFactory extends SSLSocketFactory {
public void sayHello() {
System.out.println("Hello from " + getClass().getName());
}
// Implement abstract methods.
public String[] getDefaultCipherSuites() {
return null;
}
public String[] getSupportedCipherSuites() {
return null;
}
public Socket createSocket(Socket socket, String s, int i, boolean b) throws IOException {
return null;
}
public Socket createSocket(String s, int i) throws IOException, UnknownHostException {
return null;
}
public Socket createSocket(String s, int i, InetAddress inetAddress, int i2) throws IOException, UnknownHostException {
return null;
}
public Socket createSocket(InetAddress inetAddress, int i) throws IOException {
return null;
}
public Socket createSocket(InetAddress inetAddress, int i, InetAddress inetAddress2, int i2) throws IOException {
return null;
}
}
And here is a class I've used to test it in the web service:
package com.mycompany;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.ldap.core.support.LdapContextSource;
import java.security.Security;
public class MySocketFactoryTest {
private LdapTemplate ldapTemplate;
public MySocketFactoryTest() throws Exception {
// Tell Java to use my socket factory.
Security.setProperty("ssl.SocketFactory.provider", "com.mycompany.MySocketFactory");
// Setup the ldap template.
LdapContextSource contextSource = new LdapContextSource();
contextSource.setUrl("ldaps://url");
contextSource.setUserDn("usr");
contextSource.setPassword("pwd");
contextSource.afterPropertiesSet();
ldapTemplate = new LdapTemplate(contextSource);
}
public void runTest() {
new MySocketFactory().sayHello();
ldapTemplate.lookup("testing");
}
}
When I run runTest(), this line is first printed to the log:
16:58:23,172 INFO [stdout] Hello from com.mycompany.MySocketFactory
So sayHello() went fine, but when I try to do the lookup I get this:
java.lang.ClassNotFoundException: com.mycompany.MySocketFactory
This is clearly a class loading issue. How do I make MySocketFactory visible to the JBoss? Just adding the jar to java.class.path doesn't seem to do the trick.
Please help!
/Matti