Sunday, January 9, 2011

Adding NTLM authentication

I had some trouble adding NTLM authentication as it doesn't seem to be there by default. I need the authentication as I have to be able to access a Microsoft IIS Web Server using standard windows user authentication.

In order to do this I
- used an example from :
     http://hc.apache.org/httpcomponents-client-ga/ntlm.html

- downloaded the latest JCIFS library from :
     http://jcifs.samba.org

- Changed the Type3Message initialisation in the JCIFSEngine class as it isn't
   supported by he version of JCIFS that I downloaded

        Type3Message t3m = new Type3Message(
                t2m,
                password,
                domain,
                username,
                workstation);

     was changed to

        Type3Message t3m = new Type3Message(
                t2m); //,
//                password,
//                domain,
//                username,
//                workstation);
        t3m.setNTResponse(Type3Message.getNTResponse(t2m, password));
        t3m.setLMResponse(Type3Message.getLMResponse(t2m, password));
        t3m.setDomain(domain);
        t3m.setUser(username);
        t3m.setWorkstation(workstation);

I don't know if that is the correct way to do it, but it works.