henning 2003/02/27 09:56:19
Modified: src/java/org/apache/turbine Turbine.java
Log:
This is a quite innocent looking change. In fact, it is a major bug
fix. It still is ugly as hell, introduces a dependency of the Velocity
Service to Turbine.java but the correct fix would be a massive rewrite
of some parts of the Turbine cycle (you would need action specific
listeners for this so some code can be run if a specific action is
executed) so I keep this either for Turbine NG or post-2.3 This fix
will do, because these days, everyone seems to run Turbine with
Velocity.
It might be, that the actual bug isn't even (yet) present in the
current Turbine source base, but I will tell you about it
nevertheless. :-)
When Turbine starts up, it should have no user logged in. So the
session validator will create a new user object for the anonymous user
by calling TurbineSecurity.getAnonymousUser(). After that, the pull
tools are initialized for this user and the Login screen is displayed.
User specific tools are kept in a hash table which is copied and then
populated with the request tools.
If the user logs in, we get a new user object. But at this point, the
non-request tools are already set. So on the first screen that the
freshly logged in user is shown, he still gets the tools of the old
(anonymous) user. The second and any further screens will contain the
right tools. Same goes for logout. The first login screen after the
user logged out will contain all the tools of the last authorized
user.
This change fixes this by removing the Velocity Context containing the
global and session tools, forcing the Pull Service to rebuild these.
Revision Changes Path
1.30 +28 -1 jakarta-turbine-2/src/java/org/apache/turbine/Turbine.java
Index: Turbine.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/Turbine.java,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -r1.29 -r1.30
--- Turbine.java 27 Feb 2003 17:37:34 -0000 1.29
+++ Turbine.java 27 Feb 2003 17:56:18 -0000 1.30
@@ -92,6 +92,8 @@
import org.apache.turbine.services.template.TurbineTemplate;
+import org.apache.turbine.services.velocity.VelocityService;
+
import org.apache.turbine.util.RunData;
import org.apache.turbine.util.RunDataFactory;
import org.apache.turbine.util.ServerData;
@@ -99,6 +101,8 @@
import org.apache.turbine.util.security.AccessControlList;
+import org.apache.turbine.util.template.TemplateInfo;
+
import org.apache.turbine.util.uri.URIConstants;
/**
@@ -883,6 +887,7 @@
}
}
ActionLoader.getInstance().exec(data, data.getAction());
+ cleanupTemplateContext(data);
data.setAction(null);
}
@@ -901,8 +906,30 @@
throws Exception
{
ActionLoader.getInstance().exec(data, data.getAction());
+ cleanupTemplateContext(data);
data.setAction(null);
}
+
+ /**
+ * cleans the Velocity Context if available.
+ *
+ * @param data A RunData Object
+ *
+ * @throws Exception A problem while cleaning out the Template Context occured.
+ */
+ private void cleanupTemplateContext(RunData data)
+ throws Exception
+ {
+ // This is Velocity specific and shouldn't be done here.
+ // But this is a band aid until we get real listeners
+ // here.
+ TemplateInfo ti = data.getTemplateInfo();
+ if (ti != null)
+ {
+ ti.removeTemp(VelocityService.CONTEXT);
+ }
+ }
+
/**
* Return the servlet info.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]