You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by negora <pu...@negora.com> on 2021/07/01 10:53:29 UTC
Create client that uses NTLM authentication
Hi:
I need to create a client to call a web service that requires NTLM
authentication (Microsoft Dynamic NAV). This client will be used from an
EJB module (Jakarta EE), in a Wildfly application server.
To create my proxy, I've used the WSDL2Java program, through the Maven
"cxf-codegen-plugin". Then, I've read this documentation:
*
https://cxf.apache.org/docs/client-http-transport-including-ssl-support.html#ClientHTTPTransport(includingSSLsupport)-NTLMAuthentication
*
https://cwiki.apache.org/confluence/display/CXF20DOC/Asynchronous+Client+HTTP+Transport
With regard to the synchronous mode, I've needed to look for information
outside of the official documentation (at StackOverflow), because the
former gives instructions only for Java 5. With Java 11 I've needed to
create a custom "java.net.Authenticator" and set it as the default
authenticator:
NTLMAuthenticator authenticator = new NTLMAuthenticator ();
Authenticator.setDefault (authenticator);
Setting the "BindingProvider.USERNAME_PROPERTY" and
"BindingProvider.PASSWORD_PROPERTY" properties hasn't worked. Indeed,
after setting the default "Authenticator", I've not needed to set them
at all.
After solving that, I've been able to make my client work in both modes,
synchronous and asynchronous, as a standalone application and also from
my EJB module. But, finally, I've chosen the asynchronous mode because I
need to run the client inside a server, and I think that setting a
default "Authenticator" for the whole JVM might interfere with other
parts that use "HttpURLConnection" (for example, other client that uses
different NTLM credentials).
Am I right? Or is there a way to use the synchronous mode without
setting a default "Authenticator"?
Thank you!
Best regards,
Negora.