title: Java : Licensing a webapp. Check for license before login happens
body: <p>I want to make my webapp license protected. When any page/resource of webapp is requested, I want to first check for the license. If license is not found then I want to redirect to license upload page.</p>
  
  <p>I have created a filter which maps to all the requests where I can check for license and redirect if necessary.
  The problem is that my webapp has security constraint of login authentication.
  see web.xml at the end for more information.</p>
  
  <p>Because of the security constraint, all the requests are first intercepted by login authentication and then forwarded to my filter. However, I want to check for license before the login can happen.</p>
  
  <p>Here is a related question I asked. </p>
  
  <p><a href="https://stackoverflow.com/questions/34429932/java-intercept-all-requests-before-they-go-to-login-authentication/34431075#34431075">Java : Intercept all requests before they go to login authentication</a></p>
  
  <p>Prioritizing filter over the security constraint seems to be impossible. So, I want to ask is there any other way I can approach this use case?</p>
  
  <blockquote>
    <p>web.xml</p>
  </blockquote>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
      xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
      id="WebApp_ID" version="2.5"&gt;
      &lt;display-name&gt;Tango&lt;/display-name&gt;
  
      &lt;filter&gt;
          &lt;filter-name&gt;SalsaValidationFilter&lt;/filter-name&gt;
          &lt;filter-class&gt;net.semandex.salsa.validationFilters.SalsaValidationFilter&lt;/filter-class&gt;
      &lt;/filter&gt;
  
      &lt;filter-mapping&gt;
          &lt;filter-name&gt;SalsaValidationFilter&lt;/filter-name&gt;
          &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
          &lt;!-- &lt;servlet-name&gt;SalsaValidationServlet&lt;/servlet-name&gt; --&gt;
          &lt;dispatcher&gt;REQUEST&lt;/dispatcher&gt;
      &lt;/filter-mapping&gt;
  
      &lt;session-config&gt;
          &lt;session-timeout&gt;20&lt;/session-timeout&gt;
      &lt;/session-config&gt;
  
      &lt;security-constraint&gt;
          &lt;web-resource-collection&gt;
              &lt;web-resource-name&gt;Login page images&lt;/web-resource-name&gt;
              &lt;url-pattern&gt;/images/salsadb-logo2.png&lt;/url-pattern&gt;
              &lt;url-pattern&gt;/images/salsa-icon.png&lt;/url-pattern&gt;
              &lt;url-pattern&gt;/images/shadow_box.png&lt;/url-pattern&gt;
              &lt;url-pattern&gt;/images/header.png&lt;/url-pattern&gt;
              &lt;url-pattern&gt;/images/bg.png&lt;/url-pattern&gt;
              &lt;url-pattern&gt;/css/splash.css&lt;/url-pattern&gt;
              &lt;url-pattern&gt;/WEB-INF/licenseValidation.html&lt;/url-pattern&gt;
              &lt;url-pattern&gt;/auth/licenseValidation.html&lt;/url-pattern&gt;
          &lt;/web-resource-collection&gt;
      &lt;/security-constraint&gt;
  
      &lt;security-constraint&gt;
          &lt;web-resource-collection&gt;
              &lt;web-resource-name&gt;The entire webapp&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;SalsaUser&lt;/role-name&gt;
          &lt;/auth-constraint&gt;
      &lt;/security-constraint&gt;
  
      &lt;security-role&gt;
          &lt;role-name&gt;SalsaUser&lt;/role-name&gt;
      &lt;/security-role&gt;
  
      &lt;login-config&gt;
          &lt;auth-method&gt;FORM&lt;/auth-method&gt;
          &lt;form-login-config&gt;
            &lt;form-login-page&gt;/auth/login.jsp&lt;/form-login-page&gt;
            &lt;form-error-page&gt;/auth/loginError.jsp&lt;/form-error-page&gt;
          &lt;/form-login-config&gt;
  
          &lt;realm-name&gt;mongo_login&lt;/realm-name&gt;
      &lt;/login-config&gt;
  &lt;/web-app&gt;
  </code></pre>