I'm working on a client that consumes an https web service (client code created with JAX-WS RI). The server requires users authentication, provided with different PKCS12 files. When my client starts, I set the keystore and the truststore as follows:
System.setProperty("javax.net.ssl.keyStore",fileKeystore);
System.setProperty("javax.net.ssl.keyStorePassword",pwdKeystore);
System.setProperty("javax.net.ssl.keyStoreType","PKCS12");
System.setProperty("javax.net.ssl.trustStore",fileTruststore);
System.setProperty("javax.net.ssl.trustStorePassword",pwdTruststore);
System.setProperty("javax.net.ssl.trustStoreType","JKS");
Then I consume the WS, and all works:
string result = myClient.WSMethod(...);
I know these system properties can't be changed in the same way once setted. So, if I need to change the keystore to consume the webservice, without restart my server, as another user, what should I do?
In other words, I would achieve this behaviour:
- Consume the WS using keystore/truststore of user #1
- Consume the WS using keystore/truststore of user #2
- ....
Searching on SO I read about creating an SSLContext but I'm a little bit confused about how to do that and assign it to the connection with the WS.