我的应用程序如何访问在Weblogic管理控制台中配置的密钥库?

时间:2012-05-01 14:31:21

标签: weblogic keystore

我想访问我的Web应用程序中Weblogic的自定义密钥库配置中配置的Identity密钥库(JKS)。如何在不依赖以下环境属性的情况下让weblogic公开它:-Djavax.net.ssl.Keystore,-Djavax.net.ssl.KeystorePassword。

1 个答案:

答案 0 :(得分:2)

您可以使用以下代码作为起点。

几点说明:

  • 执行代码的用户需要属于名为OracleSystemGroup
  • 的组
  • 密钥库是从文件系统加载的,不是EJB规范推荐的。但我认为文件阅读可以安全地完成。
  • 密钥库密码包含在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());
相关问题