[open-ils-commits] r18923 - trunk/Open-ILS/src/c-apps (erickson)

svn at svn.open-ils.org svn at svn.open-ils.org
Mon Dec 6 15:56:19 EST 2010


Author: erickson
Date: 2010-12-06 15:56:14 -0500 (Mon, 06 Dec 2010)
New Revision: 18923

Modified:
   trunk/Open-ILS/src/c-apps/oils_auth.c
Log:
refresh cached user during auth session reset

Add a boolean (1/0) param to open-ils.auth.session.reset_timeout
that forces open-ils.auth to refresh the cached user object.  Useful if
a column on actor.usr was updated and the client may be pulling the
object from the cache w/ a page reload, etc.

Modified: trunk/Open-ILS/src/c-apps/oils_auth.c
===================================================================
--- trunk/Open-ILS/src/c-apps/oils_auth.c	2010-12-06 20:20:48 UTC (rev 18922)
+++ trunk/Open-ILS/src/c-apps/oils_auth.c	2010-12-06 20:56:14 UTC (rev 18923)
@@ -680,10 +680,59 @@
 }
 
 /**
+ * Fetches the user object from the database and updates the user object in 
+ * the cache object, which then has to be re-inserted into the cache.
+ * User object is retrieved inside a transaction to avoid replication issues.
+ */
+static int _oilsAuthReloadUser(jsonObject* cacheObj) {
+    int reqid, userId;
+    osrfAppSession* session;
+	osrfMessage* omsg;
+    jsonObject *param, *userObj, *newUserObj;
+
+    userObj = jsonObjectGetKey( cacheObj, "userobj" );
+    userId = oilsFMGetObjectId( userObj );
+
+    session = osrfAppSessionClientInit( "open-ils.cstore" );
+    osrfAppSessionConnect(session);
+
+    reqid = osrfAppSessionSendRequest(session, NULL, "open-ils.cstore.transaction.begin", 1);
+	omsg = osrfAppSessionRequestRecv(session, reqid, 60);
+
+    if(omsg) {
+
+        osrfMessageFree(omsg);
+        param = jsonNewNumberObject(userId);
+        reqid = osrfAppSessionSendRequest(session, param, "open-ils.cstore.direct.actor.user.retrieve", 1);
+	    omsg = osrfAppSessionRequestRecv(session, reqid, 60);
+        jsonObjectFree(param);
+
+        if(omsg) {
+            newUserObj = jsonObjectClone( osrfMessageGetResult(omsg) );
+            osrfMessageFree(omsg);
+            reqid = osrfAppSessionSendRequest(session, NULL, "open-ils.cstore.transaction.rollback", 1);
+	        omsg = osrfAppSessionRequestRecv(session, reqid, 60);
+            osrfMessageFree(omsg);
+        }
+    }
+
+    osrfAppSessionFree(session); // calls disconnect internally
+
+    if(newUserObj) {
+        jsonObjectRemoveKey(cacheObj, "userobj"); // this also frees the old user object
+        jsonObjectSetKey(cacheObj, "userobj", newUserObj);
+        return 1;
+    } 
+
+    osrfLogError(OSRF_LOG_MARK, "Error retrieving user %d from database", userId);
+    return 0;
+}
+
+/**
 	Resets the auth login timeout
 	@return The event object, OILS_EVENT_SUCCESS, or OILS_EVENT_NO_SESSION
 */
-static oilsEvent*  _oilsAuthResetTimeout( const char* authToken ) {
+static oilsEvent*  _oilsAuthResetTimeout( const char* authToken, int reloadUser ) {
 	if(!authToken) return NULL;
 
 	oilsEvent* evt = NULL;
@@ -698,6 +747,11 @@
 		evt = oilsNewEvent(OSRF_LOG_MARK, OILS_EVENT_NO_SESSION);
 
 	} else {
+
+        if(reloadUser) {
+            _oilsAuthReloadUser(cacheObj);
+        }
+
 		// Determine a new timeout value
 		jsonObject* endtime_obj = jsonObjectGetKey( cacheObj, "endtime" );
 		if( endtime_obj ) {
@@ -743,7 +797,8 @@
 int oilsAuthResetTimeout( osrfMethodContext* ctx ) {
 	OSRF_METHOD_VERIFY_CONTEXT(ctx);
 	const char* authToken = jsonObjectGetString( jsonObjectGetIndex(ctx->params, 0));
-	oilsEvent* evt = _oilsAuthResetTimeout(authToken);
+    double reloadUser = jsonObjectGetNumber( jsonObjectGetIndex(ctx->params, 1));
+	oilsEvent* evt = _oilsAuthResetTimeout(authToken, (int) reloadUser);
 	osrfAppRespondComplete( ctx, oilsEventToJSON(evt) );
 	oilsEventFree(evt);
 	return 0;
@@ -760,7 +815,7 @@
 	if( authToken ){
 
 		// Reset the timeout to keep the session alive
-		evt = _oilsAuthResetTimeout(authToken);
+		evt = _oilsAuthResetTimeout(authToken, 0);
 
 		if( evt && strcmp(evt->event, OILS_EVENT_SUCCESS) ) {
 			osrfAppRespondComplete( ctx, oilsEventToJSON( evt ));    // can't reset timeout



More information about the open-ils-commits mailing list