Jetty Logo
Version: 9.4.5.v20170502
Contact the core Jetty developers at www.webtide.com

private support for your internal/customer projects ... custom extensions and distributions ... versioned snapshots for indefinite support ... scalability guidance for your apps and Ajax/Comet projects ... development services for sponsored feature development

Chapter 7. Configuring Security

Table of Contents

Using the $\{jetty.home} and $\{jetty.base} Concepts to Configure
Authentication
Limiting Form Content
Aliased Files and Symbolic links
Secure Password Obfuscation
JAAS Support
Spnego Support

Using the $\{jetty.home} and $\{jetty.base} Concepts to Configure

Security

Jetty implementations are structured around the idea of ${jetty.base} and ${jetty.home} directories.

  • ${jetty.home} is the directory location for the Jetty distribution (the binaries) should not be modified.
  • ${jetty.base} is the directory location for your customizations to the distribution.

This separation:

  • Allows you to manage multiple Jetty installations.
  • Makes it simple to retain your current configuration when you upgrade your Jetty distribution.

For more information, see Managing Jetty Base and Jetty Home.

Further, Jetty 9.1 parameterized all of the standard configuration XMLs. For SSL, parameters are now properties in the start.ini or start.d\ssl.ini, reducing to eliminating the need to edit XML files.

