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

full control over multiple SPs blocks

parent b8b20d50
No related branches found
No related tags found
No related merge requests found
...@@ -11,12 +11,23 @@ templates_dir = @templatesdir@ ...@@ -11,12 +11,23 @@ templates_dir = @templatesdir@
templates_theme = edugain templates_theme = edugain
accounts_file = /var/lib/access-check/accounts.php accounts_file = /var/lib/access-check/accounts.php
[federations] [groups]
list = edugain list = self, renater, edugain
[self]
type = organization
label = my own organization
[renater]
type = metadata
file = /var/lib/access-check/renater.xml
label = fédération Education-Recherche
[edugain] [edugain]
metadata = /var/lib/access-check/edugain.xml type = link
url = https://access-check.edugain.org
label = eduGAIN label = eduGAIN
message = eduGAIN Access Check
[logger] [logger]
file = /var/log/access-check/manager.log file = /var/log/access-check/manager.log
......
...@@ -112,7 +112,7 @@ sub new { ...@@ -112,7 +112,7 @@ sub new {
); );
} }
if (!$self->{configuration}->{federations}->{list}) { if (!$self->{configuration}->{groups}->{list}) {
$self->{logger}->fatal( $self->{logger}->fatal(
"No federations defined in configuration, aborting" "No federations defined in configuration, aborting"
); );
...@@ -202,8 +202,6 @@ sub respond { ...@@ -202,8 +202,6 @@ sub respond {
$theme_templates_dir : $theme_templates_dir :
$default_templates_dir; $default_templates_dir;
$Template::Stash::PRIVATE = undef;
my $tt2 = Template->new({ my $tt2 = Template->new({
ENCODING => 'utf8', ENCODING => 'utf8',
PRE_CHOMP => CHOMP_ONE, PRE_CHOMP => CHOMP_ONE,
...@@ -255,18 +253,17 @@ sub req_select_sp { ...@@ -255,18 +253,17 @@ sub req_select_sp {
$self->check_authentication(action => 'select_sp') $self->check_authentication(action => 'select_sp')
if $self->{configuration}->{app}->{login_url}; if $self->{configuration}->{app}->{login_url};
my @federations = split(/, */, $self->{configuration}->{federations}->{list});
my @groups; my @groups;
my @self_entities; my @organization_entities;
foreach my $federation (@federations) {
if ($self->{configuration}->{$federation}->{metadata}) { foreach my $id (split(/, */, $self->{configuration}->{groups}->{list})) {
my $file = $self->get_metadata_file(federation => $federation); my $spec = $self->{configuration}->{$id};
if ($spec->{type} eq 'metadata') {
my $metadata; my $metadata;
eval { eval {
$metadata = AccountManager::Metadata->new( $metadata = AccountManager::Metadata->new(
file => $file file => $spec->{file}
); );
}; };
$self->abort( $self->abort(
...@@ -276,13 +273,14 @@ sub req_select_sp { ...@@ -276,13 +273,14 @@ sub req_select_sp {
my $entities = $metadata->parse(type => 'sp'); my $entities = $metadata->parse(type => 'sp');
push @groups, { push @groups, {
id => $federation, id => $id,
label => $self->{configuration}->{$federation}->{label}, label => $spec->{label},
type => 'list',
entities => [ entities => [
map { { map { {
id => $_->{entityid}, id => $_->{entityid},
name => $_->{display_name}, name => $_->{display_name},
federation => $federation federation => $id
} } @$entities } } @$entities
] ]
}; };
...@@ -297,36 +295,37 @@ sub req_select_sp { ...@@ -297,36 +295,37 @@ sub req_select_sp {
$self->{logger}->debugf( $self->{logger}->debugf(
"idp %s found in federation %s metadata with organization %s", "idp %s found in federation %s metadata with organization %s",
$ENV{HTTP_SHIB_IDENTITY_PROVIDER}, $ENV{HTTP_SHIB_IDENTITY_PROVIDER},
$federation, $id,
$organization $organization
); );
push @self_entities, push @organization_entities,
map { { map { {
id => $_->{entityid}, id => $_->{entityid},
name => $_->{display_name}, name => $_->{display_name},
federation => $federation federation => $id
} } } }
grep { $_->{organization} eq $organization } grep { $_->{organization} eq $organization }
@$entities; @$entities;
} }
} }
} elsif ($self->{configuration}->{$federation}->{link}) { } elsif ($spec->{type} eq 'organization') {
push @groups, {
id => $id,
label => $spec->{label},
type => 'list',
entities => \@organization_entities,
};
} elsif ($spec->{type} eq 'link') {
push @groups, { push @groups, {
id => $federation, id => $id,
label => $self->{configuration}->{$federation}->{label}, label => $spec->{label},
link => $self->{configuration}->{$federation}->{link}, type => 'link',
url => $spec->{url},
message => $spec->{message},
}; };
} }
} }
if (@self_entities) {
unshift @groups, {
id => '_self',
label => $self->{lh}->maketext("My organization"),
entities => \@self_entities,
};
}
$self->respond( $self->respond(
template => 'select_sp.tt2.html', template => 'select_sp.tt2.html',
data => { data => {
......
...@@ -15,22 +15,22 @@ ...@@ -15,22 +15,22 @@
[% lh.maketext("You must be an administrator of that service to continue afterwards.") %] [% lh.maketext("You must be an administrator of that service to continue afterwards.") %]
</p> </p>
[% FOREACH group IN groups() %] [% FOREACH group IN groups() %]
<fieldset> <fieldset>
[% IF group.entities %]
<legend>[% group.label %]</legend> <legend>[% group.label %]</legend>
[% SWITCH group.type %]
[% CASE 'list' %]
<select id="[% group.id %]" name="[% group.id %]"> <select id="[% group.id %]" name="[% group.id %]">
<option value=""></option> <option value=""></option>
[% FOREACH entity IN group.entities.sort('name') %] [% FOREACH entity IN group.entities.sort('name') %]
<option value="[% entity.id %]" data-federation="[% entity.federation %]">[% entity.name %]</option> <option value="[% entity.id %]" data-federation="[% entity.federation %]">[% entity.name %]</option>
[% END %] [% END %]
</select> </select>
[% END %] [% CASE 'link' %]
[% IF group.link %] <a class="button" href="[% group.url %]">[% group.label %]</a>
<a class="button" href="[% group.link %]">[% group.label %]</a> [% END %]
[% END %]
</fieldset> </fieldset>
[% END %] [% END %]
<input type="hidden" id="federation" name="federation"/> <input type="hidden" id="federation" name="federation"/>
<input type="hidden" id="entityid" name="entityid"/> <input type="hidden" id="entityid" name="entityid"/>
......
...@@ -15,22 +15,22 @@ ...@@ -15,22 +15,22 @@
[% lh.maketext("You must be an administrator of that service to continue afterwards.") %] [% lh.maketext("You must be an administrator of that service to continue afterwards.") %]
</p> </p>
[% FOREACH group IN groups %] [% FOREACH group IN groups %]
<fieldset> <fieldset>
[% IF group.entities %]
<legend>[% group.label %]</legend> <legend>[% group.label %]</legend>
[% SWITCH group.type %]
[% CASE 'list' %]
<select id="[% group.id %]" name="[% group.id %]"> <select id="[% group.id %]" name="[% group.id %]">
<option value=""></option> <option value=""></option>
[% FOREACH entity IN group.entities.sort('name') %] [% FOREACH entity IN group.entities.sort('name') %]
<option value="[% entity.id %]" data-federation="[% entity.federation %]">[% entity.name %]</option> <option value="[% entity.id %]" data-federation="[% entity.federation %]">[% entity.name %]</option>
[% END %] [% END %]
</select> </select>
[% END %] [% CASE 'link' %]
[% IF group.link %] <a class="button" href="[% group.url %]">[% group.message %]</a>
<a class="button" href="[% group.link %]">[% group.label %]</a> [% END %]
[% END %]
</fieldset> </fieldset>
[% END %] [% END %]
<input type="hidden" id="federation" name="federation"/> <input type="hidden" id="federation" name="federation"/>
<input type="hidden" id="entityid" name="entityid"/> <input type="hidden" id="entityid" name="entityid"/>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment