[jcifs] NTLM Authentication for HTTP Connections on GlassFish (or any servlet container)

Michael B Allen ioplex at gmail.com
Fri Jun 26 17:08:38 GMT 2009

On Fri, Jun 26, 2009 at 5:58 AM, Allan Lykke
Christensen<allan.lykke.christensen at gmail.com> wrote:
> I've created a class that connects to an IIS website requiring NTLM
> authentication. The Java class is based on the following example
> (http://jcifs.samba.org/src/examples/NtlmHttpClient.java):
> The example works fine when executed from the command prompt, but as soon as
> I try to use the same code in a servlet container (specifically GlassFish),
> I get an IOException containing the message "Server returned HTTP response
> code: 401 for URL: ....".

I'm surprised that code works at all. The HttpURLConnection that comes
with JCIFS is a wrapper around the builtin Java HTTP client but the
builtin client supports NTLM so it's not clear how the two interact.

Java's builtin HTTP client supports at least NTLMv1 authentication so
the JCIFS NTLM HTTP client is obsolete.

So no one uses that code and futhermore all HTTP related code will be
removed from JCIFS.

Or you can use jcifs.smb.NtlmContext.initSecContext to get the tokens
necessary to perform NTLM HTTP authentication explicitly but you'll
need to find an HTTP client or write one yourself.


Michael B Allen
Java Active Directory Integration

More information about the jcifs mailing list