{@code LoginModule} describes the interfaceimplemented by authentication technology providers. LoginModules are plugged in under applications to provide a particular type of authentication.
While applications write to the {@code LoginContext} API,authentication technology providers implement the {@code LoginModule} interface.A {@code Configuration} specifies the LoginModule(s)to be used with a particular login application. Therefore different LoginModules can be plugged in under the application without requiring any modifications to the application itself.
The {@code LoginContext} is responsible for reading the{@code Configuration} and instantiating the appropriateLoginModules. Each {@code LoginModule} is initialized witha {@code Subject}, a {@code CallbackHandler}, shared {@code LoginModule} state, and LoginModule-specific options.The {@code Subject} represents the{@code Subject} currently being authenticated and is updatedwith relevant Credentials if authentication succeeds. LoginModules use the {@code CallbackHandler} tocommunicate with users. The {@code CallbackHandler} may beused to prompt for usernames and passwords, for example. Note that the {@code CallbackHandler} may be null. LoginModuleswhich absolutely require a {@code CallbackHandler} to authenticatethe {@code Subject} may throw a {@code LoginException}. LoginModules optionally use the shared state to share information or data among themselves.
The LoginModule-specific options represent the options configured for this {@code LoginModule} by an administrator or userin the login {@code Configuration}. The options are defined by the {@code LoginModule} itselfand control the behavior within it. For example, a {@code LoginModule} may define options to support debugging/testingcapabilities. Options are defined using a key-value syntax, such as debug=true. The {@code LoginModule}stores the options as a {@code Map} so that the values maybe retrieved using the key. Note that there is no limit to the number of options a {@code LoginModule} chooses to define.
The calling application sees the authentication process as a single operation. However, the authentication process within the {@code LoginModule} proceeds in two distinct phases.In the first phase, the LoginModule's {@code login} method gets invoked by the LoginContext's{@code login} method. The {@code login}method for the {@code LoginModule} then performsthe actual authentication (prompt for and verify a password for example) and saves its authentication status as private state information. Once finished, the LoginModule's {@code login}method either returns {@code true} (if it succeeded) or{@code false} (if it should be ignored), or throws a{@code LoginException} to specify a failure.In the failure case, the {@code LoginModule} must not retry theauthentication or introduce delays. The responsibility of such tasks belongs to the application. If the application attempts to retry the authentication, the LoginModule's {@code login} method will becalled again.
In the second phase, if the LoginContext's overall authentication succeeded (the relevant REQUIRED, REQUISITE, SUFFICIENT and OPTIONAL LoginModules succeeded), then the {@code commit}method for the {@code LoginModule} gets invoked.The {@code commit} method for a {@code LoginModule} checks itsprivately saved state to see if its own authentication succeeded. If the overall {@code LoginContext} authentication succeededand the LoginModule's own authentication succeeded, then the {@code commit} method associates the relevantPrincipals (authenticated identities) and Credentials (authentication data such as cryptographic keys) with the {@code Subject}located within the {@code LoginModule}.
If the LoginContext's overall authentication failed (the relevant REQUIRED, REQUISITE, SUFFICIENT and OPTIONAL LoginModules did not succeed), then the {@code abort} method for each {@code LoginModule}gets invoked. In this case, the {@code LoginModule} removes/destroysany authentication state originally saved.
Logging out a {@code Subject} involves only one phase.The {@code LoginContext} invokes the LoginModule's {@code logout}method. The {@code logout} method for the {@code LoginModule}then performs the logout procedures, such as removing Principals or Credentials from the {@code Subject} or logging session information.
A {@code LoginModule} implementation must have a constructor withno arguments. This allows classes which load the {@code LoginModule}to instantiate it. @see javax.security.auth.login.LoginContext @see javax.security.auth.login.Configuration
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|