title: HTTP Status 404 after deploying a web application with a custom realm to Tomcat 6
body: <p>I develop a web application for Tomcat 6, and I'm face to face with a problem I don't know how to resolve. Let's consider the following small scenario. Imagine that it's required to authenticate users not just by user and password, the authentication is only granted if some extra conditions are true (e.g. user, password, and his IP address matches). As far I understood, Tomcat introduced the concept of realms. A simple <code>JDBCRealm</code> was enough for the application, because the user and password pair was checked only until the moment. Now it's required to check the IP address too. I have written a simple test class that extends the <code>JDBCRealm</code> class:</p>
  
  <pre><code>package security;
  
  import org.apache.catalina.realm.JDBCRealm;
  import org.apache.log4j.Logger;
  
  import java.security.Principal;
  import java.sql.Connection;
  
  public class ApplicationRealm extends JDBCRealm {
  
      protected final Logger logger = Logger.getLogger(this.getClass());
  
      @Override
      public synchronized Principal authenticate(Connection connection, String userName, String credentials) {
          logger.info("custom realm test, the authentication will be failed just for testing");
          return null;
      }
  
  }
  </code></pre>
  
  <p>And then I have tried to bind this realm class using the <code>context.xml</code>:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;Context&gt;
      &lt;Realm className="security.ApplicationRealm" connectionName="${user}" connectionPassword="${password}"
          connectionURL="${url}${database}" debug="99" driverName="${driver}" roleNameCol="role" userCredCol="pw"
          userNameCol="login" userRoleTable="users_roles" userTable="users"/&gt;
  &lt;/Context&gt;
  </code></pre>
  
  <p>The deployment of the web application succeeds, but when I try to access the login page, Tomcat returns a 404 page (I suspect the root of the problem is the <code>className</code> attribute in the <code>Realm</code> node):</p>
  
  <p><code>HTTP Status 404 -</code><br>
  <code>type Status report</code><br>
  <code>message</code><br>
  <code>description The requested resource () is not available.</code><br>
  <code>Apache Tomcat/6.0.24</code></p>
  
  <p>How can I bind a custom <code>JDBCRealm</code> descendant in <code>context.xml</code>? Maybe I'm totally wrong trying to use the <code>JDBCRealm</code> for this, but I can't see the correct solution anyway.</p>
  
  <p>Thanks in advance.</p>