title: Setting request Header in server before Authentication Happens in Keycloak
body: <p>I'm using keycloak header based authentication to secure a REST API.
  There I want set a request header field (basically keycloak Autharization Header) before authication happes.</p>
  
  <p>Another appocach for this is exlained here : <a href="https://stackoverflow.com/questions/51387730/how-to-get-javax-servlet-filter-called-before-keycloak-authentication">How to get javax.servlet.Filter called before Keycloak Authentication</a></p>
  
  <p>In this try I tried to call the overriden <code>HeaderBasedKeycloakConfigResolver's</code> resolve method and after tempering the <code>web.xml</code>. I could note that it can be called before the authentication happens. I read some request header values also but there is no setter to set the request headers to there (to <code>org.keycloak.adapters.spi.HttpFacade.Request</code>).</p>
  
  <p>Looking for a hint on setting a Request Header before Keycloak Auth happens in this way or another?</p>
  
  <ul>
  <li>Key claok version : 3.1.0.Final</li>
  </ul>
  
  <p><strong>HeaderBasedKeycloakConfigResolver.java</strong> </p>
  
  <pre><code>public class HeaderBasedKeycloakConfigResolver implements KeycloakConfigResolver {
  
      @Override
      public KeycloakDeployment resolve(Request request) {
  
          String uri = request.getURI();
          logger.info("resolve().uri : " + uri);
  
          String auth_key = request.getHeader("auth_key");
          logger.info("resolve().auth_key : " + auth_key);
  
          request.setHeader("Autherization","&lt;auth value&gt;"); // there's no this like setter
  
          KeycloakDeployment deployment = cache.get(applicationId);
          --build deployment using the keycloak.json"
  
          return deployment;
      }
  
  }
  </code></pre>
  
  <p><strong>web.xml</strong></p>
  
  <pre class="lang-xml prettyprint-override"><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"
      xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
      version="3.0"&gt;
  
      &lt;!-- more security-constraint --&gt;
  
      &lt;!-- keycloak --&gt;
  
      &lt;context-param&gt;
          &lt;param-name&gt;keycloak.config.resolver&lt;/param-name&gt;
          &lt;param-value&gt;package.to.class.HeaderBasedKeycloakConfigResolver&lt;/param-value&gt;
      &lt;/context-param&gt;
  
      &lt;security-constraint&gt;
          &lt;web-resource-collection&gt;
              &lt;web-resource-name&gt;REST endpoints&lt;/web-resource-name&gt;
              &lt;url-pattern&gt;/ep-name/resource-name&lt;/url-pattern&gt;
          &lt;/web-resource-collection&gt;
          &lt;auth-constraint&gt;
              &lt;role-name&gt;resource-name&lt;/role-name&gt;
          &lt;/auth-constraint&gt;
      &lt;/security-constraint&gt;
  
      &lt;!-- more security-constraint --&gt;
      &lt;!-- more security-constraint --&gt;
      &lt;!-- more security-constraint --&gt;
  
       &lt;login-config&gt;
          &lt;auth-method&gt;KEYCLOAK&lt;/auth-method&gt;
          &lt;realm-name&gt;realm-name&lt;/realm-name&gt;
      &lt;/login-config&gt;
  
      &lt;security-role&gt;
          &lt;role-name&gt;role-name-for-resource-1&lt;/role-name&gt;
          &lt;role-name&gt;role-name-for-resource-2&lt;/role-name&gt;
          &lt;!-- more security-role --&gt;
          &lt;!-- more security-role --&gt;
          &lt;!-- more security-role --&gt;
      &lt;/security-role&gt;
  
      &lt;listener&gt;
          &lt;listener-class&gt;
              org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap&lt;/listener-class&gt;
      &lt;/listener&gt;
  
      &lt;servlet&gt;
          &lt;servlet-name&gt;resteasy-servlet&lt;/servlet-name&gt;
          &lt;servlet-class&gt;
              org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher&lt;/servlet-class&gt;
      &lt;/servlet&gt;
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;resteasy-servlet&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/resource-path/*&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  
  &lt;/web-app&gt;
  </code></pre>