Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jetty-users] Need Help Configuring A Security Handler for Embedded Jetty

I posted this question on StackOverflow ( https://stackoverflow.com/questions/70278074/override-login-service-for-embedded-jetty ) but I'm hoping someone here can help as well. I'm trying to do some integration testing on a jetty application with basic authentication. I'm using a jetty-web.xml file to configure the security handler like this:

<Configure id="eyerep-data" class="org.eclipse.jetty.webapp.WebAppContext">

<Set name="contextPath">/eyerep-data</Set>

<Set name="war"><SystemProperty name="jetty.base" default="./webapps" />/eyerep-data/eyerep-data.war</Set>

<Get name="securityHandler">

    <Set name="loginService">

      <New class="org.eclipse.jetty.security.HashLoginService">

            <Set name="name">EyeRep</Set>

            <Set name="config"><SystemProperty name="jetty.home" default="."/>/etc/realm.properties</Set>

      </New>

    </Set>

  </Get>

</Configure>



That works for production, but for testing, I'm using an embedded jetty server so I need to use a different config path for the login service.


The problem I'm running into is that there doesn't seem to be any way to override just the config path. if I try to do something like: 


WebAppContext context = new WebAppContext();

loginService = ((HashLoginService)context.getSecurityHandler().getLoginService());

loginService.setConfig("src/test/resources/realm.properties");


I found that there is no point where that code can succeed. If I run it before calling 'server.start()' the login service has not been initialized yet and I get an NPE. If I run it after the call to 'server.start()', it is too late. The server will already have tried and failed to setup the user store using the invalid config path.


I'm at a bit of a loss here. I don't see anything equivalent to context.setOverrideDescriptors() for jetty-web.xml. Is there any way to do this without completely replacing the work done by jetty-web.xml with manual code?



Back to the top