I am trying to request data from a web service for which a client certificate must be submitted by the client. The server uses SSL for all communications and uses a self-signed certificate. I gave Netbeans a WSDL service file and it generated client code using wsimport.
I have no problem when client code is written in a regular Java application; I installed the trust store in a file cacertscontaining the server certificate, installed the key store as a file provided by the server administrator in the JKS format, containing 2 keys - the client’s private key and the server’s public key, built the request object, and send the request.
The problem occurs when I port it to the corporate Java environment. Requirements dictate that the code must be Enterprise JavaBean inside the corporate archive running on the Glassfish application server. Glassfish seems to have its own security settings that override the JVM settings. When the EJB method contains a call to a Web service, SSL negotiation is not performed: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target. I don’t know how to set Glassfish security settings, like JVM settings, can anyone explain Glassfish security settings? The research I did only showed how to configure Glassfish as a web service server , and not as a web service client .
I have a .cer certificate file for a server that I added to the trust store using Java keytoolto add it cacertsto the default file . Would it be better to modify the file cacertswith InstallCertto enable a self-signed certificate by following the steps http://blog.johnryding.com/post/1548502059/acquire-an-ssl-certificate-for-your-java-programs-in-win ?
I have a trust store file, a keystore file, a .cer certificate file, and a .p12 browser certificate stored in $ JAVA_HOME / jre / lib / security and $ JAVA_HOME / lib / security.
I am using Netbeans 6.9.1 and Glassfish 3.1 Final. Below is the relevant piece of code copied from my EJB. An exception occurs on the last line.
System.setProperty("javax.net.ssl.trustStore", "C:\\jssecacerts");
System.setProperty("javax.net.ssl.trustStorePassword", "changeit");
System.setProperty("javax.net.ssl.keyStore", "C:\\userCertificate.jks");
System.setProperty("javax.net.ssl.keyStorePassword", "password");
RequestObject request = new RequestObject;
request.setQuery("some data");
request.setUsername("user");
request.setPassword("pass");
Service service = new Service();
Endpoint port = service.getWebServicePort();
Result result = port.specificWebServiceMethod(request);
source
share