<p>I am trying to implement NTLM authentication on one of our internal sites and everything is working. The one piece of the puzzle I do not have is how to take the information from NTLM and authenticate with Active Directory.</p>

<p>There is a <a href="http://www.innovation.ch/personal/ronald/ntlm.html" rel="nofollow noreferrer">good description of NTLM</a> and the <a href="http://us1.samba.org/samba/docs/man/Samba-Developers-Guide/pwencrypt.html" rel="nofollow noreferrer">encryption used for the passwords</a>, which I used to implement this, but I am not sure of how to verify if the user's password is valid.</p>

<p>I am using ColdFusion but a solution to this problem can be in any language (Java, Python, PHP, etc).</p>

<p>Edit:</p>

<p>I am using ColdFusion on Redhat Enterprise Linux. Unfortunately we cannot use IIS to manage this and instead have to write or use a 3rd party tool for this.</p>

<hr>

<p><strong>Update</strong> - <em>I got this working and here is what I did</em></p>

<p>I went with the <a href="http://jcifs.samba.org/" rel="nofollow noreferrer">JCIFS library from samba.org.</a></p>

<blockquote>
  <p>Note that the method below will only work with NTLMv1 and <strong>DOES NOT</strong> work with NTLMv2. If you are unable to use NTLMv1 you can try <a href="http://www.ioplex.com/jespa.html" rel="nofollow noreferrer">Jespa</a>, which supports NTLMv2 but is not open source, or you can use <a href="http://spnego.sourceforge.net" rel="nofollow noreferrer">Kerberos/SPNEGO.</a></p>
</blockquote>

<p>Here is my web.xml:</p>

