我想访问我的Web应用程序中Weblogic的自定义密钥库配置中配置的Identity密钥库(JKS)。如何在不依赖以下环境属性的情况下让weblogic公开它:-Djavax.net.ssl.Keystore,-Djavax.net.ssl.KeystorePassword。
答案 0 :(得分:2)
您可以使用以下代码作为起点。
几点说明:
OracleSystemGroup
java.lang.String
中,不建议这样做。由于这些缺点,我正在研究一种更好的方法。我一直在尝试找到一个WebLogic服务,它将提供访问身份存储中的证书和密钥的服务。看来there is not one。
InitialContext ic = new InitialContext();
MBeanServer server = (MBeanServer) ic.lookup("java:comp/env/jmx/runtime");
// Get access to server configuration
ObjectName runtime = new ObjectName("com.bea:Name=RuntimeService,Type=weblogic.management.mbeanservers.runtime.RuntimeServiceMBean");
ObjectName serverConfig = (ObjectName) server.getAttribute(runtime, "ServerConfiguration");
/* Load identity store location and passphrase.
* If e.g. Demo identity has been configured (in WL console) instead of
* custom identity then the following does not work.
*/
// Passphrase as clear text
Object keyStorePassPhrase = server.getAttribute(serverConfig, "CustomIdentityKeyStorePassPhrase");
Object keyStoreFileName = server.getAttribute(serverConfig, "CustomIdentityKeyStoreFileName");
// Load keystore
KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
ks.load(new FileInputStream(keyStoreFileName.toString()),
keyStorePassPhrase.toCharArray());