Jetty has moved!
Jetty is a project at the Eclipse Foundation.
Homepage:http://www.eclipse.org/jetty
Downloads: http://download.eclipse.org/jetty/
Documentation:http://www.eclipse.org/jetty/documentation/current/
About:http://www.eclipse.org/jetty/about.php
Jetty Powered:http://www.eclipse.org/jetty/powered/
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 from 1 day to full product delivery
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

Realms

Security realms allow you to secure your web applications against unauthorized access. Protection is based on authentication (identifying who is requesting access to the webapp) and access control (restricting what can be accessed and how it is accessed within the webapp).

A webapp statically declares its security requirements in the web.xml file. Authentication is controlled by the <login-config> element. Access controls are specified by <security-constraint> and <security-role-ref> elements. When a request is received for a protected resource, the web container checks if the user performing the request is authenticated, and if the user has a role assignment that permits access to the requested resource.

The Servlet Specification does not address how the static security information in the WEB-INF/web.xml file is mapped to the runtime environment of the container. Jetty does this with the "realm" concept.

A realm has a unique name, and is composed of a set of users. Each user has authentication information (e.g. a password) and a set of roles associated with him/herself.

You may configure one or many different realms depending on your needs. A single realm would indicate that you wish to share common security information across all of your web applications. Distinct realms allow you to partition your security information webapp by webapp.

When a request to a web application requires authentication or authorisation, Jetty will use the <login-config><realm-name> element in the web.xml file to perform an exact match to a realm defined in a jetty xml configuration file (or programmatically).

Realm definitions in jetty xml configuration files are placed in a section like this:

Alternatively, you may define a realm for just a single webapp in a context deployment file:

Jetty provides a number of different realm types from which you can choose.

HashUserRealm

This realm is a simple realm whose autentication and authorisation information is stored in a properties file. Each line in the file contains a username, a password, and 0 or more role assignments. The format is:

where:

  • username is the user's unique identity
  • password is the user's (possibly obfuscated or MD5 encrypted) password
  • rolename is the user's role

For example:

Contents of property file

The HashUserRealm is configured with a name and a reference to the location of the properties file:

You can also configure it to check the properties file regularly for changes and reload when changes
are detected. The reloadInterval is in seconds:

JDBCUserRealm

In this implementation, authentication and role information is stored in a database accessed via JDBC. A properties file defines the JDBC connection and database table information. Below is an example of a properties file for this realm implementation:

The format of the database tables is:

users

id

user

pwd

user_roles

user_id

role_id

roles

id

role

Where:

  • users is a table containing one entry for every user consisting of:
    • id - the unique identity of a user
    • user - the name of the user
    • pwd - the user's password (possibily obfuscated or MD5 encrypted)
  • user-roles is a table containing one row for every role granted to a user:
    • user_id - the unique identity of the user
    • role_id - the role for a user
  • roles is a a table containing one role for every role in the system:
    • id is the unique identifier of a role
    • role is a human-readable name for a role

The pseudo-sql to set up each of these tables would look like:

users
user_roles
roles

A JDBCRealm is defined with the name of the realm and the location of the properties file describing the database:

Please also see the page on JAAS authentication and authorization with Jetty.

  • No labels
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 from 1 day to full product delivery