vnp4vq
Last Updated: February 25, 2016
·
1.191K
· skuro

Dummy authentication realm in Jetty XML

If your webapp configures an authentication realm such as:

<login-config>
    <auth-method>DIGEST</auth-method>
    <realm-name>Foobar</realm-name>
</login-config>

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" "http://jetty.mortbay.org/configure.dtd">

<Configure class="org.eclipse.jetty.server.Server">
    <Call name="addBean">
        <Arg>
            <New class="org.eclipse.jetty.security.HashLoginService">
                <Set name="name">Foobar</Set>
                <Set name="config">foobar.properties</Set>
                <Set name="refreshInterval">0</Set>
                <Call name="putUser">
                    <Arg>dummy</Arg>
                    <Arg>
                        <New class="org.eclipse.jetty.util.security.Password">
                            <Arg>secret</Arg>
                        </New>
                    </Arg>
                    <Arg></Arg>
                </Call>
            </New>
        </Arg>
    </Call>
</Configure>