In order to obtain the wanted behavior I extended some Spring Security classes and hack them a little bit, so I created:
- An AuthenticationEntryPoint strategy to switch between NTLM or standard login
- A custom AuthenticationProvider to prevent password checking when user authenticate with NTLM
- A custom NtlmProcessingFilter to disable NTLM authentication if a remember-me cookie is present
The thing I was unable to do is detecting if the user client is NTLM compliant before starting the NTLM challenge. Due to the way the protocol is build (and certainly for security reasons) it's impossible to know if the client is NTLM compliant before launching the challenge.
So let's took the scenario of a Google Chrome user:
- A popup (HTTP realm) authentication window is shown to the user
- He hit enter with invalid credentials (i.e. empty username/password)
- The browser is redirected to the standard html login form
By using 'remember me' the NTLM authentication won't be shown next time the user access the site due to the presence of the cookie.
If the user client is Internet Explorer no authentication window is shown because the navigator use directly the information of the logged user. If the authentication fail, then the standard html login form is displayed letting him login with other credentials.
Download
You can download a sample application including hacked class here:
http://github.com/downloads/aloiscochard/spring-security-ntlm-samples/spring-security-ntlm-samples-2.0.5.SNAPSHOT.zip