使用缺省传播令牌来传播安全性属性
缺省传播令牌位于正在运行的线程上,供应用程序和安全基础结构使用。产品往下游传播此缺省传播令牌,而且此令牌位于调用到达每个中继段的线程上。
关于此任务
数据可用于传播令牌到达的任何资源的容器中。请记住您必须在发送请求以使传播进行的每个服务器上启用传播功能。请确保您为要传播的环境中的所有单元启用安全性属性传播。
存在具有用于访问 PropagationToken 属性的应用程序编程接口 (API) 的 WSSecurityHelper 类。本主题记录使用方案并包括示例。传播令牌和工作区功能之间存在一种紧密的关系。这些功能之间的主要差异在于,在您将属性添加到传播令牌后,无法更改属性。您无法更改这些属性,因此安全运行时可以添加可审计的信息,并且使该信息在整个调用过程中都保留在那里。任何时候您将属性添加到特定键,都存储 ArrayList 对象以保存该属性。任何用同一键添加的新属性都被添加到 ArrayList 对象。当您调用 getAttributes 时,会将 ArrayList 对象转换为字符串数组并保存顺序。字符串数组中的第一个元素是为该特定键添加的第一个属性。
在缺省传播令牌中,有一个更改标志,它记录任何对令牌的数据更改。跟踪这些更改以使 WebSphere® Application Server 能了解何时再次往下游发送认证信息,以便下游服务器具有那些更改。通常,公共安全互操作性 V2 (CSIv2) 会为已认证的客户机在服务器间保持会话。如果传播令牌更改,那么生成新会话,而且接下来会发生新认证。在方法期间频繁对传播令牌进行更改会导致频繁的下游调用。如果您在进行许多下游调用前更改令牌或在每个下游调用之间更改令牌,那么可能会影响安全性能。
过程
- 从缺省传播令牌获取服务器列表。
每次水平地或往下游传播传播令牌并使用它创建已认证的主体集时,会将接收应用程序服务器的名称记录到传播令牌中。主机的格式是 "Cell:Node:Server",它为您提供对下述各项的访问权:接收调用的每个应用程序服务器的单元名、节点名和服务器名。
以下代码为您提供此名称列表,并可以从 Java™ 2 Platform, Enterprise Edition (J2EE) 应用程序调用。
表中每个服务器的格式是:cell:node_name:server_name。例如,输出是:myManager:node1:server1
String[] server_list = null;
// If security is disabled on this application server, do not bother checking
if (com.ibm.websphere.security.WSSecurityHelper.isServerSecurityEnabled())
{
try
{
// Gets the server_list string array
server_list = com.ibm.websphere.security.WSSecurityHelper.getServerList();
}
catch (Exception e)
{
// Performs normal exception handling for your application
}
if (server_list != null)
{
// print out each server in the list, server_list[0] is the first server
for (int i=0; i<server_list.length; i++)
{
System.out.println("Server[" + i + "] = " + server_list[i]);
}
}
} - 使用 getCallerList API 获取调用者列表。 在正在运行的线程上设置已认证的用户或任何人尝试将属性添加到传播令牌的任何时候,将生成缺省传播令牌。无论何时在线程上设置已认证的用户,都会将用户记录到缺省传播令牌中。有时,如果 RunAs 用户不同于调用者,那么同一用户可能记录多次。以下列表提供用于 确定是否将添加到线程的用户记录到传播令牌中的规则:
- 必须认证当前的主体集。例如,不记录未认证的主体集。
- 如果先前还未记录主体集,那么记录当前已认证的主体集。
- 如果最近记录的已认证主体集不包含同一用户,那么记录当前已认证的主体集。
- 当前已认证的主体集记录在传播过程中涉及的每个唯一的应用程序服务器上。
以下代码样本显示如何使用 getCallerList API。
列表中每个调用者的格式是:cell:node_name:server_name:realm:port_number/securityName。例如,输出是:myManager:node1:server1:ldap.austin.ibm.com:389/jsmith。
String[] caller_list = null;
// If security is disabled on this application server, do not check the caller list
if (com.ibm.websphere.security.WSSecurityHelper.isServerSecurityEnabled())
{
try
{
// Gets the caller_list string array
caller_list = com.ibm.websphere.security.WSSecurityHelper.getCallerList();
}
catch (Exception e)
{
// Performs normal exception handling for your application
}
if (caller_list != null)
{
// Prints out each caller in the list, caller_list[0] is the first caller
for (int i=0; i<caller_list.length;i++)
{
System.out.println("Caller[" + i + "] = " + caller_list[i]);
}
}
} - 使用 getFirst Caller API 获取第一个已认证用户的安全性名称。
无论何时要了解哪个已认证的调用者已启动请求,您可以调用 getFirstCaller 方法并解析调用者列表。但是,此方法仅会返回调用者的安全性名称。如果您需要了解的不止是安全性名称,那么调用 getCallerList 方法并检索 String[] 中的第一个条目。此条目提供调用者的所有信息。
以下代码样本使用 getFirstCaller API 检索第一个已认证的调用者的安全性名称。
例如,输出是:jsmith。String first_caller = null;
// If security is disabled on this application server, do not bother checking
if (com.ibm.websphere.security.WSSecurityHelper.isServerSecurityEnabled())
{
try
{
// Gets the first caller
first_caller = com.ibm.websphere.security.WSSecurityHelper.getFirstCaller();
// Prints out the caller name
System.out.println("First caller: " + first_caller);
}
catch (Exception e)
{
// Performs normal exception handling for your application
}
} - 使用 getFirstServer 方法获取请求的第一个应用程序服务器的名称。
无论何时要了解此请求的第一个应用程序服务器是哪个,请直接调用 getFirstServer 方法。
以下代码样本使用 getFirstServer API 检索第一个应用程序服务器的名称。
例如,输出是:myManager:node1:server1。
String first_server = null;
// If security is disabled on this application server, do not bother checking
if (com.ibm.websphere.security.WSSecurityHelper.isServerSecurityEnabled())
{
try
{
// Gets the first server
first_server = com.ibm.websphere.security.WSSecurityHelper.getFirstServer();
// Prints out the server name
System.out.println("First server: " + first_server);
}
catch (Exception e)
{
// Performs normal exception handling for your application
}
} - 使用 addPropagationAttribute API 将定制属性添加到缺省传播令牌。 可以将定制属性添加到缺省传播令牌以供应用程序使用。此令牌跟随请求向下游传递,以便这些属性随时可用。当您使用缺省传播令牌添加属性时,必须了解以下问题:
- 将信息添加到传播令牌会影响 CSIv2 会话高速缓存。在远程请求之间节约地添加信息。
- 在您用特定键添加信息后,无法移除此信息。
- 可以根据需要将尽可能多的值添加到特定键。但是,所有值必须可从返回的字符串数组按添加它们的顺序获取。
- 传播令牌仅可用于启用了传播和安全性的服务器上。
- 需要 Java 2 安全性 javax.security.auth.AuthPermission wssecurity.addPropagationAttribute 属性将属性添加到缺省传播令牌。
- 应用程序无法使用以 com.ibm.websphere.security 或 com.ibm.wsspi.security 开头的密钥。保留这些前缀供系统使用。
以下代码样本显示如何使用 addPropagationAttribute API。
// If security is disabled on this application server,
// do not check the status of server security
if (com.ibm.websphere.security.WSSecurityHelper.isServerSecurityEnabled())
{
try
{
// Specifies the key and values
String key = "mykey";
String value1 = "value1";
String value2 = "value2";
// Sets key, value1
com.ibm.websphere.security.WSSecurityHelper.
addPropagationAttribute (key, value1);
// Sets key, value2
String[] previous_values = com.ibm.websphere.security.WSSecurityHelper.
addPropagationAttribute (key, value2);
// Note: previous_values should contain value1
}
catch (Exception e)
{
// Performs normal exception handling for your application
}
} - 使用 getPropagationAttributes API 获取定制属性。 定制属性是使用 addPropagationAttribute API 添加到缺省传播令牌的。请使用 getPropagationAttributes API 检索这些属性。此令牌跟随请求向下游传递,因此这些属性随时可用。当您使用缺省传播令牌检索属性时,必须了解以下问题:
- 传播令牌仅可用于启用了传播和安全性的服务器上。
- 需要 Java 2 安全性 javax.security.auth.AuthPermission“wssecurity.getPropagationAttributes”许可权才能检索缺省传播令牌中的属性。
请参阅将定制属性添加到缺省 PropagationToken,以使用 addPropagationAttributes API 添加属性。
以下代码样本显示如何使用 getPropagationAttributes API。
// If security is disabled on this application server, do not bother checking
if (com.ibm.websphere.security.WSSecurityHelper.isServerSecurityEnabled())
{
try
{
String key = "mykey";
String[] values = null;
// Sets key, value1
values = com.ibm.websphere.security.WSSecurityHelper.
getPropagationAttributes (key);
// Prints the values
for (int i=0; i<values.length; i++)
{
System.out.println("Value[" + i + "] = " + values[i]);
}
}
catch (Exception e)
{
// Performs normal exception handling for your application
}
}例如,输出是:Value[0] = value1Value[1] = value2
- 修改传播令牌工厂配置以使用某一令牌工厂取代缺省令牌工厂。
当 WebSphere Application Server 生成缺省传播令牌时,应用程序服务器会利用使用 com.ibm.wsspi.security.token.propagationTokenFactory 属性指定的 TokenFactory 类。
为此属性指定的缺省令牌工厂称为 com.ibm.ws.security.ltpa.AuthzPropTokenFactory。此令牌工厂编码传播令牌中的数据,但不加密数据。由于传播令牌通常在使用安全套接字层 (SSL) 的 CSIv2 上传输,所以不需要加密该令牌。但是,如果您需要传播令牌的其他安全性 ,那么可以将另一个令牌工厂实现与此属性关联以获取加密。例如,如果您选择将 com.ibm.ws.security.ltpa.LTPAToken2Factory 令牌工厂与此属性关联,那么令牌是 AES 加密的。但是,您需要根据安全需要考虑性能影响。将敏感信息添加到传播令牌是将令牌工厂实现更改为加密而不仅是编码的一个很好的原因。
- 打开管理控制台。
- 单击安全性 > 全局安全性。
- 单击定制属性。
- 由您自己对缺省传播令牌执行签名和加密。 如果您要自己执行缺省传播令牌的签名和加密,那么必须实现以下各类:
- com.ibm.wsspi.security.ltpa.Token
- com.ibm.wsspi.security.ltpa.TokenFactory
- 将令牌工厂与缺省传播令牌相关联。
- 打开管理控制台。
- 单击安全性 > 全局安全性。
- 单击定制属性。
- 找到 com.ibm.wsspi.security.token.propagationTokenFactory 属性,并验证此属性的值是否与定制令牌工厂实现匹配。
- 验证实现类是否已放入 app_server_root/classes 目录,以便 WebSphere Application Server 类装入器可以装入这些类。
验证实现类是否位于 ${USER_INSTALL_ROOT}/classes 目录中,以便 WebSphere Application Server 类装入器可以装入这些类。
验证 QEJBSVR 用户概要文件是否对类目录具有读、写和执行 (*RWX) 权限。可以使用“使用权限”(WRKAUT) 命令来查看该目录的权限许可权。
示例


http://www14.software.ibm.com/webapp/wsbroker/redirect?version=cord&product=was-nd-mp&topic=tsec_defproptoken
文件名:tsec_defproptoken.html