Instrumented the UserManager to debug dev1, yay.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2051 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -123,6 +123,11 @@ public class UserManager
|
|||||||
_userAuthCookie = authCook;
|
_userAuthCookie = authCook;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (USERMGR_DEBUG) {
|
||||||
|
Log.info("UserManager initialized [acook=" + _userAuthCookie +
|
||||||
|
", login=" + _loginURL + "].");
|
||||||
|
}
|
||||||
|
|
||||||
// register a cron job to prune the session table every hour
|
// register a cron job to prune the session table every hour
|
||||||
_pruner = new Interval() {
|
_pruner = new Interval() {
|
||||||
public void expired ()
|
public void expired ()
|
||||||
@@ -162,7 +167,11 @@ public class UserManager
|
|||||||
public User loadUser (HttpServletRequest req)
|
public User loadUser (HttpServletRequest req)
|
||||||
throws PersistenceException
|
throws PersistenceException
|
||||||
{
|
{
|
||||||
return loadUser(CookieUtil.getCookieValue(req, _userAuthCookie));
|
String authcook = CookieUtil.getCookieValue(req, _userAuthCookie);
|
||||||
|
if (USERMGR_DEBUG) {
|
||||||
|
Log.info("Loading user by cookie [" + _userAuthCookie + "=" + authcook + "].");
|
||||||
|
}
|
||||||
|
return loadUser(authcook);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -171,6 +180,9 @@ public class UserManager
|
|||||||
public User loadUser (String authcode)
|
public User loadUser (String authcode)
|
||||||
throws PersistenceException
|
throws PersistenceException
|
||||||
{
|
{
|
||||||
|
if (USERMGR_DEBUG) {
|
||||||
|
Log.info("Loading user by authcode directly [code=" + authcode + "].");
|
||||||
|
}
|
||||||
return (authcode == null) ? null : _repository.loadUserBySession(authcode);
|
return (authcode == null) ? null : _repository.loadUserBySession(authcode);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -186,12 +198,14 @@ public class UserManager
|
|||||||
throws PersistenceException, RedirectException
|
throws PersistenceException, RedirectException
|
||||||
{
|
{
|
||||||
User user = loadUser(req);
|
User user = loadUser(req);
|
||||||
// if no user was loaded, we need to redirect these fine people to the
|
// if no user was loaded, we need to redirect these fine people to the login page
|
||||||
// login page
|
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
// first construct the redirect URL
|
// first construct the redirect URL
|
||||||
String eurl = RequestUtils.getLocationEncoded(req);
|
String eurl = RequestUtils.getLocationEncoded(req);
|
||||||
String target = StringUtil.replace(_loginURL, "%R", eurl);
|
String target = StringUtil.replace(_loginURL, "%R", eurl);
|
||||||
|
if (USERMGR_DEBUG) {
|
||||||
|
Log.info("No user found in require, redirecting [to=" + target + "].");
|
||||||
|
}
|
||||||
throw new RedirectException(target);
|
throw new RedirectException(target);
|
||||||
}
|
}
|
||||||
return user;
|
return user;
|
||||||
@@ -276,7 +290,9 @@ public class UserManager
|
|||||||
|
|
||||||
// register a session for this user
|
// register a session for this user
|
||||||
String authcode = _repository.registerSession(user, expires);
|
String authcode = _repository.registerSession(user, expires);
|
||||||
|
if (USERMGR_DEBUG) {
|
||||||
|
Log.info("Session started [user=" + username + ", code=" + authcode + "].");
|
||||||
|
}
|
||||||
return new Tuple<User,String>(user, authcode);
|
return new Tuple<User,String>(user, authcode);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -299,6 +315,9 @@ public class UserManager
|
|||||||
}
|
}
|
||||||
acookie.setPath("/");
|
acookie.setPath("/");
|
||||||
acookie.setMaxAge((expires > 0) ? (expires*24*60*60) : -1);
|
acookie.setMaxAge((expires > 0) ? (expires*24*60*60) : -1);
|
||||||
|
if (USERMGR_DEBUG) {
|
||||||
|
Log.info("Setting cookie " + acookie + ".");
|
||||||
|
}
|
||||||
rsp.addCookie(acookie);
|
rsp.addCookie(acookie);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -307,9 +326,8 @@ public class UserManager
|
|||||||
*/
|
*/
|
||||||
public void logout (HttpServletRequest req, HttpServletResponse rsp)
|
public void logout (HttpServletRequest req, HttpServletResponse rsp)
|
||||||
{
|
{
|
||||||
String authcode = CookieUtil.getCookieValue(req, _userAuthCookie);
|
|
||||||
|
|
||||||
// nothing to do if they don't already have an auth cookie
|
// nothing to do if they don't already have an auth cookie
|
||||||
|
String authcode = CookieUtil.getCookieValue(req, _userAuthCookie);
|
||||||
if (authcode == null) {
|
if (authcode == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -319,10 +337,12 @@ public class UserManager
|
|||||||
c.setPath("/");
|
c.setPath("/");
|
||||||
c.setMaxAge(0);
|
c.setMaxAge(0);
|
||||||
CookieUtil.widenDomain(req, c);
|
CookieUtil.widenDomain(req, c);
|
||||||
|
if (USERMGR_DEBUG) {
|
||||||
|
Log.info("Clearing cookie " + c + ".");
|
||||||
|
}
|
||||||
rsp.addCookie(c);
|
rsp.addCookie(c);
|
||||||
|
|
||||||
// we need an unwidened one to ensure that old-style cookies are
|
// we need an unwidened one to ensure that old-style cookies are wiped as well
|
||||||
// wiped as well
|
|
||||||
c = new Cookie(_userAuthCookie, "x");
|
c = new Cookie(_userAuthCookie, "x");
|
||||||
c.setPath("/");
|
c.setPath("/");
|
||||||
c.setMaxAge(0);
|
c.setMaxAge(0);
|
||||||
@@ -330,9 +350,8 @@ public class UserManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called by the user manager to create the user repository. Derived
|
* Called by the user manager to create the user repository. Derived classes can override this
|
||||||
* classes can override this and create a specialized repository if
|
* and create a specialized repository if they so desire.
|
||||||
* they so desire.
|
|
||||||
*/
|
*/
|
||||||
protected UserRepository createRepository (ConnectionProvider conprov)
|
protected UserRepository createRepository (ConnectionProvider conprov)
|
||||||
throws PersistenceException
|
throws PersistenceException
|
||||||
@@ -366,4 +385,7 @@ public class UserManager
|
|||||||
|
|
||||||
/** Indicates how long (in days) that a "non-persisting" session token should last. */
|
/** Indicates how long (in days) that a "non-persisting" session token should last. */
|
||||||
protected static final int NON_PERSIST_EXPIRE_DAYS = 1;
|
protected static final int NON_PERSIST_EXPIRE_DAYS = 1;
|
||||||
|
|
||||||
|
/** Change this to true and recompile to debug cookie handling. */
|
||||||
|
protected static final boolean USERMGR_DEBUG = true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user