check if the NodeHandle of a registered user is broken.
If so, reset the handle, logging the user out. This should solve the "broken session" phenomenon. Also added some comments.
This commit is contained in:
parent
841f09b789
commit
6c883367e7
1 changed files with 30 additions and 36 deletions
|
@ -20,11 +20,22 @@ public class User implements Serializable {
|
||||||
|
|
||||||
Application app;
|
Application app;
|
||||||
String sessionID;
|
String sessionID;
|
||||||
String uid; // the unique id (login name) for the user, if logged in
|
|
||||||
|
// the unique id (login name) for the user, if logged in
|
||||||
|
String uid;
|
||||||
|
|
||||||
|
// the handle to this user's persistent db node, if logged in
|
||||||
NodeHandle nhandle;
|
NodeHandle nhandle;
|
||||||
|
|
||||||
|
// the transient cache node. This stays the same across logins and logouts.
|
||||||
|
// If logged out, this also represents the user's main node.
|
||||||
|
TransientNode cache;
|
||||||
|
|
||||||
DbMapping umap;
|
DbMapping umap;
|
||||||
long onSince, lastTouched;
|
long onSince, lastTouched;
|
||||||
TransientNode cache;
|
|
||||||
|
// used to remember messages to the user between requests -
|
||||||
|
// used for redirects.
|
||||||
String message;
|
String message;
|
||||||
|
|
||||||
public User (String sid, Application app) {
|
public User (String sid, Application app) {
|
||||||
|
@ -43,8 +54,11 @@ public class User implements Serializable {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is used to turn an anonymous user into a registered or known one.
|
* This is used to turn for login and logout.
|
||||||
* The user object remains the same, but she gets some persistent storage.
|
* Calling this weith a DB Node object will turn an anonymous user into a registered or known one.
|
||||||
|
* The user object remains the same, but he or she gets some persistent storage.
|
||||||
|
* On the other side, calling this method with a parameter value of null is means the user
|
||||||
|
* is logged out and will be represented by its transient cache node.
|
||||||
*/
|
*/
|
||||||
public void setNode (INode n) {
|
public void setNode (INode n) {
|
||||||
// IServer.getLogger().log ("esn = "+esn);
|
// IServer.getLogger().log ("esn = "+esn);
|
||||||
|
@ -53,15 +67,25 @@ public class User implements Serializable {
|
||||||
uid = null;
|
uid = null;
|
||||||
} else {
|
} else {
|
||||||
uid = n.getElementName ();
|
uid = n.getElementName ();
|
||||||
nhandle = ((helma.objectmodel.db.Node) n).getHandle ();
|
nhandle = ((Node) n).getHandle ();
|
||||||
}
|
}
|
||||||
|
// System.err.println ("User.setNode: "+nhandle);
|
||||||
}
|
}
|
||||||
|
|
||||||
public INode getNode () {
|
public INode getNode () {
|
||||||
if (nhandle == null) {
|
if (nhandle == null) {
|
||||||
return cache;
|
return cache;
|
||||||
} else {
|
} else {
|
||||||
return nhandle.getNode (app.nmgr.safe);
|
// in some special cases, a user's node handle may go bad, for instance
|
||||||
|
// if something bad happens during registration. For this reason, we check
|
||||||
|
// if the handle actually works. If not, it is reset to the transient cache, which
|
||||||
|
// means the user is logged out.
|
||||||
|
Node n = nhandle.getNode (app.nmgr.safe);
|
||||||
|
if (n == null) {
|
||||||
|
setNode (null);
|
||||||
|
return cache;
|
||||||
|
}
|
||||||
|
return n;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,33 +123,3 @@ public class User implements Serializable {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue