From b2958a8bb6145c5aa2eee8aa0b7b6a306732785a Mon Sep 17 00:00:00 2001 From: Jason Stephenson Date: Mon, 31 Oct 2011 15:48:38 -0400 Subject: [PATCH] Add authentication capability to OpenILS::Utils::Cronscript. This allows the client script to call authenticate with a hash ref of user information so that the user can login and get an authtoken if needed. It also stores the authtoken and authtime values for later retrieval. Signed-off-by: Jason Stephenson Signed-off-by: Dan Scott --- .../perlmods/lib/OpenILS/Utils/Cronscript.pm.in | 49 ++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Utils/Cronscript.pm.in b/Open-ILS/src/perlmods/lib/OpenILS/Utils/Cronscript.pm.in index 73281fbc60..9e5e8e59cc 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Utils/Cronscript.pm.in +++ b/Open-ILS/src/perlmods/lib/OpenILS/Utils/Cronscript.pm.in @@ -38,6 +38,9 @@ use File::Basename qw/fileparse/; use Data::Dumper; use Carp; +# Added for authentication +use Digest::MD5 qw/md5_hex/; + our @extra_opts = ( # additional keys are stored here # 'addlopt' ); @@ -282,6 +285,52 @@ sub editor { return new_editor(@_); } +# Authenticate with the open-ils.auth module. +# Takes a hash ref of arguments: +# { +# username => username to authenticate as, +# password => the user's password, +# workstation => the workstation to use (optional), +# type => the type of login (optional, but defaults to staff) +# } +# +# returns the authtoken or undef on failure. +# Also stores the authtoken and authtime as fields on the object. +sub authenticate { + my $self = shift or return; + my $args = shift or return; + if ($args && ref($args) eq 'HASH') { + my $session = $self->session('open-ils.auth'); + my $seed = $session->request('open-ils.auth.authenticate.init', + $args->{'username'})->gather(1); + $args->{password} = md5_hex($seed . md5_hex($args->{password})); + my $req = $session->request('open-ils.auth.authenticate.complete', + $args); + my $response = $req->gather(1); + if ($response && ref($response) eq 'HASH' && $response->{payload}) { + $self->{authtoken} = $response->{payload}->{authtoken}; + $self->{authtime} = $response->{payload}->{authtime}; + } else { + $self->{authtoken} = undef; + $self->{authtime} = undef; + } + $session->disconnect(); + return $self->authtoken; + } else { + return undef; + } +} + +sub authtoken { + my $self = shift; + return $self->{authtoken}; +} + +sub authtime { + my $self = shift; + return $self->{authtime}; +} + 1; __END__ -- 2.11.0