Last Updated: February 25, 2016
· skuro

Dummy authentication realm in Jetty XML

If your webapp configures an authentication realm such as:


you need to tell Jetty what authenticator will be used for Foobar realm. Jetty provides a HashLoginService that keeps user in an in-memory hash map, which is quite handy for test and dummy services.

The following jetty.xml configures the authentication realm to load users from a properties file and with a hard coded user as well:

<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "">

<Configure class="org.eclipse.jetty.server.Server">
    <Call name="addBean">
            <New class="">
                <Set name="name">Foobar</Set>
                <Set name="config"></Set>
                <Set name="refreshInterval">0</Set>
                <Call name="putUser">
                        <New class="">