title: Jboss 7 own authenticator
body: <p>I am trying to write own authenticator which will read particular custom cookies and authenticate user based od token which is stored in that cookie. As an example I took this class: org.jboss.security.negotiation.NegotiationAuthenticator</p>
  
  <p>So I start to writing my own authenticator:</p>
  
  <p>public class SampleAuthenticator extends AuthenticatorBase{</p>
  
  <pre><code>@Override
  protected boolean authenticate(Request arg0, Response arg1, LoginConfig arg2) throws IOException {
      System.out.println("===CHECK===");
      return false;
  }
  </code></pre>
  
  <p>As you can see my class contains only needed method that must be implemented with default values.</p>
  
  <p>I have installed this authenticator as module in Jboss "modules" directory.</p>
  
  <p>Then I have added new security-domain in standalone.xml:</p>
  
  <pre><code>&lt;security-domain name="sso" cache-type="default"&gt;
                  &lt;authentication&gt;
                      &lt;login-module code="UsersRoles" flag="required" /&gt;
                  &lt;/authentication&gt;
  &lt;/security-domain&gt;
  </code></pre>
  
  <p>I have made my module as global in standalone.xml as well (in jboss domain subsystem):</p>
  
  <pre><code>&lt;global-modules&gt;
              &lt;module name="com.myexample.authenticator"/&gt;
  &lt;/global-modules&gt;
  </code></pre>
  
  <p>Now it seems that my authenticator is ready for use (just for output word "===CHECK===")</p>
  
  <p>Into my example web application I have added jboss-web.xml descriptor:</p>
  
  <pre><code>&lt;jboss-web&gt;
      &lt;security-domain&gt;sso&lt;/security-domain&gt;
      &lt;valve&gt;
          &lt;class-name&gt;com.myexample.authenticator.SampleAuthenticator&lt;/class-name&gt;
      &lt;/valve&gt;
  &lt;/jboss-web&gt;
  </code></pre>
  
  <p>My web.xml descriptor is following:</p>
  
  <pre><code>&lt;security-constraint&gt;
      &lt;web-resource-collection&gt;
          &lt;web-resource-name&gt;MyResourceName&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;user&lt;/role-name&gt;
      &lt;/auth-constraint&gt;
  &lt;/security-constraint&gt;
  &lt;login-config&gt;
      &lt;auth-method&gt;FORM&lt;/auth-method&gt;
      &lt;realm-name&gt;My kinda secure web application&lt;/realm-name&gt;
  &lt;/login-config&gt;
  &lt;security-role&gt;
      &lt;role-name&gt;user&lt;/role-name&gt;
  &lt;/security-role&gt;
  </code></pre>
  
  <p>Finally when I am trying to deploy my web application it is throwing this exception:</p>
  
  <pre><code>12:41:28,554 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-2) MSC000001: Failed to start service jboss.web.valve.myvalve: org.jboss.msc.service.StartException in service jboss.web.valve.myvalve: java.lang.ClassCastException: com.myexample.authenticator.SampleAuthenticator cannot be cast to org.apache.catalina.Valve
          at org.jboss.as.web.WebValveService.start(WebValveService.java:92)
          at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.4.GA-redhat-1.jar:1.0.4.GA-redhat-1]
          at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.4.GA-redhat-1.jar:1.0.4.GA-redhat-1]
          at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_55]
          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_55]
          at java.lang.Thread.run(Thread.java:744) [rt.jar:1.7.0_55]
  Caused by: java.lang.ClassCastException: com.myexample.authenticator.SampleAuthenticator cannot be cast to org.apache.catalina.Valve
          at org.jboss.as.web.WebValveService.start(WebValveService.java:72)
          ... 5 more
  </code></pre>
  
  <p>I am stuck at this point. I tried to reimplement some authenticators but this ClassCastException is always there.</p>
  
  <p>Can anybody help me with writing own authenticator?
  I am using Jboss EAP 6.2 with Jboss 7.1.1</p>