[DS-1085] Apply patch (slightly updated) from Jira ticket

This commit is contained in:
Mark H. Wood
2012-08-15 11:55:39 -04:00
committed by Ivan Masár
parent a0714564b7
commit 0d948ae708
2 changed files with 45 additions and 5 deletions

View File

@@ -11,12 +11,16 @@ import javax.servlet.http.HttpServletRequest;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Date;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import org.dspace.authorize.AuthorizeException;
import org.dspace.core.Context; import org.dspace.core.Context;
import org.dspace.core.PluginManager; import org.dspace.core.PluginManager;
import org.dspace.eperson.EPerson; import org.dspace.eperson.EPerson;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* Access point for the stackable authentication methods. * Access point for the stackable authentication methods.
@@ -51,6 +55,9 @@ public class AuthenticationManager
private static AuthenticationMethod methodStack[] = private static AuthenticationMethod methodStack[] =
(AuthenticationMethod[])PluginManager.getPluginSequence("authentication", AuthenticationMethod.class); (AuthenticationMethod[])PluginManager.getPluginSequence("authentication", AuthenticationMethod.class);
/** SLF4J logging category */
private static final Logger log = (Logger) LoggerFactory.getLogger(AuthenticationManager.class);
/** /**
* Test credentials for authenticity. * Test credentials for authenticity.
* Apply the given credentials to each authenticate() method in * Apply the given credentials to each authenticate() method in
@@ -78,10 +85,10 @@ public class AuthenticationManager
* SUCCESS, BAD_CREDENTIALS, CERT_REQUIRED, NO_SUCH_USER, BAD_ARGS * SUCCESS, BAD_CREDENTIALS, CERT_REQUIRED, NO_SUCH_USER, BAD_ARGS
* <p>Meaning: * <p>Meaning:
* <br>SUCCESS - authenticated OK. * <br>SUCCESS - authenticated OK.
* <br>BAD_CREDENTIALS - user exists, but credenitals (e.g. passwd) don't match * <br>BAD_CREDENTIALS - user exists, but credentials (e.g. password) don't match
* <br>CERT_REQUIRED - not allowed to login this way without X.509 cert. * <br>CERT_REQUIRED - not allowed to login this way without X.509 cert.
* <br>NO_SUCH_USER - user not found using this method. * <br>NO_SUCH_USER - user not found using this method.
* <br>BAD_ARGS - user/pw not appropriate for this method * <br>BAD_ARGS - user/password not appropriate for this method
*/ */
public static int authenticate(Context context, public static int authenticate(Context context,
String username, String username,
@@ -119,10 +126,10 @@ public class AuthenticationManager
* SUCCESS, BAD_CREDENTIALS, CERT_REQUIRED, NO_SUCH_USER, BAD_ARGS * SUCCESS, BAD_CREDENTIALS, CERT_REQUIRED, NO_SUCH_USER, BAD_ARGS
* <p>Meaning: * <p>Meaning:
* <br>SUCCESS - authenticated OK. * <br>SUCCESS - authenticated OK.
* <br>BAD_CREDENTIALS - user exists, but credenitals (e.g. passwd) don't match * <br>BAD_CREDENTIALS - user exists, but credentials (e.g. password) don't match
* <br>CERT_REQUIRED - not allowed to login this way without X.509 cert. * <br>CERT_REQUIRED - not allowed to login this way without X.509 cert.
* <br>NO_SUCH_USER - user not found using this method. * <br>NO_SUCH_USER - user not found using this method.
* <br>BAD_ARGS - user/pw not appropriate for this method * <br>BAD_ARGS - user/password not appropriate for this method
*/ */
public static int authenticateImplicit(Context context, public static int authenticateImplicit(Context context,
String username, String username,
@@ -160,6 +167,18 @@ public class AuthenticationManager
} }
if (ret == AuthenticationMethod.SUCCESS) if (ret == AuthenticationMethod.SUCCESS)
{ {
EPerson me = context.getCurrentUser();
me.setLastActive(new Date());
try
{
me.update();
} catch (SQLException ex)
{
log.error("Could not update last-active stamp", ex);
} catch (AuthorizeException ex)
{
log.error("Could not update last-active stamp", ex);
}
return ret; return ret;
} }
if (ret < bestRet) if (ret < bestRet)

View File

@@ -9,6 +9,7 @@ package org.dspace.eperson;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import java.util.List; import java.util.List;
import org.apache.commons.codec.DecoderException; import org.apache.commons.codec.DecoderException;
@@ -811,7 +812,7 @@ public class EPerson extends DSpaceObject
} }
/** /**
* Can the user log in? * Is the user self-registered?
* *
* @return boolean, yes/no (or false if the column is an SQL NULL) * @return boolean, yes/no (or false if the column is an SQL NULL)
*/ */
@@ -954,6 +955,26 @@ public class EPerson extends DSpaceObject
return answer; return answer;
} }
/**
* Stamp the EPerson's last-active date.
*
* @param when latest activity timestamp, or null to clear.
*/
public void setLastActive(Date when)
{
myRow.setColumn("last_active", when);
}
/**
* Get the EPerson's last-active stamp.
*
* @return date when last logged on, or null.
*/
public Date getLastActive()
{
return myRow.getDateColumn("last_active");
}
/** /**
* Update the EPerson * Update the EPerson
*/ */