Search code examples
windowsscalaauthenticationplayframeworkntlm

How to do Integrated Windows Authentication (IWA) in a scala play web application


I've tried hard to familiarize myself with the different authentication protocols for Windows (NTLM v1, NTLM v2, Keberos, LDAP..) and based on that understanding I believe NTLM (v1/2) should be the target implementations.

I have a simple web application developed in Scala Play for which I would like it to have a login feature based on the AD credentials of a user (manual or through the existing workstation session).

That being said, I am struggling to get it to work. I found a few libraries on the web mostly poorly documented and others commercial only.

A simple example, or resource as to how to get it working would massively helpful.


Solution

  • You can have a try on JCIFS, sample codes as follows:

            Config.setProperty("jcifs.smb.client.connTimeout", "1000");
            InetAddress ip = InetAddress.getByName("domainControler"); 
            UniAddress myDomain = new UniAddress(ip);
            NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication("domain_name", user_name, password);
            try{
                SmbSession.logon(myDomain, auth);
            }catch(Exception sme){
                //Login failed.
            }