Instead of explicitly listing all the libraries, properties, and XML files for a feature, Jetty 9.1 introduced a new module system. A module is defined in a modules/*.mod file, including the libraries, dependencies, XML, and template INI files for a Jetty feature. Thus you can use a single --module=name command line option as the equivalent of specifying many --lib=location, feature.xml, name=value arguments for a feature and all its dependencies. Modules use their dependencies to control the ordering of libraries and XML files. For more information, see Managing Startup Modules.

Configuring SSL in with modules

This page describes how to configure SSL in Jetty with modules. It provides an example of using the ${jetty.home} and ${jetty.base} to maximum effect. It also includes a detailed explanation of how modules work.

This example assumes you have the jetty-distribution unpacked in /home/user/jetty-distribution-{VERSION}. It also assumes you are using start.ini to configure your server features.

  1. Create a base directory anywhere.

    [/home/user]$ mkdir my-base
    [/home/user]$ cd my-base
  2. Add the modules for SSL, HTTP, and webapp deployment. Adding modules in this way will append the associated module properties to the ${jetty.base}/start.ini file.

    [my-base]$ java -jar /home/user/jetty-distribution-9.4.5.v20170502/start.jar --add-to-start=http,https,deploy
    
    ssl             initialised in ${jetty.base}/start.ini (appended)
    ssl             enabled in     ${jetty.base}/start.ini
    DOWNLOAD: https://github.com/eclipse/jetty.project/raw/master/jetty-server/src/main/config/etc/keystore to etc/keystore
    server          initialised in ${jetty.base}/start.ini (appended)
    server          enabled in     ${jetty.base}/start.ini
    http            initialised in ${jetty.base}/start.ini (appended)
    http            enabled in     ${jetty.base}/start.ini
    server          enabled in     ${jetty.base}/start.ini
    deploy          initialised in ${jetty.base}/start.ini (appended)
    deploy          enabled in     ${jetty.base}/start.ini
    MKDIR: ${jetty.base}/webapps
    server          enabled in     ${jetty.base}/start.ini
  3. Look at your directory.

    [my-base]$ ls -la
    total 20
    drwxrwxr-x   4 user group 4096 Oct  8 06:55 ./
    drwxr-xr-x 103 user group 4096 Oct  8 06:53 ../
    drwxrwxr-x   2 user group 4096 Oct  8 06:55 etc/
    -rw-rw-r--   1 user group  815 Oct  8 06:55 start.ini
    drwxrwxr-x   2 user group 4096 Oct  8 06:55 webapps/
  4. Copy your WAR files into webapps.

    [my-base]$ ls -la
    [my-base]$ cp ~/code/project/target/gadget.war webapps/
  5. Copy your keystore into place.

    [my-base]$ cp ~/code/project/keystore etc/keystore
  6. Edit the start.ini to configure your SSL settings.

    [my-base]$ cat start.ini
  7. Initialize module ssl.

    --module=ssl
  8. Define the port to use for secure redirection.

    jetty.secure.port=8443
  9. Set up a demonstration keystore and truststore.

    jetty.keystore=etc/keystore
    jetty.truststore=etc/keystore
  10. Set the demonstration passwords.

    jetty.keystore.password=OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4
    jetty.keymanager.password=OBF:1u2u1wml1z7s1z7a1wnl1u2g
    jetty.truststore.password=OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4
  11. Initialize the module server.

    --module=server
    threads.min=10
    threads.max=200
    threads.timeout=60000
    #jetty.host=myhost.com
    jetty.dump.start=false
    jetty.dump.stop=false
  12. Initialize module http.

    --module=http
    jetty.http.port=8080
    http.timeout=30000
  13. Initialize module deploy.

    --module=deploy

Look at the configuration you have at this point.

[my-base]$ java -jar /home/user/jetty-distribution-9.4.5.v20170502/start.jar --list-config

Java Environment:
-----------------
 java.home=/usr/lib/jvm/jdk-7u21-x64/jre
 java.vm.vendor=Oracle Corporation
 java.vm.version=23.21-b01
 java.vm.name=Java HotSpot(TM) 64-Bit Server VM
 java.vm.info=mixed mode
 java.runtime.name=Java(TM) SE Runtime Environment
 java.runtime.version=1.7.0_21-b11
 java.io.tmpdir=/tmp

Jetty Environment:
-----------------
 jetty.home=/home/user/jetty-distribution-9.4.5.v20170502
 jetty.base=/home/user/my-base
 jetty.version=9.4.5.v20170502

JVM Arguments:
--------------
 (no jvm args specified)

System Properties:
------------------
 jetty.base = /home/user/my-base
 jetty.home = /home/user/jetty-distribution-9.4.5.v20170502

Properties:
-----------
 http.timeout = 30000
 jetty.dump.start = false
 jetty.dump.stop = false
 jetty.keymanager.password = OBF:1u2u1wml1z7s1z7a1wnl1u2g
 jetty.keystore = etc/keystore
 jetty.keystore.password = OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4
 jetty.http.port = 8080
 jetty.secure.port = 8443
 jetty.truststore = etc/keystore
 jetty.truststore.password = OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4
 threads.max = 200
 threads.min = 10
 threads.timeout = 60000

Jetty Server Classpath:
-----------------------
Version Information on 11 entries in the classpath.
: order presented here is how they would appear on the classpath.
      changes to the --module=name command line options will be reflected here.
 0:                    3.1.0 | ${jetty.home}/lib/servlet-api-3.1.jar
 1:                  3.1.RC0 | ${jetty.home}/lib/jetty-schemas-3.1.jar
 2:                9.4.5.v20170502 | ${jetty.home}/lib/jetty-http-9.4.5.v20170502.jar
 3:                9.4.5.v20170502 | ${jetty.home}/lib/jetty-continuation-9.4.5.v20170502.jar
 4:                9.4.5.v20170502 | ${jetty.home}/lib/jetty-server-9.4.5.v20170502.jar
 5:                9.4.5.v20170502 | ${jetty.home}/lib/jetty-xml-9.4.5.v20170502.jar
 6:                9.4.5.v20170502 | ${jetty.home}/lib/jetty-util-9.4.5.v20170502.jar
 7:                9.4.5.v20170502 | ${jetty.home}/lib/jetty-io-9.4.5.v20170502.jar
 8:                9.4.5.v20170502 | ${jetty.home}/lib/jetty-servlet-9.4.5.v20170502.jar
 9:                9.4.5.v20170502 | ${jetty.home}/lib/jetty-webapp-9.4.5.v20170502.jar
10:                9.4.5.v20170502 | ${jetty.home}/lib/jetty-deploy-9.4.5.v20170502.jar

Jetty Active XMLs:
------------------
 ${jetty.home}/etc/jetty.xml
 ${jetty.home}/etc/jetty-http.xml
 ${jetty.home}/etc/jetty-ssl.xml
 ${jetty.home}/etc/jetty-deploy.xml

Now start Jetty.

[my-base]$ java -jar /home/user/jetty-distribution-9.4.5.v20170502/start.jar
2013-10-08 07:06:55.837:INFO:oejs.Server:main: jetty-9.4.5.v20170502
2013-10-08 07:06:55.853:INFO:oejdp.ScanningAppProvider:main: Deployment monitor [file:/home/user/my-base/webapps/] at interval 1
2013-10-08 07:06:55.872:INFO:oejs.ServerConnector:main: Started ServerConnector@72974691{HTTP/1.1}{0.0.0.0:8080}

Reviewing the Configuration

The following sections review this configuration.

$\{jetty.base} and $\{jetty.home}

First notice the separation of ${jetty.base} and ${jetty.home}.

  • ${jetty.home} is where your distribution lies, unchanged, unedited.
  • ${jetty.base} is where your customizations are.

Modules

Notice that you have --module=<name> here and there; you have wrapped up the goal of a module (libs, configuration XMLs, and properties) into a single unit, with dependencies on other modules.

You can see the list of modules by appending --list-modules to the command line.

[my-base] $ java -jar ../jetty-distribution-9.4.5.v20170502/start.jar --list-modules

These are the modules by name, the libraries they bring in, the XML configurations they use, the other modules they depend on (even optional ones), and if the module is in use, where it was enabled.

While you can manage the list of active modules yourself, it is much easier to edit the ${jetty.base}/start.ini.

If you want to start using a new module:

[my-base] $ java -jar ../jetty-distribution-9.4.5.v20170502/start.jar --add-to-start=https

This adds the --module= lines and associated properties (the parameterized values mentioned above), to your start.ini.

Important

Do not edit the modules and XML files in the ${jetty.home} directory; there is no need to be moving or copying them unless you want to make your own modules or override the behavior of an existing module.

Notice that your ${jetty.base}/start.ini has no references to the XML files. That’s because the module system and its graph of dependencies now dictate all of the XML files, and their load order. Much more information on modules can be found in the section on Managing Startup Modules.

Parameters

Next is parameterizing all of the standard configuration XMLs. In this example all of the SSL parameters are now just properties in the start.ini, reducing or eliminating the need to edit XML files.

Overriding $\{jetty.home} in $\{jetty.base}

Finally, you can override anything you see in ${jetty.home} in ${jetty.base}, even XML configurations and libraries.

For more information on the start.jar in 9.1, see Using start.jar.

Summary of Configuring SSL

  1. Download and unpack Jetty into /home/user/jetty-distribution-{VERSION}.
  2. Go to your base directory and just use the distribution, no editing.

    [my-base]$ java -jar /home/user/jetty-distribution-9.4.5.v20170502/start.jar
    • The Jetty distribution provides, out of the box, the XML configuration files, in this case jetty-http.xml and jetty-ssl.xml. These can be found in the ${jetty.home}/etc/ directory.
    • We have parameterized all of the configurable values in those XMLs. You can now set the values using simple properties, either on the command line, or within the ${jetty.base}/start.ini.
    • When you activate the module for HTTP or HTTPs, Jetty automatically adds the appropriate libraries and XML to start Jetty. Unless you have a highly custom setup (such as listening on two different ports, using SSL on each, each with its own keystore and configuration), there is no need to muck around in XML files.
  3. Use modules to configure HTTPS:

    • http → server
    • https → ssl → server

      You can find the details about the modules in ${jetty.home}/modules/. For SSL they include modules/http.mod, modules/https.mod, modules/ssl.mod, and modules/server.mod.

      Ideally, this level of detail is not important to you. What is important is that you want to use HTTPS and want to configure it. You accomplish that by adding the --module=https to your start.ini. By default, the module system keeps things sane, and transitively includes all dependent modules as well.

You can see what the configuration looks like, after all of the modules are resolved, without starting Jetty via:

[my-base] $ java -jar ../jetty-distribution-9.4.5.v20170502/start.jar --list-config

Just because the JARs exist on disk does not mean that they are in use. The configuration controls what is used.

Use the --list-config to see the configuration. Notice that only a subset of the JARs from the distribution are in use. The modules you have enabled determine that subset.

[my-base]$ java -jar ~/jetty-distribution-9.4.5.v20170502/start.jar --list-config

See an error or something missing? Contribute to this documentation at Github!(Generated: 2017-05-02)