The LoginContext class describes the basic methods used
to authenticate Subjects and provides a way to develop an
application independent of the underlying authentication technology.
A Configuration specifies the authentication technology, or
LoginModule, to be used with a particular application.
Different LoginModules can be plugged in under an application
without requiring any modifications to the application itself.
In addition to supporting pluggable authentication, this class also supports the notion of stacked authentication. Applications may be configured to use more than one LoginModule. For example, one could configure both a Kerberos LoginModule and a smart card LoginModule under an application.
A typical caller instantiates a LoginContext with
a name and a CallbackHandler.
LoginContext uses the name as the index into a
Configuration to determine which LoginModules should be used,
and which ones must succeed in order for the overall authentication to
succeed. The CallbackHandler is passed to the underlying
LoginModules so they may communicate and interact with users
(prompting for a username and password via a graphical user interface,
for example).
Once the caller has instantiated a LoginContext,
it invokes the login method to authenticate
a Subject. The login method invokes
the configured modules to perform their respective types of authentication
(username/password, smart card pin verification, etc.).
Note that the LoginModules will not attempt authentication retries nor
introduce delays if the authentication fails.
Such tasks belong to the LoginContext caller.
If the login method returns without
throwing an exception, then the overall authentication succeeded.
The caller can then retrieve
the newly authenticated Subject by invoking the
getSubject method. Principals and Credentials associated
with the Subject may be retrieved by invoking the Subject's
respective getPrincipals, getPublicCredentials,
and getPrivateCredentials methods.
To logout the Subject, the caller calls
the logout method. As with the login
method, this logout method invokes the logout
method for the configured modules.
A LoginContext should not be used to authenticate more than one Subject. A separate LoginContext should be used to authenticate each different Subject.
The following documentation applies to all LoginContext constructors:
Subject
null Subject
and a null value is permitted,
the LoginContext instantiates a new Subject.
Configuration
If the constructor does not have a Configuration
input parameter, or if the caller specifies a null
Configuration object, the constructor uses the following call to
get the installed Configuration:
config = Configuration.getConfiguration();
For both cases,
the name argument given to the constructor is passed to the
Configuration.getAppConfigurationEntry method.
If the Configuration has no entries for the specified name,
then the LoginContext calls
getAppConfigurationEntry with the name, "other"
(the default entry name). If there is no entry for "other",
then a LoginException is thrown.
CallbackHandler
null
CallbackHandler object (and a null value is permitted),
the LoginContext queries the
auth.login.defaultCallbackHandler security property for the
fully qualified class name of a default handler
implementation. If the security property is not set,
then the underlying modules will not have a
CallbackHandler for use in communicating
with users. The caller thus assumes that the configured
modules have alternative means for authenticating the user.
java.security.Security , javax.security.auth.Subject , javax.security.auth.callback.CallbackHandler , javax.security.auth.login.Configuration , javax.security.auth.spi.LoginModule , security properties
| Modifier and Type | Class and Description |
|---|---|
| private static class | LoginContext.
LoginModule information - encapsulates Configuration info and actual module instances |
| Modifier and Type | Field and Description |
|---|---|
| private static final String | |
| private CallbackHandler | |
| private static final String | |
| private Configuration | |
| private ClassLoader | |
| private static final Debug | |
| private static final String | |
| private LoginException | |
| private LoginException | |
| private static final String | |
| private boolean | |
| private static final String | |
| private int | |
| private LoginContext. | |
| private static final String | |
| private static final WeakHashMap | |
| private final Map | |
| private Subject | |
| private boolean | |
| private boolean |
| Access | Constructor and Description |
|---|---|
| public | LoginContext(String
the name used as the index into the
name)Configuration.Instantiate a new |
| public | LoginContext(String
the name used as the index into the
name, Subject Configuration.the subject)Subject to authenticate.Instantiate a new |
| public | LoginContext(String
the name used as the index into the
name, CallbackHandler Configuration.the callbackHandler)CallbackHandler object used by
LoginModules to communicate with the user.Instantiate a new |
| public | LoginContext(String
the name used as the index into the
name, Subject Configuration.the subject, CallbackHandler Subject to authenticate.the callbackHandler)CallbackHandler object used by
LoginModules to communicate with the user.Instantiate a new |
| public | LoginContext(String
the name used as the index into the caller-specified
name, Subject Configuration.the subject, CallbackHandler Subject to authenticate,
or null.the callbackHandler, Configuration CallbackHandler object used by
LoginModules to communicate with the user, or null.the config)Configuration that lists the
login modules to be called to perform the authentication,
or null.Instantiate a new |
| Modifier and Type | Method and Description |
|---|---|
| private void | |
| public Subject | Returns: the authenticated Subject. If the caller specified a Subject to this LoginContext's constructor, this method returns the caller-specified Subject. If a Subject was not specified and authentication succeeds, this method returns the Subject instantiated and used for authentication by this LoginContext. If a Subject was not specified, and authentication fails or has not been attempted, this method returns null.Return the authenticated Subject. |
| private void | |
| private void | |
| private void | |
| public void | |
| public void | |
| private void |
| ABORT_METHOD | back to summary |
|---|---|
| private static final String ABORT_METHOD | |
| callbackHandler | back to summary |
|---|---|
| private CallbackHandler callbackHandler | |
| COMMIT_METHOD | back to summary |
|---|---|
| private static final String COMMIT_METHOD | |
| config | back to summary |
|---|---|
| private Configuration config | |
| contextClassLoader | back to summary |
|---|---|
| private ClassLoader contextClassLoader | |
| debug | back to summary |
|---|---|
| private static final Debug debug | |
| DEFAULT_HANDLER | back to summary |
|---|---|
| private static final String DEFAULT_HANDLER | |
| firstError | back to summary |
|---|---|
| private LoginException firstError | |
| firstRequiredError | back to summary |
|---|---|
| private LoginException firstRequiredError | |
| LOGIN_METHOD | back to summary |
|---|---|
| private static final String LOGIN_METHOD | |
| loginSucceeded | back to summary |
|---|---|
| private boolean loginSucceeded | |
| LOGOUT_METHOD | back to summary |
|---|---|
| private static final String LOGOUT_METHOD | |
| moduleIndex | back to summary |
|---|---|
| private int moduleIndex | |
| moduleStack | back to summary |
|---|---|
| private LoginContext. | |
| OTHER | back to summary |
|---|---|
| private static final String OTHER | |
| providersCache | back to summary |
|---|---|
| private static final WeakHashMap<ClassLoader, Set<ServiceLoader. | |
| state | back to summary |
|---|---|
| private final Map<String, ?> state | |
| subject | back to summary |
|---|---|
| private Subject subject | |
| subjectProvided | back to summary |
|---|---|
| private boolean subjectProvided | |
| success | back to summary |
|---|---|
| private boolean success | |
| LoginContext | back to summary |
|---|---|
| public LoginContext(String name) throws LoginException Instantiate a new
| |
| LoginContext | back to summary |
|---|---|
| public LoginContext(String name, Subject subject) throws LoginException Instantiate a new
| |
| LoginContext | back to summary |
|---|---|
| public LoginContext(String name, CallbackHandler callbackHandler) throws LoginException Instantiate a new
| |
| LoginContext | back to summary |
|---|---|
| public LoginContext(String name, Subject subject, CallbackHandler callbackHandler) throws LoginException Instantiate a new
| |
| LoginContext | back to summary |
|---|---|
| public LoginContext(String name, Subject subject, CallbackHandler callbackHandler, Configuration config) throws LoginException Instantiate a new
| |
| clearState | back to summary |
|---|---|
| private void clearState() | |
| getSubject | back to summary |
|---|---|
| public Subject getSubject() Return the authenticated Subject.
| |
| init | back to summary |
|---|---|
| private void init(String name) throws LoginException | |
| invoke | back to summary |
|---|---|
| private void invoke(String methodName) throws LoginException Invokes the login, commit, and logout methods from a LoginModule. | |
| loadDefaultCallbackHandler | back to summary |
|---|---|
private void loadDefaultCallbackHandler() throws LoginException
| |
| login | back to summary |
|---|---|
| public void login() throws LoginException Perform the authentication. This method invokes the This method completes a 2-phase authentication process by
calling each configured LoginModule's If the If the In the case where multiple LoginModules fail,
this method propagates the exception raised by the first
Note that if this method enters the
| |
| logout | back to summary |
|---|---|
| public void logout() throws LoginException Logout the This method invokes the Note that this method invokes all LoginModules configured for the
application regardless of their respective
| |
| throwException | back to summary |
|---|---|
| private void throwException(LoginException originalError, LoginException le) throws LoginException | |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv AppConfigurationEntry | |
| pack-priv LoginModule |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| entry | back to summary |
|---|---|
| pack-priv AppConfigurationEntry entry | |
| module | back to summary |
|---|---|
| pack-priv LoginModule module | |
| ModuleInfo | back to summary |
|---|---|
| pack-priv ModuleInfo(AppConfigurationEntry newEntry, LoginModule newModule) | |