public abstract class LoginContext extends Object
Subject
and can be discarded
afterwards. Usually it contains some credentials such as username and password. Note that
generally it is no a good idea to store those type of credentials in the session, so if you plan
on keeping this context in the session be sure to clear them before you return a Subject in
login()
. Some applications will require you to login with two or more different
LoginContexts before a user is fully authenticated. For that purpose a sortOrder is available in
the context. which is used in descending order to pass authentication requests to the subjects
until one of them authenticates. Sort orders are >=0 and are not required to have an interval
of 1. For example 0, 5,6 are all perfectly legal sort orders for one user. Duplicates are also
allowed, in that case they are queried in reverse order of login. The context also contains a
flag to indicate if an additional login is allowed. Note that both the sort order and the
additional login flag must be constant. Also note that all LoginContexts of the same class and
with the same sort order are equal, thus for logoff you do not need to keep a reference to the
context but can simply use a new instance.preventsAdditionalLogins()
Constructor and Description |
---|
LoginContext()
Constructs a context for single login applications.
|
LoginContext(boolean allowAdditionalLogings)
Constructs a new context with sort order 0 and a customizable flag for preventing additional
logins.
|
LoginContext(int sortOrder)
Constructs a new context at the specified sort order.
|
LoginContext(int sortOrder,
boolean allowAdditionalLogins)
Constructs a new context with customizable sort order and flag for preventing additional
logins.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object obj)
A loginContext is equal to a LoginContext of the same class (not subclass) and level.
|
protected int |
getSortOrder()
Indicates the sort order of this context.
|
int |
hashCode() |
abstract Subject |
login()
Perform a login.
|
void |
notifyLogoff(Subject subject)
Callback to take some action after a subject has been logged off.
|
boolean |
preventsAdditionalLogins()
Signals that no additional context should be allowed to login.
|
public LoginContext()
public LoginContext(int sortOrder)
sortOrder
- a number of 0 or higher.public LoginContext(boolean allowAdditionalLogings)
allowAdditionalLogings
- indicates if this context allows multiple subjects for one user and thus allows
the user to gain more permissions on the fly.public LoginContext(int sortOrder, boolean allowAdditionalLogins)
sortOrder
- allowAdditionalLogins
- public abstract Subject login() throws LoginException
LoginException
must be thrown rather
then returning null. You should clear all sensitive data stored in this context before
returning the subject or throwing an exception.Subject
, never null.LoginException
- if an exception occurs or if the subject could not login for some other reasonprotected final int getSortOrder()
public final int hashCode()
hashCode
in class Object
Object.hashCode()
public final boolean equals(Object obj)
equals
in class Object
Object.equals(java.lang.Object)
public boolean preventsAdditionalLogins()
login()
. Note in a multi login environment you will want
your logincontext with the highest possible sort order to prevent additional logins. In a
single login environment your logincontext should always prevent additional logins.public void notifyLogoff(Subject subject)
subject
- the user that has just been logged offCopyright © 2015. All rights reserved.