我正在尝试将摘要式身份验证(用户名和密码(添加到我的 SOAP 请求中,该请求使用 org.apache.cxf (3.3.2( 生成类。我尝试使用绑定提供程序附加用户名和密码,但没有成功:
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 请求不包含用户和密码。
有什么想法吗?
Similiar 帖子是关于使用 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();