From: Bill Erickson Date: Mon, 12 Oct 2020 15:29:31 +0000 (-0400) Subject: sip2 moves to its own schema X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=ccc81b61f7319c70e825011e2d10de878a78baac;p=working%2FEvergreen.git sip2 moves to its own schema Signed-off-by: Bill Erickson --- diff --git a/Open-ILS/examples/fm_IDL.xml b/Open-ILS/examples/fm_IDL.xml index 71a13e67c9..4ec0f67fee 100644 --- a/Open-ILS/examples/fm_IDL.xml +++ b/Open-ILS/examples/fm_IDL.xml @@ -13435,18 +13435,18 @@ SELECT usr, - - - + + - + @@ -13457,19 +13457,19 @@ SELECT usr, - - - + + - + @@ -13480,23 +13480,23 @@ SELECT usr, - - + + - + - + @@ -13507,6 +13507,20 @@ SELECT usr, + + + + + + + + + + + diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2.pm index 72ab594a88..d39d91c595 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2.pm @@ -77,9 +77,9 @@ sub handle_login { my $sip_username = $SC->get_field_value($message, 'CN'); my $sip_password = $SC->get_field_value($message, 'CO'); - my $sip_account = $e->search_config_sip_account([ + my $sip_account = $e->search_sip_account([ {sip_username => $sip_username, enabled => 't'}, - {flesh => 1, flesh_fields => {csa => ['workstation']}} + {flesh => 1, flesh_fields => {sipacc => ['workstation']}} ])->[0]; if (!$sip_account) { @@ -105,7 +105,7 @@ sub handle_login { sub handle_sc_status { my ($seskey, $message) = @_; - my $session = OpenILS::Application::SIPSession->from_cache($seskey); + my $session = OpenILS::Application::SIPSession->find($seskey); my $config; diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2/Patron.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2/Patron.pm index b619cf9be9..847d0150af 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2/Patron.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2/Patron.pm @@ -394,7 +394,7 @@ sub add_fine_items { my $e = $session->editor; my @fines; - my $AV_format = lc($session->sip_account->av_format) || 'eg_legacy'; + my $AV_format = lc($session->config->{settings}->{av_format} || 'eg_legacy'); # Do a prescan for validity and default to eg_legacy if ($AV_format ne "swyer_a" && diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2/Session.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2/Session.pm index 2137d1bb3c..60b6461216 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2/Session.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2/Session.pm @@ -1,10 +1,10 @@ package OpenILS::Application::SIPSession; use strict; use warnings; use JSON::XS; -use OpenSRF::Utils::Cache; use OpenSRF::Utils::Logger q/$logger/; use OpenILS::Application::AppUtils; use OpenILS::Utils::CStoreEditor q/:funcs/; +use OpenILS::Utils::Fieldmapper; my $U = 'OpenILS::Application::AppUtils'; my $json = JSON::XS->new; $json->ascii(1); @@ -33,13 +33,6 @@ use constant INSTITUTION_SUPPORTS => [ 'N', # renew all, ]; -# Cache instances cannot be created until opensrf is connected. -my $_cache; -sub cache { - $_cache = OpenSRF::Utils::Cache->new unless $_cache; - return $_cache; -} - sub new { my ($class, %args) = @_; return bless(\%args, $class); @@ -49,9 +42,9 @@ sub config { my $self = shift; return $self->{config} if $self->{config}; - my $group = $self->editor->retrieve_config_sip_setting_group([ + my $group = $self->editor->retrieve_sip_setting_group([ $self->sip_account->setting_group, - {flesh => 1, flesh_fields => {cssg => ['settings']}} + {flesh => 1, flesh_fields => {sipsetg => ['settings']}} ]); my $config = { @@ -67,20 +60,20 @@ sub config { return $self->{config} = $config; } -# Create a new sessesion from cached data. -sub from_cache { +# Retrieve an existing SIP session via SIP session token +sub find { my ($class, $seskey) = @_; - my $ses = cache()->get_cache("sip2_$seskey"); + my $session = $class->new(seskey => $seskey); + my $e = $session->editor; - if ($ses) { + my $ses = $e->retrieve_sip_session([ + $seskey, {flesh => 1, flesh_fields => {sipses => ['account']}}]); - my $session = $class->new( - seskey => $seskey, - sip_account => $ses->{sip_account} - ); + if ($ses) { + $session->sip_account($ses->account); - $session->editor->authtoken($ses->{ils_authtoken}); + $e->authtoken($ses->ils_token); return $session if $session->set_ils_account; @@ -88,7 +81,7 @@ sub from_cache { } else { - $logger->warn("SIP2: No session found in cache for key $seskey"); + $logger->warn("SIP2: No session found for key $seskey"); return undef; } } @@ -116,9 +109,10 @@ sub sip_account { # Returns true on success, false on failure to authenticate. sub set_ils_account { my $self = shift; + my $e = $self->editor; # Verify previously applied authtoken is still valid. - return 1 if $self->editor->authtoken && $self->editor->checkauth; + return 1 if $e->authtoken && $e->checkauth; my $seskey = $self->seskey; @@ -137,15 +131,22 @@ sub set_ils_account { return 0; } - my $ses = { - sip_account => $self->sip_account, - ils_authtoken => $auth->{payload}->{authtoken} - }; + # Ephemeral account sessions are not tracked in the database + return 1 if $U->is_true($self->sip_account->ephemeral); + + my $ses = Fieldmapper::sip::account->new; + $ses->key($seskey); + $ses->ils_token($auth->{payload}->{authtoken}); + $ses->account($self->sip_account->id); + + $e->xact_begin; + unless ($e->create_sip_session($ses)) { + $e->rolllback; + return 0; + } - $self->editor->authtoken($ses->{ils_authtoken}); - $self->editor->checkauth; + $e->xact_commit; - cache()->put_cache("sip2_$seskey", $ses); return 1; } diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.sip-config.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.sip-config.sql index f019bf99f9..985aee41ea 100644 --- a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.sip-config.sql +++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.sip-config.sql @@ -3,17 +3,21 @@ BEGIN; -- SELECT evergreen.upgrade_deps_block_check('TODO', :eg_version); +DROP SCHEMA IF EXISTS sip CASCADE; + +CREATE SCHEMA sip; + -- Collections of settings that can be linked to one or more SIP accounts. -CREATE TABLE config.sip_setting_group ( - id SERIAL PRIMARY KEY, +CREATE TABLE sip.setting_group ( + id SERIAL PRIMARY KEY, label TEXT UNIQUE NOT NULL, institution TEXT NOT NULL -- Duplicates OK ); -- Key/value setting pairs -CREATE TABLE config.sip_setting ( +CREATE TABLE sip.setting ( id SERIAL PRIMARY KEY, - setting_group INTEGER NOT NULL REFERENCES config.sip_setting_group (id) + setting_group INTEGER NOT NULL REFERENCES sip.setting_group (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, name TEXT NOT NULL, description TEXT NOT NULL, @@ -21,10 +25,10 @@ CREATE TABLE config.sip_setting ( CONSTRAINT name_once_per_inst UNIQUE (setting_group, name) ); -CREATE TABLE config.sip_account ( +CREATE TABLE sip.account ( id SERIAL PRIMARY KEY, enabled BOOLEAN NOT NULL DEFAULT TRUE, - setting_group INTEGER NOT NULL REFERENCES config.sip_setting_group (id) + setting_group INTEGER NOT NULL REFERENCES sip.setting_group (id) DEFERRABLE INITIALLY DEFERRED, sip_username TEXT NOT NULL, sip_password BIGINT NOT NULL REFERENCES actor.passwd @@ -32,7 +36,16 @@ CREATE TABLE config.sip_account ( usr BIGINT NOT NULL REFERENCES actor.usr(id) DEFERRABLE INITIALLY DEFERRED, workstation INTEGER REFERENCES actor.workstation(id), - av_format TEXT -- e.g. '3m' + -- sessions for ephemeral accounts are not tracked in sip.session + ephemeral BOOLEAN NOT NULL DEFAULT FALSE +); + +CREATE TABLE sip.session ( + key TEXT PRIMARY KEY, + ils_token TEXT NOT NULL UNIQUE, + account INTEGER NOT NULL REFERENCES sip.account(id) + ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, + create_time TIMESTAMPTZ NOT NULL DEFAULT NOW() ); -- SEED DATA @@ -40,16 +53,20 @@ CREATE TABLE config.sip_account ( INSERT INTO actor.passwd_type (code, name, login, crypt_algo, iter_count) VALUES ('sip2', 'SIP2 Client Password', FALSE, 'bf', 5); -INSERT INTO config.sip_setting_group (label, institution) +INSERT INTO sip.setting_group (label, institution) VALUES ('Example Setting Group', 'example'); -INSERT INTO config.sip_setting (setting_group, description, name, value) +INSERT INTO sip.setting (setting_group, description, name, value) VALUES ( (SELECT id FROM config.sip_setting_group WHERE institution = 'example'), 'Monetary amounts are reported in this currency', 'currency', '"USD"' ), ( (SELECT id FROM config.sip_setting_group WHERE institution = 'example'), + 'AV Format. Options: eg_legacy, 3m, swyer_a, swyer_b', + 'av_format', '"eg_legacy"' +), ( + (SELECT id FROM config.sip_setting_group WHERE institution = 'example'), 'Allow clients to request the SIP server status before login (message 99)', 'allow_sc_status_before_login', 'true' ), ( @@ -83,15 +100,14 @@ SELECT actor.set_passwd(1, 'sip2', 'sip_password'); INSERT INTO actor.workstation (name, owning_lib) VALUES ('BR1-SIP2-Gateway', 4); -INSERT INTO config.sip_account( - setting_group, sip_username, sip_password, usr, workstation, av_format +INSERT INTO sip.account( + setting_group, sip_username, sip_password, usr, workstation ) VALUES ( (SELECT id FROM config.sip_setting_group WHERE institution = 'example'), 'admin', (SELECT id FROM actor.passwd WHERE usr = 1 AND passwd_type = 'sip2'), 1, - (SELECT id FROM actor.workstation WHERE name = 'BR1-SIP2-Gateway'), - '3m' + (SELECT id FROM actor.workstation WHERE name = 'BR1-SIP2-Gateway') );