title: Tomcat and windows integrated authentication
body: <p>I'm developing a Java app that must run on Tomcat and I need to be able to identify the remote user who is acceding to my application web.</p>
  
  <p>This remote user is running on Windows, so I need to get his "Windows login" (the SAMAccountName Active Directory attribute).</p>
  
  <p>On IIS is easiest. I follow this <a href="https://stackoverflow.com/questions/688939/detect-user-logged-on-a-computer-using-asp-net-app">Detect user logged on a computer using ASP.NET app</a> to get the user logged</p>
  
  <p>The content of server.xml is:</p>
  
  <pre><code>&lt;Realm
      className="org.apache.catalina.realm.JNDIRealm" debug="99"
      connectionURL="ldap://DAServer:389"
      connectionName="userAuth@mydomain.local"
      connectionPassword="secret"
      referrals="follow"
      userBase="OU=mycompany,DC=mydomain,DC=local"
      userSubtree="true"
      roleBase="OU=groups,DC=mydomain,DC=local"
      roleName="name"
      roleSubtree="true"
      roleSearch="(member={0})"/&gt;
  </code></pre>
  
  <p>And the content of web.xml is:</p>
  
  <pre><code>&lt;!-- Define a Security Constraint on this Application --&gt;
      &lt;security-constraint&gt;
          &lt;web-resource-collection&gt;
          &lt;web-resource-name&gt;Entire Application&lt;/web-resource-name&gt;
              &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
          &lt;/web-resource-collection&gt;
  
          &lt;auth-constraint&gt;
              &lt;role-name&gt;myCompany Users&lt;/role-name&gt;
          &lt;/auth-constraint&gt;
      &lt;/security-constraint&gt;
  
      &lt;!-- Define the Login Configuration for this Application --&gt;
      &lt;login-config&gt;
          &lt;auth-method&gt;BASIC&lt;/auth-method&gt;
          &lt;realm-name&gt;myRealm&lt;/realm-name&gt;
      &lt;/login-config&gt;
  
      &lt;!-- Security roles referenced by this web application --&gt;
      &lt;security-role&gt;
          &lt;description&gt;The role that is required to log in to APP&lt;/description&gt;
          &lt;role-name&gt;myCompany Users&lt;/role-name&gt;
      &lt;/security-role&gt;
  </code></pre>
  
  <p>I need Automatic Login.</p>