</permacrud>
</class>
- <class id="cssg" controller="open-ils.cstore open-ils.pcrud"
- oils_obj:fieldmapper="config::sip_setting_group"
- oils_persist:tablename="config.sip_setting_group"
+ <class id="sipsetg" controller="open-ils.cstore open-ils.pcrud"
+ oils_obj:fieldmapper="sip.setting_group"
+ oils_persis:tablename="sip.setting_group"
reporter:label="SIP Settings Group">
- <fields oils_persist:primary="id" oils_persist:sequence="config.sip_setting_id_seq">
- <field name="id" reporter:datatype="id" reporter:label="ID" reporter:selector="sip_username"/>
+ <fields oils_persist:primary="id" oils_persist:sequence="sip.setting_id_seq">
+ <field name="id" reporter:datatype="id" reporter:label="ID" reporter:selector="label"/>
<field name="label" reporter:datatype="text" reporter:label="Label" oils_obj:required="true"/>
<field name="institution" reporter:datatype="text" reporter:label="SIP Institution" oils_obj:required="true"/>
<field name="settings" reporter:datatype="link" reporter:label="Settings" oils_persist:virtual="true"/>
</fields>
<links>
- <link field="settings" reltype="has_many" key="setting_group" map="" class="css"/>
+ <link field="settings" reltype="has_many" key="setting_group" map="" class="sipset"/>
</links>
<permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
<actions>
</actions>
</permacrud>
</class>
- <class id="css" controller="open-ils.cstore open-ils.pcrud"
- oils_obj:fieldmapper="config::sip_setting"
- oils_persist:tablename="config.sip_setting"
+ <class id="sipset" controller="open-ils.cstore open-ils.pcrud"
+ oils_obj:fieldmapper="sip::setting"
+ oils_persist:tablename="sip.setting"
reporter:label="SIP Settings">
- <fields oils_persist:primary="id" oils_persist:sequence="config.sip_setting_id_seq">
- <field name="id" reporter:datatype="id" reporter:label="ID" reporter:selector="sip_username"/>
+ <fields oils_persist:primary="id" oils_persist:sequence="sip.setting_id_seq">
+ <field name="id" reporter:datatype="id" reporter:label="ID" reporter:selector="name"/>
<field name="setting_group" reporter:datatype="link" reporter:label="Settings Group" oils_obj:required="true"/>
<field name="name" reporter:datatype="text" reporter:label="Name" oils_obj:required="true"/>
<field name="description" reporter:datatype="text" reporter:label="Description" oils_obj:required="true"/>
<field name="value" reporter:datatype="text" reporter:label="Value" oils_obj:required="true"/>
</fields>
<links>
- <link field="setting_group" reltype="has_a" key="id" map="" class="cssg"/>
+ <link field="setting_group" reltype="has_a" key="id" map="" class="sipsetg"/>
</links>
<permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
<actions>
</actions>
</permacrud>
</class>
- <class id="csa" controller="open-ils.cstore open-ils.pcrud"
- oils_obj:fieldmapper="config::sip_account"
- oils_persist:tablename="config.sip_account"
- reporter:label="SIP AccountS">
- <fields oils_persist:primary="id" oils_persist:sequence="config.sip_account_id_seq">
+ <class id="sipacc" controller="open-ils.cstore open-ils.pcrud"
+ oils_obj:fieldmapper="sip::account"
+ oils_persist:tablename="sip.account"
+ reporter:label="SIP Account">
+ <fields oils_persist:primary="id" oils_persist:sequence="sip.account_id_seq">
<field name="id" reporter:datatype="id" reporter:label="ID" reporter:selector="sip_username"/>
<field name="enabled" reporter:datatype="bool" reporter:label="Enabled"/>
<field name="setting_group" reporter:datatype="link" reporter:label="Settings Group" oils_obj:required="true"/>
<field name="sip_username" reporter:datatype="text" reporter:label="SIP Username" oils_obj:required="true"/>
<field name="usr" reporter:datatype="link" reporter:label="ILS User" oils_obj:required="true"/>
<field name="workstation" reporter:datatype="link" reporter:label="Workstation"/>
- <field name="av_format" reporter:datatype="text" reporter:label="SIP AV Format"/>
+ <field name="ephemeral" reporter:datatype="bool" reporter:label="Ephemeral"/>
</fields>
<links>
<link field="usr" reltype="has_a" key="id" map="" class="au"/>
<link field="workstation" reltype="has_a" key="id" map="" class="aws"/>
- <link field="setting_group" reltype="has_a" key="id" map="" class="cssg"/>
+ <link field="setting_group" reltype="has_a" key="id" map="" class="sipsetg"/>
</links>
<permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
<actions>
</actions>
</permacrud>
</class>
+ <class id="sipses" controller="open-ils.cstore"
+ oils_obj:fieldmapper="sip::session"
+ oils_persist:tablename="sip.session"
+ reporter:label="SIP Session">
+ <fields oils_persist:primary="token">
+ <field name="key" reporter:datatype="text" reporter:label="SIP Session Key"/>
+ <field name="ils_token" reporter:datatype="text" reporter:label="ILS Auth Token"/>
+ <field name="account" reporter:datatype="link" reporter:label="SIP Account"/>
+ <field name="create_time" reporter:label="Create Time" reporter:datatype="timestamp"/>
+ </fields>
+ <links>
+ <link field="account" reltype="has_a" key="id" map="" class="sipacc"/>
+ </links>
+ </class>
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) {
sub handle_sc_status {
my ($seskey, $message) = @_;
- my $session = OpenILS::Application::SIPSession->from_cache($seskey);
+ my $session = OpenILS::Application::SIPSession->find($seskey);
my $config;
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" &&
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);
'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);
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 = {
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;
} else {
- $logger->warn("SIP2: No session found in cache for key $seskey");
+ $logger->warn("SIP2: No session found for key $seskey");
return undef;
}
}
# 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;
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;
}
-- 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,
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
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
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'
), (
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')
);