开发信任关联的定制拦截器
您可以定义要使用的拦截器类方法。WebSphere® Application Server 支持两个信任关联拦截器接口:com.ibm.wsspi.security.TrustAssociationInterceptor 和 com.ibm.wsspi.security.tai.TrustAssociationInterceptor。
开始之前
过程
- 定义拦截器类方法。 WebSphere Application Server 提供拦截器 Java™ 接口 com.ibm.wsspi.security.TrustAssociationInterceptor,该接口定义以下方法:
- public boolean isTargetInterceptor(HttpServletRequest req) 创建 WebTrustAssociationException;。
isTargetInterceptor 方法确定代理服务器产生的请求是否与拦截器相关联。实现代码必须检查进入请求对象,并确定转发请求的代理服务器对于此拦截器是否为有效的代理服务器。此方法的结果确定拦截器是否处理请求。
- public void validateEstablishedTrust (HttpServletRequest req) 创建 WebTrustAssociationException;。
validateEstablishedTrust 方法确定是否信任产生请求的代理服务器。在调用 isTargetInterceptor 方法之后调用此方法。实现代码必须认证代理服务器。认证机制是特定于代理服务器的。例如,在 WebSEAL 服务器的产品实现中,此方法检索来自 HTTP 头的基本认证信息,并针对 WebSphere Application Server 使用的用户注册表验证信息。如果凭证无效,那么代码产生 WebTrustAssociationException,表明代理服务器不可信且请求将被拒绝。
- public String getAuthenticatedUsername(HttpServletRequest req) 创建 WebTrustAssociationException;。
在代理服务器和 WebSphere Application Server 之间建立信任后,将调用 getAuthenticatedUsername 方法。产品已接受请求的代理服务器认证,现在必须对该请求进行授权。要对请求进行授权,授权策略必须通过原始请求者的名称来确定请求者是否具有必要的特权。此方法的实现代码必须从 HTTP 请求头抽取用户名并确定用户是否有资格使用所请求的资源。例如,在 WebSEAL 服务器的产品实现中,该方法在 HTTP 请求头中查找 iv-user 属性并抽取与它相关联的用户标识进行授权。
- public boolean isTargetInterceptor(HttpServletRequest req) 创建 WebTrustAssociationException;。
- 配置拦截器。要使拦截器成为可配置的,拦截器必须扩展 com.ibm.wsspi.security.WebSphereBaseTrustAssociationInterceptor。请实现以下方法:
- public int init (java.util.Properties props);
- init(Properties) 方法接受 java.util.Properties
对象,该对象包含初始化拦截器所必需的属性集。拦截器的所有属性集(通过使用该拦截器的定制属性链接或使用脚本编制)发送到此方法。然后拦截器可以使用这些属性初始化它本身。例如,在 WebSEAL 服务器的产品实现中,此方法读主机和端口,这样就可以验证进入请求是否来自可信的主机和端口。0 返回值暗示拦截器初始化成功。任何其他值都暗示初始化失败并且忽略该拦截器。
以下列表的适用性
如果信任关联拦截器的前一个实现返回不同的错误状态,那么您可以更改实现以符合您的期望或作以下某种更改:- 将 com.ibm.wsspi.security.trustassociation.initStatus 属性添加到信任关联拦截器定制属性中。将属性设置为表明拦截器成功初始化的值。所有其他可能的值都暗示失败。万一失败,那么不使用相应的信任关联拦截器。
- 将 com.ibm.wsspi.security.trustassociation.ignoreInitStatus 属性添加到信任关联拦截器定制属性中。将此属性的值设置为 true,指示 WebSphere Application Server 忽略此方法的状态。如果将此属性添加到定制属性,那么 WebSphere Application Server 不检查返回状态,这与先前版本的 WebSphere Application Server 类似。
- public void cleanup ();
- 当应用程序服务器停止时会调用此方法。它用来准备终止拦截器。
- public void setVersion (String s);
- 此方法是可选的。此方法用来设置版本,它仅供参考。未指定缺省值。
必须配置由定制拦截器实现的以下方法。此列表仅显示方法,它不包括任何实现。******************************************************************** import java.util.*; import javax.servlet.http.HttpServletRequest; import com.ibm.websphere.security.*; public class myTAIImpl extends WebSphereBaseTrustAssociationInterceptor implements TrustAssociationInterceptor { public myTAIImpl () { } public boolean isTargetInterceptor (HttpServletRequest req) throws WebTrustAssociationException { //return true if this is the target interceptor, else return false. } public TAIResult negotiateValidateandEstablishTrust (HttpServletRequest req, HttpServletResponse res) throws WebTrustAssociationFailedException { //validate the request and establish trust. //create and return the TAIResult public int initialize (Properties props) { //initialize the implementation. If successful return 0, else return 1. } public String getVersion() { //Return version } public String getType() { //Return type } public void cleanup () { //Cleanup code. } }
注: 如果在定制拦截器中按上述描述实现了 init(Properties) 方法,那么此注释不适用于您的实现,您可以继续执行下一个步骤。先前版本的 com.ibm.wsspi.security.WebSphereBaseTrustAssociationInterceptor 包括 public int init (String propsfile) 方法。因为不再从文件中读取拦截器属性,所以不再需要此方法。现在使用管理控制台或脚本在拦截器的管理控制台定制属性链接中输入这些属性。然后这些属性可用于 init(Properties) 方法的实现。但是,为了获取向后兼容性,仍支持 init(String) 方法。init(String) 方法由 init(Properties) 的缺省实现调用,如以下示例中所示。// Default implementation of init(Properties props) method. A Custom // implementation should override this. public int init (java.util.Properties props) { String type = props.getProperty("com.ibm.wsspi.security.trustassociation.types"); String classfile= props.getProperty("com.ibm.wsspi.security.trustassociation." +type+".config"); if (classfile != null && classfile.length() > 0 ) { return init(classfile); } else { return -1; } }
请将您的实现更改为实现 init(Properties) 方法而不是依赖 init(String propsfile) 方法。如上述示例中所示,此缺省实现读取属性以装入属性文件。com.ibm.wsspi.security.trustassociation.types 属性通过将 .config 与它的值连接来获取包含属性的文件。
注: 如果要使用 init(String) 方法而不实现 init(Properties) 方法,那么 init(String) 方法仍有效。唯一的要求是现在应该输入包含定制信任关联属性的文件名,这可以使用管理控制台中的拦截器的定制属性链接或通过使用脚本实现。您可以使用以下任何一种方法输入属性。第一种方法用来与先前版本的 WebSphere Application Server 向后兼容性。- 方法 1:
- 使用前发行版中用过的相同属性名获取文件名。
通过将 .config 与 com.ibm.wsspi.security.trustassociation.types 属性值连接来获取文件名。
如果文件名为 myTAI.properties 并位于 app_server_root/properties 目录中,那么设置下列属性:
- com.ibm.wsspi.security.trustassociation.types = myTAItype
- com.ibm.wsspi.security.trustassociation.myTAItype.config = app_server_root/properties/myTAI.properties
如果文件名为 myTAI.properties 并位于 /properties 目录中,请设置下列属性:
- com.ibm.wsspi.security.trustassociation.types = myTAItype
- com.ibm.wsspi.security.trustassociation.myTAItype.config = app_server_root/myTAI.properties
- 方法 2:
- 您可以将信任关联定制属性中的 com.ibm.wsspi.security.trustassociation.initPropsFile 属性设置为文件的位置。例如,设置以下属性:
com.ibm.wsspi.security.trustassociation.initPropsFile= app_server_root/properties/myTAI.properties
com.ibm.wsspi.security.trustassociation.initPropsFile= app_server_root/myTAI.properties
作为连续的一行输入上述代码。
属性文件的位置是全限定的(例如,app_server_root/properties/myTAI.properties)。因为该位置在 WebSphere Application Server Network Deployment 环境中可能不同,所以请使用诸如 ${USER_INSTALL_ROOT} 的变量来表示 WebSphere Application Server 的安装目录。例如,如果文件名为 myTAI.properties 并位于 app_server_root/properties 目录中,请设置下列属性:
属性文件的位置是全限定的(例如,app_server_root/myTAI.properties)。因为该位置在 WebSphere Application Server Network Deployment 环境中可能不同,所以请使用诸如 ${USER_INSTALL_ROOT} 的变量来表示 WebSphere Application Server 的安装目录。例如,如果文件名为 myTAI.properties 并位于 /properties 目录中,请设置下列属性:
- com.ibm.wsspi.security.trustassociation.types = myTAItype
com.ibm.wsspi.security.trustassociation.myTAItype.config = c:/WebSphere/AppServer/properties/myTAI.properties
com.ibm.wsspi.security.trustassociation.myTAItype.config = app_server_root/myTAI.properties
- 实现该方法后,请对其进行编译。例如, app_server_root/java/bin/javac
-classpath install_root/plugins/com.ibm.ws.runtime.jar;<install_root>/dev/JavaEE/j2ee.jar
myTAIImpl.java
标识在服务器重新启动时要使用的信任关联拦截器类文件。将该文件放置在 app_server_root/classes 目录中,或使用 Java 虚拟机 (JVM) 系统属性 -Dws.ext.dirs 指定该文件的驻留位置。
复制定制信任关联拦截器类文件到产品类路径中的位置。 将这些类文件复制到 profile_root/classes 目录。
您必须将这个类文件复制到每个节点和单元的 profile_root/classes 目录。
- 重新启动所有服务器。
- 在管理控制台中删除缺省 WebSEAL 拦截器并单击新建以添加您的定制拦截器。 验证类名是用点分开的并出现在类路径中。
- 单击定制属性链接以添加初始化定制拦截器所需的其他属性。当您实现的 init(Properties) 方法按上述步骤中的描述扩展 com.ibm.wsspi.security.WebSphereBaseTrustAssociationInterceptor 时,这些属性将传递到该方法。
- 保存并同步(如果适用)该配置。
- 重新启动服务器,以使定制拦截器生效。
示例
子主题
信任关联拦截器支持主体集创建
信任关联拦截器 (TAI) com.ibm.wsspi.security.tai.TrustAssociationInterceptor 接口支持一些功能,但这些功能与现有 com.ibm.websphere.security.TrustAssociationInterceptor 接口支持的功能不同。


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