title: JBoss5 CLIENT-CERT authentication getting HTTP Status 401 - Cannot authenticate with the provided credentials error
body: <p>I want mutual authentication using CLIENT-CERT and also specify role with Restful Jersey web service.
  Here clientAuth="false" in server.xml</p>
  
  <p>My web.xml is as follow:</p>
  
  <pre><code>&lt;servlet&gt;
      &lt;servlet-name&gt;jersey-serlvet&lt;/servlet-name&gt;
      &lt;servlet-class&gt;
          com.sun.jersey.spi.container.servlet.ServletContainer
       &lt;/servlet-class&gt;
      &lt;init-param&gt;
       &lt;param-name&gt;com.sun.jersey.config.property.packages&lt;/param-name&gt;
         &lt;param-value&gt;com.aditi.test&lt;/param-value&gt;
  &lt;/init-param&gt;
  &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
  &lt;/servlet&gt;
  &lt;login-config&gt;
      **&lt;auth-method&gt;CLIENT-CERT&lt;/auth-method&gt;**
      &lt;realm-name&gt;JMX Console&lt;/realm-name&gt;
  &lt;/login-config&gt; 
  &lt;security-role&gt;
  &lt;description&gt;Admin role&lt;/description&gt;
  &lt;role-name&gt;admin&lt;/role-name&gt;        
  &lt;/security-role&gt;
  </code></pre>
  
  <p>My jboss-web.xml is:</p>
  
  <pre><code>&lt;jboss-web&gt;
  &lt;security-domain&gt;java:/jaas/client_cert&lt;/security-domain&gt;
  &lt;/jboss-web&gt;
  </code></pre>
  
  <p>Also I have created server.keystore, server.truststore, client.keystore, client.truststore and client.p12 using keytool and openssl.</p>
  
  <p>Changes in login-config.xml is:</p>
  
  <pre><code>&lt;application-policy name="client_cert"&gt;
  &lt;authentication&gt;
  &lt;login-module code="org.jboss.security.auth.spi.UsersRolesLoginModule" flag="required"&gt;
      &lt;module-option name="usersProperties"&gt;
       props/cert-users.properties&lt;/module-option&gt;
      &lt;module-option name="rolesProperties"&gt;
        props/cert-roles.properties&lt;/module-option&gt;
      &lt;module-option name="verifier"&gt;
       com.secure.CertVerifier&lt;/module-option&gt;
    &lt;/login-module&gt;
  &lt;/authentication&gt;
  </code></pre>
  
  <p></p>
  
  <p>And jboss-service.xml contains:</p>
  
  <pre><code>&lt;mbean code="org.jboss.security.plugins.JaasSecurityDomain" name="jboss.security:service=SecurityDomain"&gt;
  &lt;constructor&gt;
      &lt;arg type="java.lang.String" value="client_cert"/&gt;
  &lt;/constructor&gt;
  &lt;attribute name="KeyStoreURL"&gt;${jboss.server.home.dir}/conf/server.keystore&lt;/attribute&gt;
  &lt;attribute name="KeyStorePass"&gt;base123&lt;/attribute&gt;
  &lt;attribute name="TrustStoreURL"&gt;${jboss.server.home.dir}/conf/server.truststore&lt;/attribute&gt;
  &lt;attribute name="TrustStorePass"&gt;base123&lt;/attribute&gt;
  &lt;depends&gt;jboss.security:service=JaasSecurityManager&lt;/depends&gt;
  </code></pre>
  
  <p></p>
  
  <p>and com.secure.CertVerifier is:</p>
  
  <pre><code>public class CertVerifier implements X509CertificateVerifier {
  @Override
  public boolean verify(X509Certificate xcert, String arg1, KeyStore arg2,
          KeyStore arg3) {
      System.out.println("hi verify");
      Principal pr=xcert.getSubjectDN();
      System.out.println("hi dear "+pr.getName());
      return true;
  }}
  </code></pre>
  
  <p>also cert-users.properties file is empty.
  and cert-roles.properties file is:</p>
  
  <p>CN\=ClientHost,\ OU\=test,\ O\=test,\ L\=pune,\ ST\=mah,\ C=IN=admin</p>
  
  <p>Now If i access RESTful web service through browser i want to import client.p12 certificate and after that i will getting error like </p>
  
  <pre><code>HTTP Status 401 - Cannot authenticate with the provided credentials
  </code></pre>
  
  <p>How I resolve it? I want to authentication as well as authorization using CLIENT-CERT in Jboss5. What is going wrong here? How does it work?</p>