Package org.apache.wiki.auth.login

# Class AbstractLoginModule

java.lang.Object
org.apache.wiki.auth.login.AbstractLoginModule

All Implemented Interfaces:
  `LoginModule`

Direct Known Subclasses:
  `AnonymousLoginModule`, `CookieAssertionLoginModule`, `CookieAuthenticationLoginModule`, `UserDatabaseLoginModule`, `WebContainerLoginModule`

public abstract class AbstractLoginModule extends Object implements LoginModule
Abstract JAAS `LoginModule`that implements base functionality. The methods `login()` and `commit()` must be implemented by subclasses. The default implementations of `initialize(Subject, CallbackHandler, Map, Map)`, `abort()` and `logout()` should be sufficient for most purposes.

Since:
  2.3

## Field Summary

Fields
Modifier and Type
Field
Description
`protected CallbackHandler`
`m_handler`
`protected Map<String,?>`
`m_options`
`protected Collection<Principal>`
`m_principals`
Implementing classes should add Principals to this collection; these will be added to the principal set when the overall login succeeds.
`protected Map<String,?>`
`m_state`
`protected Subject`
`m_subject`
`protected static final String`
`NULL`

## Constructor Summary

Constructors
Constructor
Description
`AbstractLoginModule()`

## Method Summary

Modifier and Type
Method
Description
`final boolean`
`abort()`
Aborts the login; called if the LoginContext's overall authentication failed.
`final boolean`
`commit()`
Commits the login.
`final void`
`initialize(Subject subject, CallbackHandler callbackHandler, Map<String,?> sharedState, Map<String,?> options)`
Initializes the LoginModule with a given `Subject`, callback handler, options and shared state.
`abstract boolean`
`login()`
Logs in the user by calling back to the registered CallbackHandler with a series of callbacks.
`final boolean`
`logout()`
Logs the user out.

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

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

## Field Details

### m_handler

protected CallbackHandler m_handler

### m_options

protected Map<String,?> m_options

### m_principals

protected Collection<Principal> m_principals
Implementing classes should add Principals to this collection; these will be added to the principal set when the overall login succeeds. These Principals will be added to the Subject during the `commit()` phase of login.

### m_state

protected Map<String,?> m_state

### m_subject

protected Subject m_subject

### NULL

protected static final String NULL

See Also:
  - Constant Field Values

## Constructor Details

### AbstractLoginModule

public AbstractLoginModule()

## Method Details

### abort

public final boolean abort()
Aborts the login; called if the LoginContext's overall authentication failed. (the relevant REQUIRED, REQUISITE, SUFFICIENT and OPTIONAL LoginModules did not succeed). Specifically, it removes Principals from the Subject that are associated with the individual LoginModule; these will be those contained in `m_principals`. It always returns `true`.

Specified by:
  `abort` in interface `LoginModule`
Returns:
  True, always.
See Also:
  - `LoginModule.abort()`

### commit

public final boolean commit()
Commits the login. If the overall login method succeeded, adds principals to the Subject's set; generally, these will be the user's actual Principal, plus one or more Role principals. The state of the `m_principals` member variable is consulted to determine whether to add the principals. If its size is 0 (because the login failed), the login is considered to have failed; in this case, all principals in `m_principals` are removed from the Subject's set. Otherwise, the principals added to `m_principals` in the `login()` method are added to the Subject's set.

Specified by:
  `commit` in interface `LoginModule`
Returns:
  `true` if the commit succeeded, or `false` if the previous call to `login()` failed
See Also:
  - `LoginModule.commit()`

### initialize

public final void initialize(Subject subject, CallbackHandler callbackHandler, Map<String,?> sharedState, Map<String,?> options)
Initializes the LoginModule with a given `Subject`, callback handler, options and shared state. In particular, the member variable `m_principals` is initialized as a blank Set.

Specified by:
  `initialize` in interface `LoginModule`
Parameters:
  `subject` -
  `callbackHandler` -
  `sharedState` -
  `options` -
See Also:
  - `LoginModule.initialize(javax.security.auth.Subject, javax.security.auth.callback.CallbackHandler, java.util.Map, java.util.Map)`

### login

public abstract boolean login() throws LoginException
Logs in the user by calling back to the registered CallbackHandler with a series of callbacks. If the login succeeds, this method returns `true`

Specified by:
  `login` in interface `LoginModule`
Returns:
  `true` if the commit succeeded, or `false` if this LoginModule should be ignored.
Throws:
  `LoginException` - if the authentication fails
See Also:
  - `LoginModule.login()`

### logout

public final boolean logout()
Logs the user out. Removes all principals in `m_principals` from the Subject's principal set.

Specified by:
  `logout` in interface `LoginModule`
Returns:
  `true` if the commit succeeded, or `false` if this LoginModule should be ignored
See Also:
  - `LoginModule.logout()`