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

fetch entities from database

parent c6f77306
No related branches found
No related tags found
No related merge requests found
...@@ -261,60 +261,47 @@ sub req_select_sp { ...@@ -261,60 +261,47 @@ sub req_select_sp {
my $spec = $self->{configuration}->{$id}; my $spec = $self->{configuration}->{$id};
if ($spec->{type} eq 'metadata') { if ($spec->{type} eq 'metadata') {
my $metadata; my $entities = AccountManager::Entity->get_entities(
eval { db => $self->{db},
$metadata = AccountManager::Metadata->new( query => [
file => $spec->{file} type => { eq => 'sp' },
); federations => { like => "%\"$id\"%" }
}; ],
$self->abort( debug => 1
log => "Failed to load federation metadata: $EVAL_ERROR", );
user => "internal"
) if $EVAL_ERROR;
my $entities = $metadata->parse(type => 'sp');
push @groups, { push @groups, {
id => $id, id => $id,
label => $spec->{label}, label => $spec->{label},
type => 'list', type => 'list',
entities => [ entities => $entities
map { {
id => $_->{entityid},
name => $_->{display_name},
federation => $id
} } @$entities
]
}; };
# if user is authenticated, and its IdP is found in metadata,
# push all entities with the same organization URL in a list
if ($ENV{HTTP_SHIB_IDENTITY_PROVIDER}) {
my $idps = $metadata->parse(id => $ENV{HTTP_SHIB_IDENTITY_PROVIDER});
my $idp = $idps->[0];
if ($idp) {
my $organization = $idp->{organization};
$self->{logger}->debugf(
"idp %s found in federation %s metadata with organization %s",
$ENV{HTTP_SHIB_IDENTITY_PROVIDER},
$id,
$organization
);
push @organization_entities,
map { {
id => $_->{entityid},
name => $_->{display_name},
federation => $id
} }
grep { $_->{organization} eq $organization }
@$entities;
}
}
} elsif ($spec->{type} eq 'organization') { } elsif ($spec->{type} eq 'organization') {
next unless $ENV{HTTP_SHIB_IDENTITY_PROVIDER};
my $idps = AccountManager::Entity->get_entities(
db => $self->{db},
query => [
type => 'idp',
entityid => $ENV{HTTP_SHIB_IDENTITY_PROVIDER},
]
);
my $idp = $idps->[0];
next unless $idp;
my $entities = AccountManager::Entity->get_entities(
db => $self->{db},
query => [
type => 'sp',
organization_url => $idp->organization_url()
]
);
push @groups, { push @groups, {
id => $id, id => $id,
label => $spec->{label}, label => $spec->{label},
type => 'list', type => 'list',
entities => \@organization_entities, entities => $entities
}; };
} elsif ($spec->{type} eq 'link') { } elsif ($spec->{type} eq 'link') {
push @groups, { push @groups, {
...@@ -342,52 +329,16 @@ sub req_select_email { ...@@ -342,52 +329,16 @@ sub req_select_email {
$self->check_authentication(action => 'select_email') $self->check_authentication(action => 'select_email')
if $self->{configuration}->{app}->{login_url}; if $self->{configuration}->{app}->{login_url};
my $entityid = $self->get_parameter(name => 'entityid'); my $entityid = $self->get_parameter(name => 'entityid');
my $federation = $self->get_parameter(name => 'federation');
# Create a persistent service provider object
my $sp = AccountManager::Entity->new( my $sp = AccountManager::Entity->new(
db => $self->{db}, db => $self->{db},
entityid => $entityid entityid => $entityid
); );
$self->abort(
if ($sp->load(speculative => 1)) { log => sprintf("No such SP '%s' in database", $entityid),
# already present in DB, nothing todo user => "no_such_entity"
} else { ) if !$sp->load(speculative => 1);
# extract information from metadata
my $file = $self->get_metadata_file(federation => $federation);
my $metadata;
eval {
$metadata = AccountManager::Metadata->new(
file => $file
);
};
$self->abort(
log => "Failed to load federation metadata: $EVAL_ERROR",
user => "internal"
) if $EVAL_ERROR;
my $entities = $metadata->parse(id => $entityid);
my $entity = $entities->[0];
$self->abort(
log => "No such SP $entityid in metadata",
user => "no_such_entity"
) if !$entity;
# complete persistent object
$sp->displayname($entity->{display_name});
$sp->url($entity->{url});
$sp->contacts(uniq map { $_->{EmailAddress} } @{$entity->{contacts}})
if $entity->{contacts};
# save in DB
$self->abort(
log => "Failed to save service provider",
user => "internal"
) if !$sp->save();
}
# override metadata contacts if needed # override metadata contacts if needed
my $contacts = my $contacts =
...@@ -406,10 +357,9 @@ sub req_select_email { ...@@ -406,10 +357,9 @@ sub req_select_email {
$self->respond( $self->respond(
template => 'select_email.tt2.html', template => 'select_email.tt2.html',
data => { data => {
action => 'select_email', action => 'select_email',
federation => $federation, sp => $sp,
sp => $sp, entityid => $entityid,
entityid => $entityid,
} }
); );
} }
......
...@@ -22,8 +22,8 @@ ...@@ -22,8 +22,8 @@
[% CASE 'list' %] [% 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('display_name') %]
<option value="[% entity.id %]" data-federation="[% entity.federation %]">[% entity.name %]</option> <option value="[% entity.entityid %]">[% entity.display_name %]</option>
[% END %] [% END %]
</select> </select>
[% CASE 'link' %] [% CASE 'link' %]
...@@ -31,7 +31,6 @@ ...@@ -31,7 +31,6 @@
[% END %] [% END %]
</fieldset> </fieldset>
[% END %] [% END %]
<input type="hidden" id="federation" name="federation"/>
<input type="hidden" id="entityid" name="entityid"/> <input type="hidden" id="entityid" name="entityid"/>
<div class="callout primary">[% lh.maketext("Those service providers have been extracted from the selected federation metadata.") %]</div> <div class="callout primary">[% lh.maketext("Those service providers have been extracted from the selected federation metadata.") %]</div>
...@@ -187,8 +186,9 @@ $( document ).ready(function() { ...@@ -187,8 +186,9 @@ $( document ).ready(function() {
} }
}); });
[% FOREACH group IN groups.keys() %] [% FOREACH group IN groups %]
$( "#[% group %]" ).combobox(); [% NEXT IF group.type != 'list' %]
$( "#[% group.id %]" ).combobox();
[% END %] [% END %]
$.validator.messages.required = "[% lh.maketext("This information is required") %]"; $.validator.messages.required = "[% lh.maketext("This information is required") %]";
......
...@@ -22,16 +22,15 @@ ...@@ -22,16 +22,15 @@
[% CASE 'list' %] [% 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('display_name') %]
<option value="[% entity.id %]" data-federation="[% entity.federation %]">[% entity.name %]</option> <option value="[% entity.entityid %]">[% entity.display_name %]</option>
[% END %] [% END %]
</select> </select>
[% CASE 'link' %] [% CASE 'link' %]
<a class="button" href="[% group.url %]">[% lh.maketext(group.message) %]</a> <a class="button" href="[% group.url %]">[% lh.maketext(group.message) %]</a>
[% END %] [% END %]
</fieldset> </fieldset>
[% END %] [% END %]
<input type="hidden" id="federation" name="federation"/>
<input type="hidden" id="entityid" name="entityid"/> <input type="hidden" id="entityid" name="entityid"/>
<div class="callout alert-callout-border primary">[% lh.maketext("Those service providers have been extracted from the selected federation metadata.") %]</div> <div class="callout alert-callout-border primary">[% lh.maketext("Those service providers have been extracted from the selected federation metadata.") %]</div>
...@@ -92,8 +91,6 @@ $( document ).ready(function() { ...@@ -92,8 +91,6 @@ $( document ).ready(function() {
// retrieve federation and entityid // retrieve federation and entityid
var entity = this.element.val(); var entity = this.element.val();
var federation = this.element.find('option:selected').attr('data-federation');
$("#federation").val(federation);
$("#entityid").val(entity); $("#entityid").val(entity);
}, },
...@@ -188,8 +185,9 @@ $( document ).ready(function() { ...@@ -188,8 +185,9 @@ $( document ).ready(function() {
} }
}); });
[% FOREACH group IN groups.keys() %] [% FOREACH group IN groups %]
$( "#[% group %]" ).combobox(); [% NEXT IF group.type != 'list' %]
$( "#[% group.id %]" ).combobox();
[% END %] [% END %]
$.validator.messages.required = "[% lh.maketext("This information is required") %]"; $.validator.messages.required = "[% lh.maketext("This information is required") %]";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment