我正在使用CXF 3.1.5,试图将请求发送到STS服务器,STS服务器具有策略,相关部分如下
<wsp:Policy>
<sp:RequireThumbprintReference />
<sp:WssX509V3Token10 />
</wsp:Policy>因此,在request CXF发送到STS服务器中,签名密钥如下所示:
<wsse:SecurityTokenReference wsu:Id="...">
<wsse:KeyIdentifier EncodingType="..."ValueType="...#ThumbprintSHA1">...</wsse:KeyIdentifier>
</wsse:SecurityTokenReference>但是我想把SecurityTokenReference转换成
<wsse:SecurityTokenReference>
<wsse:Reference URI="..." ValueType="...#**X509v3**"/>
</wsse:SecurityTokenReference>它指的是BinarySecurityToken,它是一个X.509证书
那我该怎么办?我发现了一些关于PolicyBasedWSS4JOutInterceptor和PolicyBasedWSS4JInInterceptor,的东西,但不知道它们是如何工作的。
非常感谢!
发布于 2016-09-01 08:21:37
@pedrofb,非常感谢您的帮助。不幸的是,我仍然有两个BinarySecurityToken元素,并且无法使用替代策略文件。
但我在这里找到了一个解决方案:如何使用Apache以简单的方式获取传入和传出soap?
它为我提供了一个在CXF发送之前编辑soap信封的解决方案。这不是很好,但这是我找到的最好的解决办法。
发布于 2016-08-17 12:31:09
您需要一个由服务器接受的CA颁发的证书来签署SOAP请求。您可以在WSS4JOutInterceptor中使用CXF。
这是在CXF中使用WSS4J的配置。省略创建密钥存储库的部分
设置WSS4J性质 (调整策略)
outProps.put("action", "Signature");
outProps.put("user", certificateAlias);
outProps.put("passwordType", "PasswordText");
outProps.put("signaturePropFile", propertiesFile);
outProps.put("signatureKeyIdentifier","DirectReference");
outProps.put("passwordCallbackRef",clientPasswordCallback);propertiesFile包含属性文件的路径,其中配置了keystore的路径。
org.apache.ws.security.crypto.provider=org.apache.ws.security.components.crypto.Merlin
org.apache.ws.security.crypto.merlin.keystore.type=jks
org.apache.ws.security.crypto.merlin.keystore.password=changeit
org.apache.ws.security.crypto.merlin.file=keystore.jksClientPasswordCallback执行来自wss4j的回调以获取证书的密码。
public class ClientPasswordCallback implements CallbackHandler {
String password = ...; //Configure the password
public void handle(Callback[] callbacks) {
for (int i = 0; i < callbacks.length; i++) {
WSPasswordCallback pc = (WSPasswordCallback) callbacks[i];
pc.setPassword(password);
}
}
}使用WebService端口配置CXF客户端
Client client = ClientProxy.getClient(port);
Endpoint cxfEndpoint = client.getEndpoint();
WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(outProps);
cxfEndpoint.getOutInterceptors().add(wssOut);
//Include LoggingOutInterceptor to log the soap message
cxfEndpoint.getOutInterceptors().add(new LoggingOutInterceptor());最后打电话给你的服务
port.myService(); https://stackoverflow.com/questions/38987591
复制相似问题