org.eclipse.jetty.security

## Class JDBCLoginService

- java.lang.Object
- - org.eclipse.jetty.util.component.AbstractLifeCycle
  - - org.eclipse.jetty.security.MappedLoginService
    - - org.eclipse.jetty.security.JDBCLoginService

All Implemented Interfaces:
  LoginService, LifeCycle

    public class JDBCLoginService
    extends MappedLoginService

HashMapped User Realm with JDBC as data source. JDBCLoginService extends HashULoginService and adds a method to fetch user information from database. The login() method checks the inherited Map for the user. If the user is not found, it will fetch details from the database and populate the inherited Map. It then calls the superclass login() method to perform the actual authentication. Periodically (controlled by configuration parameter), internal hashes are cleared. Caching can be disabled by setting cache refresh interval to zero. Uses one database connection that is initialized at startup. Reconnect on failures. authenticate() is 'synchronized'. An example properties file for configuration is in $JETTY_HOME/etc/jdbcRealm.properties

Version:
  $Id: JDBCLoginService.java 4792 2009-03-18 21:55:52Z gregw $

### Nested Class Summary

### Nested classes/interfaces inherited from class org.eclipse.jetty.security.MappedLoginService

`MappedLoginService.Anonymous, MappedLoginService.KnownUser, MappedLoginService.RolePrincipal, MappedLoginService.UserPrincipal`

### Nested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle

`AbstractLifeCycle.AbstractLifeCycleListener`

### Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.LifeCycle

`LifeCycle.Listener`

### Field Summary

### Fields inherited from class org.eclipse.jetty.security.MappedLoginService

`_identityService, _name, _users`

### Fields inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle

`_listeners, FAILED, RUNNING, STARTED, STARTING, STOPPED, STOPPING`

### Constructor Summary

Constructors
Constructor and Description
`JDBCLoginService()`
`JDBCLoginService(String name)`
`JDBCLoginService(String name, IdentityService identityService, String config)`
`JDBCLoginService(String name, String config)`

### Method Summary

Methods
`void` `connectDatabase()` (re)Connect to database with parameters setup by loadConfig()
`protected void` `doStart()`
`String` `getConfig()`
`protected UserIdentity` `loadUser(String username)`
`protected void` `loadUsers()`
`UserIdentity` `login(String username, Object credentials)` Login a user.
`void` `setConfig(String config)` Load JDBC connection configuration from properties file.

### Methods inherited from class org.eclipse.jetty.security.MappedLoginService

`doStop, getIdentityService, getName, getUsers, logout, putUser, putUser, removeUser, setIdentityService, setName, setUsers, toString, validate`

### Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle

`addLifeCycleListener, getState, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Constructor Detail

#### JDBCLoginService

    public JDBCLoginService()
                     throws IOException

Throws:
  `IOException`

#### JDBCLoginService

    public JDBCLoginService(String name)
                     throws IOException

Throws:
  `IOException`

#### JDBCLoginService

    public JDBCLoginService(String name,
                    String config)
                     throws IOException

Throws:
  `IOException`

#### JDBCLoginService

    public JDBCLoginService(String name,
                    IdentityService identityService,
                    String config)
                     throws IOException

Throws:
  `IOException`

### Method Detail

#### doStart

    protected void doStart()
                    throws Exception

Overrides:
  `doStart` in class `MappedLoginService`
Throws:
  `Exception`
See Also:
  `MappedLoginService.doStart()`

#### getConfig

    public String getConfig()

#### setConfig

    public void setConfig(String config)

Load JDBC connection configuration from properties file.

Parameters:
  `config` - Filename or url of user properties file.

#### connectDatabase

    public void connectDatabase()

(re)Connect to database with parameters setup by loadConfig()

#### login

    public UserIdentity login(String username,
                     Object credentials)

Description copied from interface: `LoginService`
Login a user.

Specified by:
  `login` in interface `LoginService`
Overrides:
  `login` in class `MappedLoginService`
Parameters:
  `username` - The user name
  `credentials` - The users credentials
Returns:
  A UserIdentity if the credentials matched, otherwise null
See Also:
  `LoginService.login(java.lang.String, java.lang.Object)`

#### loadUsers

    protected void loadUsers()

Specified by:
  `loadUsers` in class `MappedLoginService`

#### loadUser

    protected UserIdentity loadUser(String username)

Specified by:
  `loadUser` in class `MappedLoginService`