title: spring-boot, Jetty setup results in authenticated failed for username Already authenticated as UNAUTHENTICATED
body: <p>i am doing migration from jboss to jetty and during login it fails see stacktrace bellow at the end.</p>
  <p>I am using a OncePerRequestFilter where I am invoking request.login(requestEksternSsoToken, null);</p>
  <p>and then it says I am already authenticated as UNAUTHENTICATED. What is the problem and how can I fix it ?</p>
  <pre><code>14:05:05.602 [qtp1288135425-15] DEBUG n.n.m.s.filter.OpenAMLoginFilter - Login failed.
  org.eclipse.jetty.server.Authentication$Failed: Authenticated failed for username 'AQIC5wjhfjsdhfjksdhfjadshfjdhssjdfhasdkhf'. Already authenticated as UNAUTHENTICATED
          at org.eclipse.jetty.server.Request.login(Request.java:2530)
          at xx.xxxx.xxxx.security.filter.OpenAMLoginFilter.login(OpenAMLoginFilter.java:165)
          at xx.xxx.xxxx.security.filter.OpenAMLoginFilter.handleNoExistingLogin(OpenAMLoginFilter.java:95)
          at xx.xxxxx.xxxxx.security.filter.OpenAMLoginFilter.doFilterInternal(OpenAMLoginFilter.java:71)
          at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
          at org.eclipse.jetty.servlet.FilterHolder.doFilter(FilterHolder.java:193)
          at org.eclipse.jetty.servlet.ServletHandler$Chain.doFilter(ServletHandler.java:1601)
          at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)
          at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
          at org.eclipse.jetty.servlet.FilterHolder.doFilter(FilterHolder.java:193)
          at org.eclipse.jetty.servlet.ServletHandler$Chain.doFilter(ServletHandler.java:1601)
          at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:548)
          at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
          at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:602)
          at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)
          at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:235)
          at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1624)
          at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233)
          at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1435)
          at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:188)
          at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:501)
          at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1594)
          at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:186)
          at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1350)
          at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
          at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)
          at org.eclipse.jetty.server.Server.handle(Server.java:516)
          at org.eclipse.jetty.server.HttpChannel.lambda$handle$1(HttpChannel.java:388)
          at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:633)
          at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:380)
          at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:277)
          at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311)
          at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:105)
          at org.eclipse.jetty.io.ChannelEndPoint$1.run(ChannelEndPoint.java:104)
          at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:882)
          at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:1036)
          at java.base/java.lang.Thread.run(Thread.java:829)
  </code></pre>
  <p>UPDATE:</p>
  <p>Here I have written a configuration of Jetty where I am configuring security constraint still it is throwing the same error in my filter when I attempt to invoke login.</p>
  <pre><code>@Configuration
  public class JettyConfig {
      private static final Logger logger = getLogger(JettyConfig.class);
  
      
      @Bean
      WebServerFactoryCustomizer embeddedServletContainerCustomizer(final JettyServerCustomizer jettyServerCustomizer) {
      
          return container -&gt; {
              if (container instanceof JettyServletWebServerFactory) {
                  logger.info(&quot;Adding jetty server customizer&quot;);
                  ((JettyServletWebServerFactory) container).addServerCustomizers(jettyServerCustomizer);
              }
          };
      }
  
      @Bean
      JettyServerCustomizer jettyServerCustomizer(final LoginService loginService,ConstraintSecurityHandler constraintSecurityHandler) {
          return server -&gt; {
              logger.info(&quot;Setting loginService&quot;);
              ((WebAppContext) server.getHandler()).setSecurityHandler(constraintSecurityHandler);
          };// .setSecurityHandler(constraintSecurityHandler);
      }
  
      @Bean
      ConstraintSecurityHandler constraintSecurityHandler(final LoginService loginService) {
          final ConstraintSecurityHandler securityHandler = new ConstraintSecurityHandler();
  
          securityHandler.setLoginService(loginService);
          
         Constraint constraint = new Constraint();
         constraint.setName(&quot;Auth&quot;);
         ConstraintMapping mapping = new ConstraintMapping();
         mapping.setPathSpec(&quot;/*&quot;);
         mapping.setConstraint(constraint);
         securityHandler.addConstraintMapping(mapping);
         securityHandler.setLoginService(loginService);
        
  
          return securityHandler;
      }
     
      
      @Bean
      LoginService loginService()  {
          JAASLoginService jaas = new JAASLoginService(&quot;OpenAM Realm&quot;);
          jaas.setLoginModuleName(&quot;openam&quot;);
          return jaas;
      }
  </code></pre>