title: Custom Basic Authentication in Camel Jetty
body: <p>I have a <code>OSGi</code> bundle which is deployed in Apache Karaf. I am using <code>BASIC</code> authentication to check user credentials. Here is my configuration <code>Spring</code> file:</p>
  
  <pre><code>&lt;beans...&gt;
  ...
      &lt;bean id="loginService" class="org.eclipse.jetty.plus.jaas.JAASLoginService"&gt;
          &lt;property name="name" value="karaf"/&gt;
          &lt;property name="loginModuleName" value="karaf"/&gt;
          &lt;property name="roleClassNames"&gt;
              &lt;list&gt;
                  &lt;value&gt;org.apache.karaf.jaas.modules.RolePrincipal&lt;/value&gt;
              &lt;/list&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;bean id="identityService" class="org.eclipse.jetty.security.DefaultIdentityService"/&gt;
  
      &lt;bean id="constraint" class="org.eclipse.jetty.http.security.Constraint"&gt;
          &lt;property name="name" value="BASIC"/&gt;
          &lt;property name="roles" value="admin"/&gt;
          &lt;property name="authenticate" value="true"/&gt;
      &lt;/bean&gt;
  
      &lt;bean id="constraintMapping" class="org.eclipse.jetty.security.ConstraintMapping"&gt;
          &lt;property name="constraint" ref="constraint"/&gt;
          &lt;property name="pathSpec" value="/*"/&gt;
      &lt;/bean&gt;
  
      &lt;bean id="securityHandler" class="org.eclipse.jetty.security.ConstraintSecurityHandler"&gt;
          &lt;property name="authenticator"&gt;
              &lt;bean class="org.eclipse.jetty.security.authentication.BasicAuthenticator"/&gt;
          &lt;/property&gt;
          &lt;property name="constraintMappings"&gt;
              &lt;list&gt;
                  &lt;ref bean="constraintMapping"/&gt;
              &lt;/list&gt;
          &lt;/property&gt;
          &lt;property name="loginService" ref="loginService"/&gt;
          &lt;property name="strict" value="false"/&gt;
          &lt;property name="identityService" ref="identityService"/&gt;
      &lt;/bean&gt;
  
      &lt;camelContext trace="true" xmlns="http://camel.apache.org/schema/spring"&gt;
          &lt;route&gt;
              &lt;from uri="jetty:http://0.0.0.0:8282/services?handlers=securityHandler&amp;amp;matchOnUriPrefix=true"/&gt;
              &lt;transform&gt;
                  &lt;constant&gt;&amp;lt;html&gt;&amp;lt;body&gt;Hello from Fuse ESB server&amp;lt;/body&gt;&amp;lt;/html&gt;&lt;/constant&gt;
              &lt;/transform&gt;
          &lt;/route&gt;
      &lt;/camelContext&gt;
      ....
  &lt;/beans&gt;
  </code></pre>
  
  <p>When I enter this URL: <code>http://localhost:8282/services</code> in the browser I see the basic authentication window, requiring username and password. It is OK until this point. </p>
  
  <p>The user credentials is set in the <code>user.properties</code> of <code>Apache Karaf</code> <code>&amp;{base.dir}/etc/</code> directory. From there the authenticator is taking the user credentials to check. </p>
  
  <p>My problem is that I need to override somehow the authenticator to use the credentials from my database. I did not try anything yet to make this work because I have no idea where to start. I have trying searching the internet but there are no clues how to make this work or even where to start, to make this work. So if someone could point me to the right direction on how to do this, that would be very appreciated.</p>