title: Tomcat 7 java.lang.NullPointerException when wrong credential entered using Active Directory authentification
body: <p>I am trying to use Active Directory to authenticate users on my web
  application. This is now working correctly if I use the right
  credentials, but If I fail to input the correct credentials, I get the
  following error [1] and no further attempts is allowed. I did not have
  this issue when I was only using the UserDatabaseRealm.</p>
  
  <p><strong>Edit:</strong> After upgrading to Tomcat 8.0.15 as suggested by @kotacc, I am still getting an error (see [5] below) when entering the wrong credentials. <strong>end of Edit</strong></p>
  
  <p>My server.xml is in [2] and my web.xml in [3]
  My configuration details are in [4].</p>
  
  <p>Any idea of what is wrong? Could anyone point me to the right
  documentation for this?</p>
  
  <p>regards</p>
  
  <p>Ben</p>
  
  <p>[2] here is the relevant part from my server.xml:</p>
  
  <pre><code>&lt;Realm className="org.apache.catalina.realm.LockOutRealm"&gt;
          &lt;Realm className="org.apache.catalina.realm.CombinedRealm"&gt;
          &lt;!-- This Realm uses the UserDatabase configured in the global JNDI
               resources under the key "UserDatabase".  Any edits
               that are performed against this UserDatabase are immediately
               available for use by the Realm. --&gt;
        &lt;Realm className="org.apache.catalina.realm.UserDatabaseRealm"
  resourceName="UserDatabase"/&gt;
          &lt;Realm className="org.apache.catalina.realm.JNDIRealm"
          connectionURL="ldap://someServer.mycompany.com:389"
          connectionName="OneUser@mycompany.CORP"
          connectionPassword="aPassword"
          referrals="follow"
          userBase="ou=Users,OU=somServer,DC=mycompany,DC=CORP"
          userSearch="(sAMAccountName={0})"
          userSubtree="true"
        /&gt;
       &lt;/Realm&gt;
       &lt;/Realm&gt;
  </code></pre>
  
  <p>[3] here is the relevant part from my web.xml:</p>
  
  <pre><code> &lt;security-constraint&gt;
          &lt;web-resource-collection&gt;
              &lt;web-resource-name&gt;Wildcard means whole app requires
  authentication&lt;/web-resource-name&gt;
              &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
              &lt;http-method&gt;GET&lt;/http-method&gt;
              &lt;http-method&gt;POST&lt;/http-method&gt;
          &lt;/web-resource-collection&gt;
          &lt;auth-constraint&gt;
              &lt;role-name&gt;*&lt;/role-name&gt;
          &lt;/auth-constraint&gt;
  
          &lt;user-data-constraint&gt;
              &lt;transport-guarantee&gt;NONE&lt;/transport-guarantee&gt;
          &lt;/user-data-constraint&gt;
      &lt;/security-constraint&gt;
      &lt;security-constraint&gt;
      &lt;web-resource-collection&gt;
          &lt;web-resource-name&gt;Public&lt;/web-resource-name&gt;
          &lt;description&gt;Matches a few special pages.&lt;/description&gt;
          &lt;url-pattern&gt;/index.html&lt;/url-pattern&gt;
      &lt;/web-resource-collection&gt;
          &lt;!-- No auth-constraint means everybody has access! --&gt;
      &lt;/security-constraint&gt;
  
      &lt;login-config&gt;
          &lt;auth-method&gt;BASIC&lt;/auth-method&gt;
      &lt;/login-config&gt;
  
    &lt;security-role&gt;
     &lt;description&gt;this is the standard user&lt;/description&gt;
     &lt;role-name&gt;*&lt;/role-name&gt;
   &lt;/security-role&gt;
  </code></pre>
  
  <p>[4] This is on Tomcat 7.0.57 running on Windows 7 64 bit</p>
  
  <pre><code>&gt; java -version java version "1.7.0_71" Java(TM) SE Runtime Environment
  &gt; (build 1.7.0_71-b14) Java HotSpot(TM) 64-Bit Server VM (build
  &gt; 24.71-b01, mixed mode)
  </code></pre>
  
  <p>[1] here is the error:</p>
  
  <pre><code>java.lang.NullPointerException
  org.apache.catalina.realm.JNDIRealm.getUser(JNDIRealm.java:1303)
  org.apache.catalina.realm.JNDIRealm.getUser(JNDIRealm.java:1253)
  org.apache.catalina.realm.JNDIRealm.authenticate(JNDIRealm.java:1194)
  org.apache.catalina.realm.JNDIRealm.authenticate(JNDIRealm.java:1069)
  org.apache.catalina.realm.CombinedRealm.authenticate(CombinedRealm.java:146)
  org.apache.catalina.realm.CombinedRealm.authenticate(CombinedRealm.java:146)
  org.apache.catalina.realm.LockOutRealm.authenticate(LockOutRealm.java:180)
  org.apache.catalina.authenticator.BasicAuthenticator.authenticate(BasicAuthenticator.java:164)
  org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:575)
  org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
  org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
  org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)
  org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
  org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
  org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2466)
  org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2455)
  java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
  java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
  org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
  java.lang.Thread.run(Thread.java:745)
  </code></pre>
  
  <p>[5] here is the error with Tomcat 8.0.15:</p>
  
  <pre><code>java.lang.NullPointerException
      org.apache.catalina.realm.JNDIRealm.getUser(JNDIRealm.java:1286)
      org.apache.catalina.realm.JNDIRealm.getUser(JNDIRealm.java:1236)
      org.apache.catalina.realm.JNDIRealm.authenticate(JNDIRealm.java:1177)
      org.apache.catalina.realm.JNDIRealm.authenticate(JNDIRealm.java:1052)
      org.apache.catalina.realm.CombinedRealm.authenticate(CombinedRealm.java:157)
      org.apache.catalina.realm.CombinedRealm.authenticate(CombinedRealm.java:157)
      org.apache.catalina.realm.LockOutRealm.authenticate(LockOutRealm.java:180)
      org.apache.catalina.authenticator.BasicAuthenticator.authenticate(BasicAuthenticator.java:111)
      org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:576)
      org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
      org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
      org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:537)
      org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1085)
      org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:658)
      org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
      org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1556)
      org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1513)
      java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
      java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
      org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
      java.lang.Thread.run(Thread.java:745)
  </code></pre>