在我开始添加 WSS4J 之前,我在使用 CXF 设置合同第一组 Web 服务方面做得很好。
我正在尝试调试发送密码并登录soap标头。当我在 WSPasswordCallback 类中调用 getPassword() 时,我得到了 null。我可以从肥皂信封中看到密码已发送。
这篇 2009 年发布的帖子http://old.nabble.com/PasswordDigest-and-PasswordText-difference-td24475866.html让我想知道我是否缺少(需要创建)一个 UsernameTokenHandler。
如果这是真的,有人可以指出我将如何在 spring/cxf bean xml 文件中配置它吗?
任何意见或建议将不胜感激。
这是有问题的Java文件:
package com.netcentric.security.handlers;
import java.io.IOException;
import javax.annotation.Resource;
import javax.com.urity.auth.callback.Callback;
import javax.com.urity.auth.callback.CallbackHandler;
import javax.com.urity.auth.callback.UnsupportedCallbackException;
import org.apache.ws.com.urity.WSPasswordCallback;
public class ServicePWCallback implements CallbackHandler
{
@Override
public void handle(Callback[] callbacks) throws IOException,
UnsupportedCallbackException {
try {
for (int i = 0; i < callbacks.length; i++) {
if (callbacks[i] instanceof WSPasswordCallback) {
WSPasswordCallback pc = (WSPasswordCallback) callbacks[i];
sString login = pc.getIdentifier();
String password = pc.getPassword();
// password is null, not the expected myPASSWORD**1234
int n = pc.getUsage();
// this is 2 == WSPasswordCallback.USERNAME_TOKEN
//...
CXF/Spring 配置文件:
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:jaxws="http://cxf.apache.org/jaxws" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd" default-dependency-check="none" default-lazy-init="false"> <import resource="classpath:META-INF/cxf/cxf.xml" /> <import resource="classpath:META-INF/cxf/cxf-servlet.xml" /> <bean id="serverPasswordCallback" class="com.netcentric.security.handlers.ServicePWCallback"/> <bean id="wss4jInInterceptor" class="org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor"> <构造函数参数> <地图> <entry key="action" value="UsernameToken"/> <entry key="passwordType" value="PasswordText"/> <entry key="passwordCallbackRef"> <ref bean="serverPasswordCallback"/> </entry> </地图> </constructor-arg> </豆> <jaxws:endpoint id="FederationImpl" 实施者="com.netcentric.services.federation.FederationImpl" endpointName="e:federation" serviceName="e:federation" 地址=“联邦” xmlns:e="urn:federation.services.netcentric.sec"> <jaxws:inInterceptors> <bean class="org.apache.cxf.binding.soap.saaj.SAAJInInterceptor"/> <ref bean="wss4jInInterceptor"/> </jaxws:inInterceptors> </jaxws:endpoint> </beans
肥皂消息:
<?xml 版本="1.0" 编码="UTF-8"?> <soapenv:信封 xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http: //www.w3.org/2001/XMLSchema-instance"> <soapenv:标题> <wsse:comurity xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wscomurity-comext-1.0.xsd" soapenv:mustUnderstand="1"> <wsu:Timestamp xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wscomurity-utility-1.0.xsd" wsu:Id="Timestamp-16757598" > <wsu:Created>2011-09-22T18:21:23.345Z</wsu:Created> <wsu:Expires>2011-09-22T18:26:23.345Z</wsu:Expires> </wsu:时间戳> <wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wscomurity-utility-1.0.xsd" wsu:Id="UsernameToken-16649441" > <wsse:用户名>pam</wsse:用户名> <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">myPASSWORD**1234</wsse:密码> </wsse:UsernameToken> </wsse:comurity> </soapenv:标题> <soapenv:正文> <getVersion xmlns="urn:federation.services.netcentric.com"> <getVersionRequest/> </getVersion> </soapenv:正文> </soapenv:信封>