org.dspace.authenticate
Class AuthenticationManager

java.lang.Object
  extended by org.dspace.authenticate.AuthenticationManager

public class AuthenticationManager
extends Object

Access point for the stackable authentication methods.

This class initializes the "stack" from the DSpace configuration, and then invokes methods in the appropriate order on behalf of clients.

See the AuthenticationMethod interface for details about what each function does.

Configuration
The stack of authentication methods is defined by one property in the DSpace configuration:

   plugin.sequence.org.dspace.eperson.AuthenticationMethod = a list of method class names
     e.g.
   plugin.sequence.org.dspace.eperson.AuthenticationMethod = \
       org.dspace.eperson.X509Authentication, \
       org.dspace.eperson.PasswordAuthentication
 

The "stack" is always traversed in order, with the methods specified first (in the configuration) thus getting highest priority.

Version:
$Revision: 3735 $
Author:
Larry Stone
See Also:
AuthenticationMethod

Constructor Summary
AuthenticationManager()
           
 
Method Summary
static boolean allowSetPassword(Context context, javax.servlet.http.HttpServletRequest request, String username)
          Predicate, can user set EPerson password.
static int authenticate(Context context, String username, String password, String realm, javax.servlet.http.HttpServletRequest request)
          Test credentials for authenticity.
static int authenticateImplicit(Context context, String username, String password, String realm, javax.servlet.http.HttpServletRequest request)
          Test credentials for authenticity, using only Implicit methods.
static Iterator authenticationMethodIterator()
          Get stack of authentication methods.
static boolean canSelfRegister(Context context, javax.servlet.http.HttpServletRequest request, String username)
          Predicate, can a new EPerson be created.
static int[] getSpecialGroups(Context context, javax.servlet.http.HttpServletRequest request)
          Get list of extra groups that user implicitly belongs to.
static void initEPerson(Context context, javax.servlet.http.HttpServletRequest request, EPerson eperson)
          Initialize a new e-person record for a self-registered new user.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AuthenticationManager

public AuthenticationManager()
Method Detail

authenticate

public static int authenticate(Context context,
                               String username,
                               String password,
                               String realm,
                               javax.servlet.http.HttpServletRequest request)
Test credentials for authenticity. Apply the given credentials to each authenticate() method in the stack. Returns upon the first SUCCESS, or otherwise returns the most favorable outcome from one of the methods.

Parameters:
context - DSpace context, will be modified (ePerson set) upon success.
username - Username (or email address) when method is explicit. Use null for implicit method.
password - Password for explicit auth, or null for implicit method.
realm - Realm is an extra parameter used by some authentication methods, leave null if not applicable.
request - The HTTP request that started this operation, or null if not applicable.
Returns:
One of: SUCCESS, BAD_CREDENTIALS, CERT_REQUIRED, NO_SUCH_USER, BAD_ARGS

Meaning:
SUCCESS - authenticated OK.
BAD_CREDENTIALS - user exists, but credenitals (e.g. passwd) don't match
CERT_REQUIRED - not allowed to login this way without X.509 cert.
NO_SUCH_USER - user not found using this method.
BAD_ARGS - user/pw not appropriate for this method


authenticateImplicit

public static int authenticateImplicit(Context context,
                                       String username,
                                       String password,
                                       String realm,
                                       javax.servlet.http.HttpServletRequest request)
Test credentials for authenticity, using only Implicit methods. Just like authenticate(), except it only invokes the implicit authentication methods the stack.

Parameters:
context - DSpace context, will be modified (ePerson set) upon success.
username - Username (or email address) when method is explicit. Use null for implicit method.
password - Password for explicit auth, or null for implicit method.
realm - Realm is an extra parameter used by some authentication methods, leave null if not applicable.
request - The HTTP request that started this operation, or null if not applicable.
Returns:
One of: SUCCESS, BAD_CREDENTIALS, CERT_REQUIRED, NO_SUCH_USER, BAD_ARGS

Meaning:
SUCCESS - authenticated OK.
BAD_CREDENTIALS - user exists, but credenitals (e.g. passwd) don't match
CERT_REQUIRED - not allowed to login this way without X.509 cert.
NO_SUCH_USER - user not found using this method.
BAD_ARGS - user/pw not appropriate for this method


canSelfRegister

public static boolean canSelfRegister(Context context,
                                      javax.servlet.http.HttpServletRequest request,
                                      String username)
                               throws SQLException
Predicate, can a new EPerson be created. Invokes canSelfRegister() of every authentication method in the stack, and returns true if any of them is true.

Parameters:
context - DSpace context
request - HTTP request, in case it's needed. Can be null.
username - Username, if available. Can be null.
Returns:
true if new ePerson should be created.
Throws:
SQLException

allowSetPassword

public static boolean allowSetPassword(Context context,
                                       javax.servlet.http.HttpServletRequest request,
                                       String username)
                                throws SQLException
Predicate, can user set EPerson password. Returns true if the allowSetPassword() method of any member of the stack returns true.

Parameters:
context - DSpace context
request - HTTP request, in case it's needed. Can be null.
username - Username, if available. Can be null.
Returns:
true if this method allows user to change ePerson password.
Throws:
SQLException

initEPerson

public static void initEPerson(Context context,
                               javax.servlet.http.HttpServletRequest request,
                               EPerson eperson)
                        throws SQLException
Initialize a new e-person record for a self-registered new user. Give every authentication method in the stack a chance to initialize the new ePerson by calling its initEperson()

Parameters:
context - DSpace context
request - HTTP request, in case it's needed. Can be null.
eperson - newly created EPerson record - email + information from the registration form will have been filled out.
Throws:
SQLException

getSpecialGroups

public static int[] getSpecialGroups(Context context,
                                     javax.servlet.http.HttpServletRequest request)
                              throws SQLException
Get list of extra groups that user implicitly belongs to. Returns accumulation of groups of all the getSpecialGroups() methods in the stack.

Parameters:
context - A valid DSpace context.
request - The request that started this operation, or null if not applicable.
Returns:
Returns IDs of any groups the user authenticated by this request is in implicitly -- checks for e.g. network-address dependent groups.
Throws:
SQLException

authenticationMethodIterator

public static Iterator authenticationMethodIterator()
Get stack of authentication methods. Return an Iterator that steps through each configured authentication method, in order of precedence.

Returns:
Iterator object.


Copyright © 2010 DuraSpace. All Rights Reserved.