Skip to content
Snippets Groups Projects
Commit 314cca48 authored by Guillaume ROUSSE's avatar Guillaume ROUSSE
Browse files

factorisation

parent 1737cbac
No related branches found
No related tags found
No related merge requests found
......@@ -66,21 +66,39 @@ sub init_db {
return $db;
}
sub check_authentication {
sub init_user {
my $self = shift;
my $headers = $self->req()->headers();
my $idp =
$ENV{'Shib_Identity_Provider'} || # local SP
$self->req()->headers()->header('Shib-Identity-Provider'); # remote SP
$ENV{'Shib_Identity_Provider'} || # local SP
$headers->header('Shib-Identity-Provider'); # remote SP
my $name =
$ENV{displayName} || # local SP
$headers->header('displayName'); # remote SP
my $user = {
idp => $idp,
name => $name
};
$self->stash(user => $user);
return $user;
}
sub check_authentication {
my $self = shift;
return $self->abort(
status => 401,
log_message => sprintf("unauthenticated user for action %s", $self->current_route()),
user_message => Registry::Error::AuthenticationRequired->new()
) if !$idp;
) if !$self->stash('user');
return 1;
}
sub check_token {
......
......@@ -15,12 +15,14 @@ sub run {
$self->init_db();
$self->init_l10n();
$self->init_user();
if ($config->{app}->{login_url}) {
return if !$self->check_authentication();
}
my $db = $self->stash('db');
my $db = $self->stash('db');
my $user = $self->stash('user');
my $sps = AccountManager::Entity->get_entities(
db => $db,
......@@ -31,12 +33,12 @@ sub run {
);
my $idp;
if ($ENV{HTTP_SHIB_IDENTITY_PROVIDER}) {
if ($user) {
my $idps = AccountManager::Entity->get_entities(
db => $db,
query => [
type => 'idp',
entityid => $ENV{HTTP_SHIB_IDENTITY_PROVIDER},
entityid => $user->{idp}
]
);
$idp = $idps->[0];
......
......@@ -13,6 +13,7 @@ sub run {
$self->init_db();
$self->init_l10n();
$self->init_user();
if ($config->{app}->{login_url}) {
return if !$self->check_authentication();
......
......@@ -20,6 +20,7 @@ sub run {
$self->init_db();
$self->init_l10n();
$self->init_user();
if ($config->{app}->{login_url}) {
return if !$self->check_authentication();
......@@ -29,6 +30,7 @@ sub run {
my $email = $self->param('email');
my $db = $self->stash('db');
my $l10n = $self->stash('l10n');
my $user = $self->stash('user');
my $sp = $self->get_sp(entityid => $entityid);
return if !$sp;
......@@ -103,14 +105,7 @@ sub run {
$base_templates_dir->child('mail'),
]
});
my $user =
$ENV{'HTTP_DISPLAYNAME'} ? $ENV{'HTTP_DISPLAYNAME'} :
$ENV{'displayName'} ? $ENV{'displayName'} :
undef;
my $idp =
$ENV{'HTTP_SHIB_IDENTITY_PROVIDER'} ? $ENV{'HTTP_SHIB_IDENTITY_PROVIDER'} :
$ENV{'Shib-Identity-Provider'} ? $ENV{'Shib-Identity-Provider'} :
undef;
my $data = {
app => {
url => $config->{app}->{url},
......@@ -118,9 +113,9 @@ sub run {
version => $config->{app}->{version},
name => $config->{app}->{name},
},
user => $user,
user => $user->{name},
source_ip => $self->client_ip(),
idp => { entityid => $idp, },
idp => { entityid => $user->{idp}, },
sp => { entityid => $entityid, },
to => $email,
token => $token->secret(),
......
......@@ -21,6 +21,7 @@ sub run {
$self->init_db();
$self->init_l10n();
$self->init_user();
if ($config->{app}->{login_url}) {
return if !$self->check_authentication();
......
......@@ -21,6 +21,7 @@ sub run {
$self->init_db();
$self->init_l10n();
$self->init_user();
if ($config->{app}->{login_url}) {
return if !$self->check_authentication();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment