向SOAP请求中添加摘要身份验证

问题描述 投票:0回答:1

我正在尝试将摘要认证(用户名和密码)添加到我的SOAP请求中,该请求使用org.apache.cxf(3.3.2)进行类生成。我尝试使用BindingProvider附加用户名和密码,但没有成功:

MyServiceGeneratedClass soapClient = new MyServiceGeneratedClass();
MyServicePort port = soapClient.getMyServicePort();
BindingProvider bindingProvider = (BindingProvider)port;
bindingProvider.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "mySecretUsername");
bindingProvider.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "mySecretPassword");

生成的SOAP请求不包含用户名和密码。

有什么想法吗?

java wsdl cxf wsdl2java digest-authentication
1个回答
0
投票

类似职位大约是Digest Authentication With Apache CXF

也许该解决方案也可能对您有用:

MyService myService = new MyService("wsdl-url");
MyServicePort myServicePort = myService.getMyServicePort();

Client client = ClientProxy.getClient(myServicePort);
HTTPConduit http = (HTTPConduit) client.getConduit();

AuthorizationPolicy authPolicy = new AuthorizationPolicy();
authPolicy.setAuthorizationType("Digest");
authPolicy.setUserName("user");
authPolicy.setPassword("myPassword");
http.setAuthorization(authPolicy);

myServicePort.doSomething();
© www.soinside.com 2019 - 2024. All rights reserved.