Creative Solution: Retrieve properties on WebSphere SSL Certificate Trustore
As a full stack developer in Java, you might have come across a situation where you need to load keystore certificate information from your WebSphere container. So how do perform such action?
Let’s say you have a websphere application and in your application you need to consume messages from Kafka Stream. To be able to establish a secure connection to Kafka you need to specify your keystore location and some other related information in your Java Program.
Now the issue is that you already have a keystore and truststore available to you in the WebSphere container, and you don’t want to hard-code the path of the keystore location and some other property information somewhere in a configuration file which the application will load so that you can use it to establish the Kafka connection.
One creative solution is to use the API available in IBM packages which is the “KeyStoreManager”. This API is exposed in the “com.ibm.ws.runtime-*.jar” package.
By using the KeyStoreManager.getInstance().getKeyStore(…), you can iterate through the different property key and value defined in your truststore and use the one required for the Kafka connection.
WSKeyStore wsKeyStore = KeyStoreManager.getInstance().getKeystore(“xxx”, “nodeDefaultTrustStore”)
In your WAS console, you can verify the name used for your truststore. In our case, it was defined as “nodeDefaultTrustStore”.