<pre><code>&lt;web-app&gt;
    &lt;display-name&gt;Ntlm&lt;/display-name&gt;

    &lt;filter&gt;
        &lt;filter-name&gt;NtlmHttpFilter&lt;/filter-name&gt;
        &lt;filter-class&gt;jcifs.http.NtlmHttpFilter&lt;/filter-class&gt;

        &lt;init-param&gt;
            &lt;param-name&gt;jcifs.http.domainController&lt;/param-name&gt;
            &lt;param-value&gt;dc01.corp.example.com&lt;/param-value&gt;
        &lt;/init-param&gt;
        &lt;init-param&gt;
            &lt;param-name&gt;jcifs.smb.client.domain&lt;/param-name&gt;
            &lt;param-value&gt;CORP.EXAMPLE.COM&lt;/param-value&gt;
        &lt;/init-param&gt;
    &lt;/filter&gt;

    &lt;filter-mapping&gt;
        &lt;filter-name&gt;NtlmHttpFilter&lt;/filter-name&gt;
        &lt;url-pattern&gt;/admin/*&lt;/url-pattern&gt;
    &lt;/filter-mapping&gt;
&lt;/web-app&gt;
</code></pre>

<p>Now all URLs matching <code>/admin/*</code> will require NTLM authentication.</p>

[{'answer_id': 22185, 'author': 'Portman', 'author_id': 1690, 'author_profile': 'https://Stackoverflow.com/users/1690', 'pm_score': 0, 'selected': False, 'text': '<p>Hm, I\'m not sure what you\'re trying to accomplish.</p>\n\n<p>Usually implementing NTLM on an internal site is as simple as unchecking "Enable Anonymous Access" in "Authentication and Access Control" in the "Directory Security" tab of website properties in IIS. If that is cleared, then your web application users will see a pop-up NTLM dialog.</p>\n\n<p>There\'s no need for you to write any code that interfaces with Active Directory. IIS takes care of the authentication for you.</p>\n\n<p>Can you be more specific about what you\'re trying to do?</p>\n'}, {'answer_id': 22191, 'author': 'jason saldo', 'author_id': 1293, 'author_profile': 'https://Stackoverflow.com/users/1293', 'pm_score': 2, 'selected': False, 'text': '<p>As I understand it.<br>\nNTLM is one of IIS built in authentication methods.  If the the Host is registered on the domain of said active directory, it should be automatic.  One thing to watch out for is the username should be in one of two formats.  </p>\n\n<ul>\n<li>domain\\username</li>\n<li>username@domain.tld</li>\n</ul>\n\n<p>If you are trying to go against a different active directory you should be using a forms style authentication and some LDAP code.  </p>\n\n<p>If you are trying to do the Intranet No Zero Login thing with IIS Integrated authentication </p>\n\n<ul>\n<li>the domain needs to be listed as a trusted site in IEx browser</li>\n<li>or use a url the uses the netbios name instead of the DNS name.</li>\n<li>for it to work in firefox read <a href="https://calshare.berkeley.edu/Resources0/Pages/FirefoxonWindows.aspx" rel="nofollow noreferrer">here</a></li>\n</ul>\n'}, {'answer_id': 22194, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>i assume that you are wanting get to some of  the attributes that are set against the LDAP account - role - department etc.</p>\n\n<p>for coldfusion check this out <a href="http://www.adobe.com/devnet/server_archive/articles/integrating_cf_apps_w_ms_active_directory.html" rel="nofollow noreferrer">http://www.adobe.com/devnet/server_archive/articles/integrating_cf_apps_w_ms_active_directory.html</a></p>\n\n<p>and the cfldap tag <a href="http://livedocs.adobe.com/coldfusion/6.1/htmldocs/tags-p69.htm#wp1100581" rel="nofollow noreferrer">http://livedocs.adobe.com/coldfusion/6.1/htmldocs/tags-p69.htm#wp1100581</a></p>\n\n<p>As to other languages - others will do it with there respective APIs  </p>\n'}, {'answer_id': 64075, 'author': 'Matt Everson', 'author_id': 7300, 'author_profile': 'https://Stackoverflow.com/users/7300', 'pm_score': 2, 'selected': False, 'text': '<p>The <a href="http://modntlm.sourceforge.net/" rel="nofollow noreferrer">ModNTLM</a> source for Apache may provide you with the right pointers.</p>\n\n<p>If possible, you should consider using <a href="http://grolmsnet.de/kerbtut/" rel="nofollow noreferrer">Kerberos</a> instead. It lets you authenticate Apache against AD, and it\'s a more active project space than NTLM.</p>\n'}, {'answer_id': 464096, 'author': 'user8134', 'author_id': 8134, 'author_profile': 'https://Stackoverflow.com/users/8134', 'pm_score': 4, 'selected': False, 'text': '<p>What you\'re really asking is: Is there any way to validate the "WWW-Authenticate: NTLM" tokens submitted by IE and other HTTP clients when doing Single Sign-On (SSO). SSO is when the user enters their password a "single" time when they do Ctrl-Alt-Del and the workstation remembers and uses it as necessary to transparently access other resources without prompting the user for a password again.</p>\n\n<p>Note that Kerberos, like NTLM, can also be used to implement SSO authentication. When presented with a "WWW-Authenticate: Negotiate" header, IE and other browsers will send SPNEGO wrapped Kerberos and / or NTLM tokens. More on this later but first I will answer the question as asked.</p>\n\n<p>The only way to validate an NTLMSSP password "response" (like the ones encoded in "WWW-Authenticate: NTLM" headers submitted by IE and other browsers) is with a NetrLogonSamLogon(Ex) DCERPC call with the NETLOGON service of an Active Directory domain controller that is an authority for, or has a "trust" with an authority for, the target account. Additionally, to properly secure the NETLOGON communication, Secure Channel encryption should be used and is required as of Windows Server 2008.</p>\n\n<p>Needless to say, there are very few packages that implement the necessary NETLOGON service calls. The only ones I\'m aware of are:</p>\n\n<ol>\n<li><p>Windows (of course)</p></li>\n<li><p>Samba - Samba is a set of software programs for UNIX that implements a number of Windows protocols including the necessary NETLOGON service calls. In fact, Samba 3 has a special daemon for this called "winbind" that other programs like PAM and Apache modules can (and do) interface with. On a Red Hat system you can do a <code>yum install samba-winbind</code> and <code>yum install mod_auth_ntlm_winbind</code>. But that\'s the easy part - setting these things up is another story.</p></li>\n<li><p>Jespa - Jespa (<a href="http://www.ioplex.com/jespa.html" rel="noreferrer">http://www.ioplex.com/jespa.html</a>) is a 100% Java library that implements all of the necessary NETLOGON service calls. It also provides implementations of standard Java interfaces for authenticating clients in various ways such as with an HTTP Servlet Filter, SASL server, JAAS LoginModule, etc.</p></li>\n</ol>\n\n<p>Beware that there are a number of NTLM authentication acceptors that do not implement the necessary NETLOGON service calls but instead do something else that ultimately leads to failure in one scenario or another. For example, for years, the way to do this in Java was with the NTLM HTTP authentication Servlet Filter from a project called JCIFS. But that Filter uses a man-in-the-middle technique that has been responsible for a long-standing "hiccup bug" and, more important, it does not support NTLMv2. For these reasons and others it is scheduled to be removed from JCIFS. There are several projects that have been unintentionally inspired by that package that are now also equally doomed. There are also a lot of code fragments posted in Java forums that decode the header token and pluck out the domain and username but do absolutely nothing to actually validate the password responses. Suffice it to say, if you use one of those code fragments, you might as well walk around with your pants down.</p>\n\n<p>As I eluded to earlier, NTLM is only one of several Windows Security Support Providers (SSP). There\'s also a Digest SSP, Kerberos SSP, etc. But the Negotiate SSP, which is also known as SPNEGO, is usually the provider that MS uses in their own protocol clients. The Negotiate SSP actually just negotiates either the NTLM SSP or Kerberos SSP. Note that Kerberos can only be used if both the server and client have accounts in the target domain and the client can communicate with the domain controller sufficiently to acquire a Kerberos ticket. If these conditions are not satisfied, the NTLM SSP is used directly. So NTLM is by no means obsolete.</p>\n\n<p>Finally, some people have mentioned using an LDAP "simple bind" as a make-shift password validation service. LDAP is not really designed as an authentication service and for this reason it is not efficient. It is also not possible to implement SSO using LDAP. SSO requires NTLM or SPNEGO. If you can find a NETLOGON or SPNEGO acceptor, you should use that instead.</p>\n\n<p>Mike</p>\n'}, {'answer_id': 3344275, 'author': 'dB.', 'author_id': 123094, 'author_profile': 'https://Stackoverflow.com/users/123094', 'pm_score': 1, 'selected': False, 'text': '<p>Check out <a href="http://waffle.codeplex.com" rel="nofollow noreferrer">Waffle</a>. It implements SSO for Java servers using Win32 API. There\'re servlet, tomcat valve, spring-security and other filters.</p>\n'}, {'answer_id': 19856659, 'author': 'Imran Vohra', 'author_id': 1629418, 'author_profile': 'https://Stackoverflow.com/users/1629418', 'pm_score': 1, 'selected': False, 'text': '<p>You can resolve the Firefox authentication popup by performing the following steps in Firefox:</p>\n\n<ol>\n<li>Open Mozilla Firefox</li>\n<li>Type about:config in address bar</li>\n<li>Enter network.automatic-ntlm-auth.trusted-uris in Search texfield</li>\n<li>Double click preference name and key in your server name as String value</li>\n<li>Close the tab</li>\n<li>Restart Firefox.</li>\n</ol>\n'}]
['https://Stackoverflow.com/questions/22135', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/309844/']