为 Liberty 开发定制 TAI
要开发定制信任关联拦截器 (TAI) 类,可以实现 Liberty 服务器随附的 com.ibm.wsspi.security.tai.TrustAssociationInterceptor 接口。
关于此任务
信任关联接口是一个服务提供者 API,支持将第三方安全服务与 Liberty 服务器集成在一起。处理 Web 请求时,Liberty 服务器会向外调用,并将 HttpServletRequest 和 HttpServletResponse 传递到信任关联拦截器。HttpServletRequest 会调用拦截器的 isTargetInterceptor 方法来查看拦截器是否可以处理该请求。在选择相应的信任关联拦截器之后,HttpServletRequest 会由拦截器的 negotiateValidateandEstablishTrust 方法加以处理,而且结果是在 TAIResult 对象中返回。可以将您自己的逻辑代码添加到定制 TAI 类的每个方法。
另请参阅 TAI 接口的 Java™ API 文档。每个 Liberty API 的 Java API 文档均于在线 IBM® Knowledge Center 的编程接口 (Javadoc) 部分中详细说明,而且还可以在 ${wlp.install.dir}/dev 目录的某个 javadoc 子目录下的单独 .zip 文件中找到。
示例
下面是称为 SimpleTAI 的样本 TAI 类,它也列出 TrustAssociationInterceptor 接口中的所有可用方法。
package com.ibm.websphere.security.sample;
import java.util.Properties;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.ibm.websphere.security.WebTrustAssociationException;
import com.ibm.websphere.security.WebTrustAssociationFailedException;
import com.ibm.wsspi.security.tai.TAIResult;
import com.ibm.wsspi.security.tai.TrustAssociationInterceptor;
public class SimpleTAI implements TrustAssociationInterceptor {
public SimpleTAI() {
super();
}
/*
* @see com.ibm.wsspi.security.tai.TrustAssociationInterceptor#isTargetInterceptor
* (javax.servlet.http.HttpServletRequest)
*/
public boolean isTargetInterceptor(HttpServletRequest req)
throws WebTrustAssociationException {
//Add logic to determine whether to intercept this request
return true;
}
/*
* @see com.ibm.wsspi.security.tai.TrustAssociationInterceptor#negotiateValidateandEstablishTrust
* (javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
*/
public TAIResult negotiateValidateandEstablishTrust(HttpServletRequest req,
HttpServletResponse resp) throws WebTrustAssociationFailedException {
// Add logic to authenticate a request and return a TAI result.
String tai_user = "taiUser";
return TAIResult.create(HttpServletResponse.SC_OK, tai_user);
}
/*
* @see com.ibm.wsspi.security.tai.TrustAssociationInterceptor#initialize(java.util.Properties)
*/
public int initialize(Properties arg0)
throws WebTrustAssociationFailedException {
return 0;
}
/*
* @see com.ibm.wsspi.security.tai.TrustAssociationInterceptor#getVersion()
*/
public String getVersion() {
return "1.0";
}
/*
* @see com.ibm.wsspi.security.tai.TrustAssociationInterceptor#getType()
*/
public String getType() {
return this.getClass().getName();
}
/*
* @see com.ibm.wsspi.security.tai.TrustAssociationInterceptor#cleanup()
*/
public void cleanup()
{}
}
下一步做什么
将 TAI 类添加至 Liberty 服务器。
使用下列其中一种方法将 TAI 类添加至 Liberty 服务器:
- 将定制 TAI 类放入 JAR 文件(例如 simpleTAI.jar),然后使 JAR 文件可作为共享库提供。请参阅为 Liberty 配置 TAI。
- 将定制 TAI 类打包为功能部件。请参阅将定制 TAI 作为 Liberty 功能部件来开发。