【发布时间】:2015-01-26 16:48:14
【问题描述】:
我正在使用 Apache CFX 编写一个到 HP Quality Center 的 REST 连接器。当向服务器发出请求时,我想使用 CFX 基础架构进行抢先式身份验证
HP Quality Center 使用基于 Basic 的身份验证机制。要进行身份验证,将使用标准基本身份验证标头将获取请求发送到 http:///qcbin/authentication-point/authenticate。然后服务器返回一个必须包含在所有后续请求中的 cookie(“LWSSO”)。在进行身份验证之前从服务器请求资源将导致带有 WWW-Authenticate 标头的 401,其中包含身份验证点 URI(例如 LWSSO realm="http://:80/qcbin/authentication-point)。
理想情况下,我想创建一个 CFX HttpAuthProvider 或拦截器,它通过拦截 401 响应、解析 WWW-Authenticate 标头并在为所有后续请求缓存 cookie 之前在身份验证点 URI 上执行请求来处理身份验证。
这将允许我使用工厂模式创建一个干净的基于代理的 API。例如:
public QualityCenter create(String url, String username, String password) {
JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
bean.setAddress(url);
bean.setUsername(username);
bean.setPassword(password);
bean.setServiceClass(QualityCenter.class);
// TODO: Setup authentication modules here that use AuthPolicy for credentials.
return bean.create(QualityCenter.class);
}
我似乎无法弄清楚这是否可行以及在哪里最好地实现该功能。
【问题讨论】:
标签: apache authentication cookies reset basic-authentication