[cvs] expresso commit by rimovm: Updated to save some bugs with
JCorporate Ltd
jcorp at jcorp2.servlets.net
Mon Nov 8 15:46:09 PST 2004
Log Message:
-----------
Updated to save some bugs with SecurityDBObjects complaining about no filter.
Modified Files:
--------------
expresso/expresso-web/WEB-INF/src/com/jcorporate/expresso/core/registry:
RequestRegistryFilter.java
expresso/expresso-web/WEB-INF/src/com/jcorporate/expresso/services/dbobj:
SecurityDBObject.java
Revision Data
-------------
Index: RequestRegistryFilter.java
===================================================================
RCS file: /home/javacorp/.cvs/expresso/expresso/expresso-web/WEB-INF/src/com/jcorporate/expresso/core/registry/RequestRegistryFilter.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -Lexpresso-web/WEB-INF/src/com/jcorporate/expresso/core/registry/RequestRegistryFilter.java -Lexpresso-web/WEB-INF/src/com/jcorporate/expresso/core/registry/RequestRegistryFilter.java -u -r1.2 -r1.3
--- expresso-web/WEB-INF/src/com/jcorporate/expresso/core/registry/RequestRegistryFilter.java
+++ expresso-web/WEB-INF/src/com/jcorporate/expresso/core/registry/RequestRegistryFilter.java
@@ -78,6 +78,7 @@
import com.jcorporate.expresso.core.misc.CurrentLogin;
import com.jcorporate.expresso.core.security.User;
import com.jcorporate.expresso.core.servlet.CheckLogin;
+import com.jcorporate.expresso.core.security.SuperUser;
/**
* Does a similar job as Expresso's checkLogin() but it also sets the
@@ -112,14 +113,26 @@
FilterChain filterChain) throws ServletException, IOException {
try {
HttpServletRequest req = (HttpServletRequest)request;
- CheckLogin.getInstance().checkLogin((HttpServletRequest)request);
- CurrentLogin cl = (CurrentLogin)GenericSession
- .getAttribute(req,"CurrentLogin");
+ RequestRegistry superUserSettings =
+ new MutableRequestRegistry("default",SuperUser.SUPER_USER);
+ CurrentLogin cl;
+ User u;
+ try {
+ //Set the current thread to superuser for authentication
+ //purposes. We downgrade it as soon as we have privlidges.
+ CheckLogin.getInstance().checkLogin((HttpServletRequest)request);
+ cl = (CurrentLogin)GenericSession
+ .getAttribute(req,"CurrentLogin");
- User u = new User();
- u.setDataContext(cl.getDBName());
- u.setUid(cl.getUid());
- u.retrieve();
+ u = new User();
+ u.setDataContext(cl.getDBName());
+ u.setUid(cl.getUid());
+ u.retrieve();
+ } finally {
+ //Take out the superuser settings to save any chances of
+ //exploits occuring by reuse of a thread.
+ superUserSettings.releaseSettings();
+ }
//The following line sets the particular instance of requestRegistry
//into the threadlocal context.
Index: SecurityDBObject.java
===================================================================
RCS file: /home/javacorp/.cvs/expresso/expresso/expresso-web/WEB-INF/src/com/jcorporate/expresso/services/dbobj/SecurityDBObject.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -Lexpresso-web/WEB-INF/src/com/jcorporate/expresso/services/dbobj/SecurityDBObject.java -Lexpresso-web/WEB-INF/src/com/jcorporate/expresso/services/dbobj/SecurityDBObject.java -u -r1.12 -r1.13
--- expresso-web/WEB-INF/src/com/jcorporate/expresso/services/dbobj/SecurityDBObject.java
+++ expresso-web/WEB-INF/src/com/jcorporate/expresso/services/dbobj/SecurityDBObject.java
@@ -80,27 +80,31 @@
* this object provides a means to control the DB context via Setup values.
* subclasses will ignore any context except that found in Setup.
*
- * You probably will never create a subclass of SecurityDBObject yourself--it is a framework tool embedded in the Expresso security system. The idea is to provide a flexible way to redirect authentication classes to another database context. For example, consider a situation where there are two Expresso applications, and you wanted the second application to rely on the first in order to authenticate users and otherwise supply user information.
-
- The following classes extend SecurityDBObject in Expresso:
-
- * ControllerSecurity
- * DBObjSecurity
- * DefaultUserInfo
- * GroupMembers
- * GroupNest
- * JobSecurity
- * TmpUser
- * UserGroup
- * UserPreference
- * UserPreferenceDef
-
- SecurityDBObject provides a means to control the DB context (for some or all of the classes listed above) via Setup values.
- Two Setup values are important for SecurityDBObject:
-
+ * You probably will never create a subclass of SecurityDBObject yourself--it is
+ * a framework tool embedded in the Expresso security system. The idea is to provide
+ * a flexible way to redirect authentication classes to another database context.
+ * For example, consider a situation where there are two Expresso applications,
+ * and you wanted the second application to rely on the first in order to
+ * authenticate users and otherwise supply user information.
+ * The following classes extend SecurityDBObject in Expresso:
+ *<ul>
+ * <li>ControllerSecurity</li>
+ * <li>DBObjSecurity</li>
+ * <li>DefaultUserInfo</li>
+ * <li>GroupMembers</li>
+ * <li>GroupNest</li>
+ * <li>JobSecurity</li>
+ * <li>TmpUser</li>
+ * <li>UserGroup</li>
+ * <li>UserPreference</li>
+ * <li>UserPreferenceDef</li>
+ * </ul>
+ * <p>SecurityDBObject provides a means to control the DB context
+ * (for some or all of the classes listed above) via Setup values.
+ * Two Setup values are important for SecurityDBObject:
* SecurityDB -- Database to use for User/Group Security Info
* SecurityDBObjs -- Database Objects that should use the 'fixed' context found in the SecurityDB parameter
-
+ *<p>
If these Setup values are empty, SecurityDBObject does nothing special. However, if these 2 Setup values contain
meaningful info, subclasses of SecurityDBObject may ignore any DB context supplied (e.g., they can ignore a
context like 'default' that comes from the ControllerRequest). The logic is two-fold: the Setup value SecurityDB
@@ -109,28 +113,31 @@
value SecurityDB. That's a bit tricky, so to repeat: even though all the security classes listed above are
instances of SecurityDBObject, each one will use the fixed context only if that individual class is also listed
in the Setup value, SecurityDBObjs.
-
- This scheme is useful in at least one case: one primary Expresso application supplying User information to a
- secondary Expresso application.
-
- LIMITATION: user info and group membership changed on the primary, UserInfo application will not trigger a cache cleaning on the secondary
- system. So when these memberships are changed, manually clean the cache on the secondary system via admin
- pages, or by restarting.
-
- As always, this sample may not be representative of your needs, so attempt
- this only with caution and a single-step debugger handy.
-
+ </p>
+ * <p>
+ * This scheme is useful in at least one case: one primary Expresso application supplying User information to a
+ * secondary Expresso application.
+ * </p>
+ * <p>
+ * LIMITATION: user info and group membership changed on the primary,
+ * UserInfo application will not trigger a cache cleaning on the secondary
+ * system. So when these memberships are changed, manually clean the cache on
+ * the secondary system via admin
+ * pages, or by restarting.</p>
+ *<p>As always, this sample may not be representative of your needs, so attempt
+ * this only with caution and a single-step debugger handy.</p>
+ *
* @author Michael Nash
*/
-public abstract class SecurityDBObject
- extends SecuredDBObject {
+public abstract class SecurityDBObject extends SecuredDBObject
+{
private static Logger log = Logger.getLogger(SecurityDBObject.class);
public static final String SECURITY_CONTEXT = "SecurityDB";
public static final String SECURITY_OBJECTS = "SecurityDBObjs";
- public SecurityDBObject()
- throws DBException {
- } /* SecurityDBOBject() */
+ public SecurityDBObject() throws DBException {
+ super();
+ }
/**
* Use over (String) constructor. Initializes the object in the context
@@ -138,8 +145,7 @@
* @param uid the Uid of the user context
* @throws DBException if there's an initialization problem
*/
- public SecurityDBObject(int uid)
- throws DBException {
+ public SecurityDBObject(int uid) throws DBException {
super(uid);
}
@@ -150,8 +156,7 @@
* @param request - The controller request handed to you by the framework.
* @throws DBException if there's an error constructing the object
*/
- public SecurityDBObject(RequestContext request)
- throws DBException {
+ public SecurityDBObject(RequestContext request) throws DBException {
super(request);
}
@@ -168,14 +173,16 @@
}
/**
- * ignore the newContext parameter if Setup values indicate to do this.
+ * Ignore the newContext parameter if Setup values indicate to do this.
* In other words, when someone tries to set a new data context, check
* with Setup values to see if this SecurityDBObject subclass is listed in the set
* of SecurityDBObjs (a list configurable as a Setup param).
- *
- * Warning: calls super.setDBName(), which could loop back recursively if the superclass
+ *
+ * Warning: calls super.setDBName(),
+ * which could loop back recursively if the superclass
* then creates objects which get db context set.
* @param newContext the new dataContext to use
+ * @throws DBException upon construction error.
*/
public void setDBName(String newContext) throws DBException {
super.setDBName(newContext);
@@ -187,20 +194,22 @@
* with Setup values to see if this new context should be
* ignored, such as when a SecurityDBObject subclass is listed in the set
* of SecurityDBObjs (a list configurable as a Setup param).
+ * @param newContext the new data context to use.
*/
protected void overrideDataContext(String newContext) {
try {
- if ( newContext == null || newContext.length() == 0 ) {
+ if (newContext == null || newContext.length() == 0) {
newContext = DBConnection.DEFAULT_DB_CONTEXT_NAME;
}
// look for setup values only if the context includes setup
ConfigContext config = ConfigManager.getContext(newContext);
- if ( config != null && config.hasSetupTables() ) {
- String securityDB = StringUtil.notNull(Setup.getValue(newContext,
- SECURITY_CONTEXT));
+ if (config != null && config.hasSetupTables()) {
+ String securityDB = StringUtil.notNull(Setup.getValue(
+ newContext,
+ SECURITY_CONTEXT));
String objNames = StringUtil.notNull(Setup.getValue(newContext,
- SECURITY_OBJECTS));
+ SECURITY_OBJECTS));
// if our object is included in list,
// use the Setup value for DB context instead the one passed in
@@ -210,8 +219,8 @@
}
} catch (Exception ex) {
String errorMessage = "Problem overriding newContext name: "
- + newContext + ": "
- + ex.getMessage();
+ + newContext + ": "
+ + ex.getMessage();
log.error(errorMessage, ex);
throw new IllegalArgumentException(errorMessage);
}
More information about the cvs
mailing list