# Class UnixLoginModule

java.lang.Object
com.sun.security.auth.module.UnixLoginModule

All Implemented Interfaces:
  `LoginModule`

public class UnixLoginModule extends Object implements LoginModule
This `LoginModule` imports a user's Unix `Principal` information (`UnixPrincipal`, `UnixNumericUserPrincipal`, and `UnixNumericGroupPrincipal`) and associates them with the current `Subject`.

This LoginModule recognizes the debug option. If set to true in the login Configuration, debug messages will be output to the output stream, System.out.

Since:
  1.4

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `UnixLoginModule()`
  Creates a `UnixLoginModule`.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `boolean`
  `abort()`
  Abort the authentication (second phase).
  `boolean`
  `commit()`
  Commit the authentication (second phase).
  `void`
  `initialize(Subject subject, CallbackHandler callbackHandler, Map<String,?> sharedState, Map<String,?> options)`
  Initialize this `LoginModule`.
  `boolean`
  `login()`
  Authenticate the user (first phase).
  `boolean`
  `logout()`
  Logout the user

  ### Methods declared in class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`
  Modifier and Type
  Method
  Description
  `protected Object`
  `clone()`
  Creates and returns a copy of this object.
  `boolean`
  `equals(Object obj)`
  Indicates whether some other object is "equal to" this one.
  `protected void`
  `finalize()`
  Deprecated, for removal: This API element is subject to removal in a future version.
  Finalization is deprecated and subject to removal in a future release.
  `final Class<?>`
  `getClass()`
  Returns the runtime class of this `Object`.
  `int`
  `hashCode()`
  Returns a hash code value for this object.
  `final void`
  `notify()`
  Wakes up a single thread that is waiting on this object's monitor.
  `final void`
  `notifyAll()`
  Wakes up all threads that are waiting on this object's monitor.
  `String`
  `toString()`
  Returns a string representation of the object.
  `final void`
  `wait()`
  Causes the current thread to wait until it is awakened, typically by being notified or interrupted.
  `final void`
  `wait(long timeoutMillis)`
  Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.
  `final void`
  `wait(long timeoutMillis, int nanos)`
  Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.

- ## Constructor Details

  - ### UnixLoginModule

    public UnixLoginModule()
    Creates a `UnixLoginModule`.

- ## Method Details

  - ### initialize

    public void initialize(Subject subject, CallbackHandler callbackHandler, Map<String,?> sharedState, Map<String,?> options)
    Initialize this `LoginModule`.
    Specified by:
      `initialize` in interface `LoginModule`
    Parameters:
      `subject` - the `Subject` to be authenticated.
      `callbackHandler` - a `CallbackHandler` for communicating with the end user (prompting for usernames and passwords, for example).
      `sharedState` - shared `LoginModule` state.
      `options` - options specified in the login `Configuration` for this particular `LoginModule`.

  - ### login

    public boolean login() throws LoginException
    Authenticate the user (first phase).

    The implementation of this method attempts to retrieve the user's Unix `Subject` information by making a native Unix system call.

    Specified by:
      `login` in interface `LoginModule`
    Returns:
      true in all cases (this `LoginModule` should not be ignored).
    Throws:
      `FailedLoginException` - if attempts to retrieve the underlying system information fail.
      `LoginException` - if the authentication fails

  - ### commit

    public boolean commit() throws LoginException
    Commit the authentication (second phase).

    This method is called if the LoginContext's overall authentication succeeded (the relevant REQUIRED, REQUISITE, SUFFICIENT and OPTIONAL LoginModules succeeded).

    If this LoginModule's own authentication attempt succeeded (the importing of the Unix authentication information succeeded), then this method associates the Unix Principals with the `Subject` currently tied to the `LoginModule`. If this LoginModule's authentication attempted failed, then this method removes any state that was originally saved.

    Specified by:
      `commit` in interface `LoginModule`
    Returns:
      true if this LoginModule's own login and commit attempts succeeded, or false otherwise.
    Throws:
      `LoginException` - if the commit fails

  - ### abort

    public boolean abort() throws LoginException
    Abort the authentication (second phase).

    This method is called if the LoginContext's overall authentication failed. (the relevant REQUIRED, REQUISITE, SUFFICIENT and OPTIONAL LoginModules did not succeed).

    This method cleans up any state that was originally saved as part of the authentication attempt from the `login` and `commit` methods.

    Specified by:
      `abort` in interface `LoginModule`
    Returns:
      false if this LoginModule's own login and/or commit attempts failed, and true otherwise.
    Throws:
      `LoginException` - if the abort fails

  - ### logout

    public boolean logout() throws LoginException
    Logout the user

    This method removes the Principals associated with the `Subject`.

    Specified by:
      `logout` in interface `LoginModule`
    Returns:
      true in all cases (this `LoginModule` should not be ignored).
    Throws:
      `LoginException` - if the logout fails