使用 JSSEHelper API 以编程方式指定出站 SSL 配置

WebSphere® Application Server 提供了一种方法,您可按编程方式指定在进行出站连接之前要使用的安全套接字层 (SSL) 配置。com.ibm.websphere.ssl.JSSEHelper 接口提供了一组完整的应用程序编程接口 (API) 来处理 SSL 配置。

关于此任务

在使用 JSSEHelper API 在线程上建立运行时所使用的 SSL 属性对象时,请对应用程序执行以下步骤。其中一些 API 具有 Java™ 2 安全性许可权需求。请参阅 JSSEHelper API 文档,以获取有关应用程序所需的许可权的更多信息。

在以编程方式指定在进行出站连接之前要使用的安全套接字层 (SSL) 配置时,选择最适合连接情况的方法。

过程

  1. 获取 JSSEHelper API 的实例。
    com.ibm.websphere.ssl.JSSEHelper jsseHelper  = com.ibm.websphere.ssl.JSSEHelper.getInstance();
  2. WebSphere Application Server 配置获取 SSL 属性或使用应用程序提供的 SSL 属性。 使用下列其中一个选项。
    • 通过在相同或更高级别的管理范围中对别名进行定向选择,如以下示例中所示:
      try 
      { 	String alias = "NodeAServer1SSLSettings";
        // As specified in the WebSphere SSL configuration 	Properties
       sslProps = jsseHelper.getProperties(alias); }
       catch (com.ibm.websphere.ssl.SSLException e)
       { 	e.printStackTrace();   // handle exception }
    • 根据优先顺序规则和继承对编程、定向、动态出站或管理范围方面的所选内容使用 getProperties API。SSL 运行时使用 getProperties API 来确定要用于特定协议的 SSL 配置。此决策基于输入(sslAlias 和 connectionInfo)和从中调用属性的管理范围。getProperties API 按以下顺序制定决策:
      1. API 检查线程以了解属性是否已经存在。
      2. API 进行检查以获取与 ENDPOINT_NAME、REMOTE_HOST 和/或 REMOTE_PORT 匹配的动态出站配置。
      3. API 进行检查以了解是否指定了可选 sslAlias 属性。可将任何协议配置为直接管理或集中管理。当协议配置为直接管理时,sslAlias 参数为 null。当协议配置为集中管理时,sslAlias 参数同样为 null
      4. 如果未进行任何选择,那么 API 将根据从中进行调用的管理范围来选择动态出站配置。如果未在同一范围中定义动态出站配置,那么搜索该层次结构以找到该配置。

      最后的选择是限于单元范围的 SSL 配置(在 WebSphere Application Server Network Deployment 中)或限于节点范围的 SSL 配置(在基本应用程序服务器中)。当调用 getProperties API 的操作所选择的 SSL 配置更改时,将通知 com.ibm.websphere.ssl.SSLConfigChangeListener 参数。这样,该协议会再次调用该 API 以获取新属性,如以下示例中所示:

      try { 	String sslAlias = null;
       // The sslAlias is not specified directly at this time. 	String host = "myhost.austin.ibm.com";
       // the target host 	String port = "443";
       // the target port  	HashMap connectionInfo = new HashMap();
       connectionInfo.put(JSSEHelper.CONNECTION_INFO_DIRECTION,    JSSEHelper.DIRECTION_OUTBOUND);
       connectionInfo.put(JSSEHelper.CONNECTION_INFO_REMOTE_HOST, host);
       connectionInfo.put(JSSEHelper.CONNECTION_INFO_REMOTE_PORT,    Integer.toString(port));
      	connectionInfo.put(JSSEHelper.CONNECTION_INFO_ENDPOINT_NAME,    JSSEHelper.ENDPOINT_IIOP);
                  	java.util.Properties props = jsseHelper.getProperties(sslAlias,    connectionInfo, null); }
       catch (com.ibm.websphere.ssl.SSLException e)
       { 	e.printStackTrace();   // handle exception }
    • 通过创建您自己的 SSL 属性并将其传递至运行时,如以下示例中所示:
      try {
      	// This is the recommended "minimum" set of SSL properties. The trustStore can
       	// be the same as the keyStore. 	Properties sslProps = new Properties();
      	sslProps.setProperty("com.ibm.ssl.trustStore", "some value");
      	sslProps.setProperty("com.ibm.ssl.trustStorePassword", "some value");
      	sslProps.setProperty("com.ibm.ssl.trustStoreType", "some value");
      	sslProps.setProperty("com.ibm.ssl.keyStore", "some value");
      	sslProps.setProperty("com.ibm.ssl.keyStorePassword", "some value");
      	sslProps.setProperty("com.ibm.ssl.keyStoreType", "some value");
       	jsseHelper.setSSLPropertiesOnThread(sslProps); }
       catch (com.ibm.websphere.ssl.SSLException e) 
      { 	e.printStackTrace();   // handle exception } 
  3. 使用 JSSEHelper.setSSLPropertiesOnThread(props) API 以在线程上设置属性对象,以便运行时选择它并使用相同的 JSSEHelper.getProperties API。 还可在使用 jsseHelper.getSSLPropertiesOnThread() API 设置属性后从线程获取它们,如以下示例中所示:
    try 
    { 	Properties sslProps = jsseHelper.getProperties(null,    connectionInfo, null);
    jsseHelper.setSSLPropertiesOnThread(sslProps); }
     catch (com.ibm.websphere.ssl.SSLException e) 
    { 	e.printStackTrace();   // handle exception }
  4. 完成连接后,必须通过将 null 值传递给 setPropertiesOnThread API 来从线程中清除 SSL 属性。
    try
     { 	jsseHelper.setSSLPropertiesOnThread(null); }
     catch (com.ibm.websphere.ssl.SSLException e) 
     { 	e.printStackTrace();   // handle exception }

指示主题类型的图标 任务主题



时间戳记图标 最近一次更新时间: last_date
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=cord&product=was-nd-mp&topic=tsec_ssloutconfiguseJSSE
文件名:tsec_ssloutconfiguseJSSE.html