TT#122000 split session cookies per realm

* new Plugin Catalyst/Plugin/NGCP/RealmCookie.pm
  that extends Catalyst::Plugin::Session::State::Cookie
  and overloads methods responsible for cookie_name creation.
  It uses NGCP_REALM fastcgi header to append it to the cookie name.
  Empty cookie with name "appprefix"_session is suppressed on Session
  pre-setup.
* Base cookie_name is now set to 'ngcp-panel'

Change-Id: I6b4c10c5e1728d0dd7a6398bf5191925d5b904f6
mr9.5.1
Kirill Solomko 4 years ago
parent 4d72ec99e0
commit 61fc16dec8

@ -0,0 +1,43 @@
package Catalyst::Plugin::NGCP::RealmCookie;
use Moose;
use namespace::autoclean;
extends 'Catalyst::Plugin::Session::State::Cookie';
# prevents creation of an empty ..._session cookies during
# session pre-setup
sub setup_session {
my $c = shift;
$c->maybe::next::method(@_);
return;
}
sub get_cookie_name {
my $c = shift;
my $ngcp_api_realm = $c->request->env->{NGCP_REALM} // "";
my $cookie_name = $c->_session_plugin_config->{cookie_name} //
Catalyst::Utils::appprefix($c);
$cookie_name .= $ngcp_api_realm ? '_'.$ngcp_api_realm : '';
return $cookie_name;
}
sub update_session_cookie {
my ( $c, $updated ) = @_;
unless ( $c->cookie_is_rejecting( $updated ) ) {
my $cookie_name = $c->get_cookie_name;
$c->response->cookies->{$cookie_name} = $updated;
}
}
sub get_session_cookie {
my $c = shift;
my $cookie_name = $c->get_cookie_name;
return $c->request->cookies->{$cookie_name};
}
1;

@ -25,7 +25,7 @@ use Catalyst qw/
Authorization::Roles
Session
Session::Store::Redis
Session::State::Cookie
NGCP::RealmCookie
NGCP::EscapeSensitiveValue
NGCP::EscapeJs
I18N
@ -122,6 +122,7 @@ __PACKAGE__->config(
flash_to_stash => 1,
expires => 3600,
cookie_secure => 1,
cookie_name => 'ngcp-panel',
},
'Plugin::Authentication' => {

Loading…
Cancel
Save