diff --git a/lib/Catalyst/Plugin/NGCP/RealmCookie.pm b/lib/Catalyst/Plugin/NGCP/RealmCookie.pm new file mode 100644 index 0000000000..2069f53488 --- /dev/null +++ b/lib/Catalyst/Plugin/NGCP/RealmCookie.pm @@ -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; diff --git a/lib/NGCP/Panel.pm b/lib/NGCP/Panel.pm index 3ac04d6fed..71793bbae6 100644 --- a/lib/NGCP/Panel.pm +++ b/lib/NGCP/Panel.pm @@ -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' => {