From: miker Date: Tue, 13 Feb 2007 18:42:42 +0000 (+0000) Subject: forward porting safe token code X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=07a507b5fad49f4bb2556c6e2de3b91c6d6e81fe;p=Evergreen.git forward porting safe token code git-svn-id: svn://svn.open-ils.org/ILS/trunk@6944 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm b/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm index 5043eb75bf..4c8d60af48 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm @@ -2582,6 +2582,56 @@ sub session_home_lib { return $org->shortname; } +__PACKAGE__->register_method( + method => 'session_safe_token', + api_name => 'open-ils.actor.session.safe_token', + signature => q/ + Returns a hashed session ID that is safe for export to the world. + This safe token will expire after 1 hour of non-use. + @param auth Active authentication token + / +); + +sub session_safe_token { + my( $self, $conn, $auth ) = @_; + my $e = new_editor(authtoken=>$auth); + return undef unless $e->checkauth; + + my $safe_token = md5_hex($auth); + + $cache ||= OpenSRF::Utils::Cache->new("global", 0); + + # Add more like the following if needed... + $cache->put_cache( + "safe-token-home_lib-shortname-$safe_token", + $e->retrieve_actor_org_unit( + $e->requestor->home_ou + )->shortname, + 60 * 60 + ); + + return $safe_token; +} + + +__PACKAGE__->register_method( + method => 'safe_token_home_lib', + api_name => 'open-ils.actor.safe_token.home_lib.shortname', + signature => q/ + Returns the home library shortname from the session + asscociated with a safe token from generated by + open-ils.actor.session.safe_token. + @param safe_token Active safe token + / +); + +sub safe_token_home_lib { + my( $self, $conn, $safe_token ) = @_; + + $cache ||= OpenSRF::Utils::Cache->new("global", 0); + return $cache->get_cache( 'safe-token-home_lib-shortname-'. $safe_token ); +} + __PACKAGE__->register_method(