|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object SK.gnome.dwarf.auth.login.GenericLoginModule
This class provides a generic login module.
The validate(String, char[])
method must be implemented by all extending classes.
This method should validate the user according to the given username and password.
The password can be tested via the checkPassword(String, char[])
method using
the given PasswordEncoder
implementation. The default password encoder used is the
MD5PasswordEncoder
, but other implementations may be specified also via the
encoder option key in the module configuration. Use a full name of the encoder
class as the key value.
The option key debug can be also specified for a modules based on this class.
See the debug(String)
and isDebugOn()
methods for the exact meaning.
The default key value is false.
The option key ignorecase can be specified for a modules based on this class, too.
The isIgnoreCaseOn()
method may be consulted by the subclasses to decide whether or
not the module may perform case-insensitive logins. The default key value is false.
A sample login module configuration entry may look like this:
Test { SK.gnome.dwarf.auth.login.PlaintextLoginModule required debug="true" ignorecase="true" encoder="SK.gnome.dwarf.auth.login.CryptPasswordEncoder"; };
An option key ident may be also supported for a particular module implementation.
If it is set to "true", the module should be able to perform identification instead
of an authentication. To support this, the validate(String, char[])
method must be
implemented in a way that if the password argument is null, it will only test the
given user for existence and eventually return its various identities in the array of principal
objects. In this case the password check must be bypassed by the method. This enables the
application code just to test if the given user is valid, and eventually to obtain also its
various security roles. This is suitable in the situations when we need to validate a user
without knowing any of her security credentials (password, certificate, etc.) However, subjects
processed by this type of authentication must not be regarder as a fully authenticated subjects.
The option key value is therefore false by default.
A sample login module configuration entry enabling the identification feature:
Ident { SK.gnome.dwarf.auth.login.MyLoginModule required ident="true"; };
A sample code using the identification and authentication:
Subject subject = new Subject(); // performs only identification try { login("Ident", subject, new BasicCallbackHandler("joe"); // no password is given // user is valid } catch (LoginException e) { // user is not valid } subject = new Subject(); // performs full authentication try { login("Ident", subject, new BasicCallbackHandler("joe", "password"); // user is authenticated } catch (LoginException e) { // user is not authenticated }
Field Summary | |
protected java.lang.Class |
encoder
The password encoder used by this module. |
Constructor Summary | |
GenericLoginModule()
|
Method Summary | |
boolean |
abort()
This method is called if the LoginContext's overall authentication failed (the relevant REQUIRED, REQUISITE, SUFFICIENT and OPTIONAL login modules did not succeed). |
boolean |
commit()
This method is called if the LoginContext's overall authentication succeeded (the relevant REQUIRED, REQUISITE, SUFFICIENT and OPTIONAL login modules succeeded). |
protected void |
debug(java.lang.String message)
Prints a debugging message to the standard output. |
protected boolean |
getBooleanOption(java.lang.String name,
boolean defaultValue)
Returns an option key value as a boolean. |
protected int |
getIntOption(java.lang.String name,
int defaultValue)
Returns an option key value as an integer. |
protected java.lang.String |
getStringOption(java.lang.String name,
java.lang.String defaultValue)
Returns an option key value as a string. |
protected boolean |
checkPassword(java.lang.String encoded,
char[] plain)
Checks the given password. |
void |
initialize(javax.security.auth.Subject subject,
javax.security.auth.callback.CallbackHandler callbackHandler,
java.util.Map sharedState,
java.util.Map options)
Initializes this login module. |
protected boolean |
isDebugOn()
Whether the debugging messages are enabled. |
protected boolean |
isIdentOn()
Whether the identification feature is enabled. |
protected boolean |
isIgnoreCaseOn()
Whether the module may perform a case-insensitive logins. |
boolean |
login()
Authenticates the user. |
boolean |
logout()
Logouts the user. |
protected abstract java.security.Principal[] |
validate(java.lang.String username,
char[] password)
Validates the given user. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected java.lang.Class encoder
Constructor Detail |
public GenericLoginModule()
Method Detail |
public void initialize(javax.security.auth.Subject subject, javax.security.auth.callback.CallbackHandler callbackHandler, java.util.Map sharedState, java.util.Map options)
initialize
in interface javax.security.auth.spi.LoginModule
subject
- the subject to be authenticatedcallbackHandler
- the callbackHandler for getting the username and passwordsharedState
- shared login module stateoptions
- options specified in the login configuration for this particular
login modulepublic boolean login() throws javax.security.auth.login.LoginException
This method uses NameCallback and PasswordCallback to gather the
user credentials via CallbackHandler, then it calls the validate(String, char[])
method to perform the actual user validation.
login
in interface javax.security.auth.spi.LoginModule
javax.security.auth.login.FailedLoginException
- if the authentication fails
javax.security.auth.login.LoginException
- if this login module is unable to perform the authenticationpublic boolean commit() throws javax.security.auth.login.LoginException
If this login module's own authentication attempt succeeded (checked by retrieving the
private state saved by the login()
method), then this method associates all
principal objects returned from the validate(String, char[])
method with the
Subject instance.
If this login module's own authentication attempt failed, then this method removes
any state that was originally saved.
commit
in interface javax.security.auth.spi.LoginModule
javax.security.auth.login.LoginException
- if the commit failspublic boolean abort() throws javax.security.auth.login.LoginException
If this login module's own authentication attempt succeeded (checked by retrieving the
private state saved by the login()
and commit()
methods), then this method
cleans up any state that was originally saved.
abort
in interface javax.security.auth.spi.LoginModule
javax.security.auth.login.LoginException
- if the abort fails.public boolean logout() throws javax.security.auth.login.LoginException
This method removes the principal objects that were added by the commit()
method from the Subject instance.
logout
in interface javax.security.auth.spi.LoginModule
javax.security.auth.login.LoginException
- if the logout failsprotected java.lang.String getStringOption(java.lang.String name, java.lang.String defaultValue)
If no option with the given name can be found, the defaultValue is returned.
name
- the option's namedefaultValue
- the default value
protected int getIntOption(java.lang.String name, int defaultValue)
If no option with the given name can be found, the defaultValue is returned.
name
- the option's namedefaultValue
- the default value
protected boolean getBooleanOption(java.lang.String name, boolean defaultValue)
Returns true if the option is found and its value equals to "true" or "on", otherwise returns false
name
- the option's namedefaultValue
- the default value
protected void debug(java.lang.String message)
The message is printed only if the isDebugOn()
method returns true.
message
- debugging messageprotected boolean isDebugOn()
Returns true if the debugging messages were enabled for this module via the debug option key, otherwise returns false.
protected boolean isIdentOn()
Returns true if the identification feature was enabled for this module via the ident* option key, otherwise returns false.
protected boolean isIgnoreCaseOn()
Returns true if the case-insensitive login was enabled for this module via the ignorecase option key, otherwise returns false.
protected boolean checkPassword(java.lang.String encoded, char[] plain) throws javax.security.auth.login.LoginException
Checks whether or not the encoded password equals to the plain (non-encoded) password.
This method allows the login module to check passwords encoded by various different
algorithms by using a custom password encoder. The password encoder must be a class
implementing the PasswordEncoder
interface. The default encoder used is the
MD5PasswordEncoder
, and a custom encoder may be specified via the encoder
option key by providing its full class name.
This method calls the PasswordEncoder.compare(String, char[])
method of the
current PasswordEncoder
with the corresponding arguments.
encoded
- the encoded passwordplain
- the plain (non-encoded) password
javax.security.auth.login.LoginException
- if an error ocurredprotected abstract java.security.Principal[] validate(java.lang.String username, char[] password) throws javax.security.auth.login.LoginException
This method must validate a user according to the given username and password, and should return an array of principal objects representing the various user's identities. If no principals are found, an empty array must be returned. If the user could not be validated, a LoginException is thrown to indicate the failed login. Exception is then propagated to the calling LoginContext object.
It is recommended for the implementations to use the checkPassword(String, char[])
method to validate the password using the current PasswordEncoder
instance.
This method may be implemented in a way that if the password argument is null, it will bypass the password check and will test the user existence only. However, the subject procesed by this type of authentication must not be used to represent an authenticated user. The implementations must consult the ident option key prior to enabling this feature.
The ignorecase option key may be consulted by the implementing modules, too, for enabling the case-insensitive logins.
username
- the name of the userpassword
- the user password
javax.security.auth.login.LoginException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |