[horde] Sharing user information between hooks
Michael J Rubinsky
mrubinsk at horde.org
Mon Oct 26 15:01:38 UTC 2015
Quoting Jens Wahnes <wahnes at uni-koeln.de>:
> On Fri, Oct 02 2015, at 19:14:28 +0000, Michael J Rubinsky wrote:
>
>> Quoting Jens Wahnes <wahnes at uni-koeln.de>:
>>> To customize the user experience, we are using hooks in our Horde
>>> installation. Among others, we are using preauth-Hooks both within the
>>> "horde" scope (.../config/hooks.php) and within the "imp" scope
>>> (.../imp/config/hooks.php). So far, these hooks work completely
>>> independent from each other. However, we would like to change that and
>>> access information that has been generated by Horde's preauth hook from
>>> within IMP's preauth hook. What is the best way to share such
>>> information between these hooks? Should I add some key-value pair to
>>> the user's session? If so, how should I go about that? Should I use
>>> PHP's $_SESSION variable? Or is there a preferred way to do that
>>> through some interface the Horde framework provides?
>
>> IIRC, depending on the context, it's possible for the preauth hooks to
>> be executed before the session is created, so you may or may not be able
>> to utilize the horde session within those hooks.
>
> For what we are trying to achieve, storing things within the session
> works quite well. To me, it looks like all of Horde's hooks are
> executed before any of IMP's hooks are executed (using LDAP
> authentication, that is - might be different when using IMAP
> authentication through IMP). So we are off just fine as long as we
> look into IMP preauth requests only if they have got a $userId set.
> Now we are just dependend on the fact that IMP's hooks are run after
> Horde's, so I hope that things will stay that way for a while. :-)
>
>> For the record, though, you should access the session using the
>> $GLOBALS['session'] object, not the raw php $_SESSION variable.
>
> Just in case anyone else is interested in doing something like this, I
> got this working using statements like these:
>
> $GLOBALS['session']->set('RRZK', 'foo', 'bar');
>
> $foo = $GLOBALS['session']->get('RRZK', 'foo');
>
> However, now that this is working, I'm already off to try something
> else.
>
> The reason to introduce code to write things into the session was to
> save unnecessary LDAP requests that would otherwise have to be executed
> in both Horde's hooks and IMP's hooks. The bulk of LDAP requests we
> see, however, seems to stem from the fact that a complete session is
> set up (including hooks being run) whenever there is a request through
> CalDAV or such. And not only is a session created for the user
> performing the CalDAV request, but also for all users that have granted
> this user access to their calendars, plus all users that this user is
> granting access to his or her calendars. All in all, that's a lot of
> sessions with lots of LDAP requests. (Consider, for example, a group
> of just 5 people granting calendar access to each other's personal
> calendar. Then you've got 5 LDAP requests per every CalDAV request.
> If everyone within the group is accessing all 5 calendars via CalDAV,
> that's 5*5*5 = 125 LDAP requests for just 5 people.)
>
> So I came to the idea to use memcache to cache the LDAP data, since we
> make heavy use of memcache anyways. I dug around the Horde API docs a
> bit and came up with some code that looks like this (not exactly, but
> close enough):
>
>
> $memcache =
> $GLOBALS['injector']->getInstance('Horde_Core_Factory_HashTable')->create($GLOBALS['injector']);
This should be: $GLOBALS['injector']->getInstance('Horde_HashTable');
The Horde_Core_Factory_HashTable class is registered with the injector
as the factory to use to create the hash table driver. If interested,
this is done in Horde_Registry::__construct().
--
mike
The Horde Project
http://www.horde.org
https://www.facebook.com/hordeproject
https://www.twitter.com/hordeproject
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 5751 bytes
Desc: S/MIME Signature
URL: <http://lists.horde.org/archives/horde/attachments/20151026/1e5f69da/attachment.bin>
More information about the horde
mailing list