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

return extracted metadata directly

parent 2dd375b9
No related branches found
No related tags found
No related merge requests found
...@@ -158,13 +158,11 @@ sub parse_federation_metadata { ...@@ -158,13 +158,11 @@ sub parse_federation_metadata {
}; };
die "unable to load federation metadata: $EVAL_ERROR" if $EVAL_ERROR; die "unable to load federation metadata: $EVAL_ERROR" if $EVAL_ERROR;
my %args; my $data;
if ($options{sp_entityid}) {
$args{filter_entity_id} = $options{sp_entityid};
}
eval { eval {
$federation_metadata->parse(%args); $data = $federation_metadata->parse(
entity_id => $options{sp_entityid},
);
}; };
die "unable to parse federation metadata: $EVAL_ERROR\n" if $EVAL_ERROR; die "unable to parse federation metadata: $EVAL_ERROR\n" if $EVAL_ERROR;
...@@ -173,9 +171,7 @@ sub parse_federation_metadata { ...@@ -173,9 +171,7 @@ sub parse_federation_metadata {
## List SAML entities ## List SAML entities
printf "Hashref representing the metadata:\n"; printf "Hashref representing the metadata:\n";
IdPAccountManager::Tools::dump_var( IdPAccountManager::Tools::dump_var($data, 0, \*STDOUT);
$federation_metadata->{federation_metadata_as_hashref},
0, \*STDOUT);
} }
......
...@@ -39,42 +39,9 @@ sub new { ...@@ -39,42 +39,9 @@ sub new {
sub parse { sub parse {
my ($self, %args) = @_; my ($self, %args) = @_;
my %parser_args = (
metadata_as_xml => $self->{doc},
filter_entity_type => 'sp'
);
if ($args{filter_entity_id}) {
$parser_args{filter_entity_id} = $args{filter_entity_id};
}
$self->{federation_metadata_as_hashref} =
$self->_parse_saml_metadata(%parser_args);
die "Failed to parse federation metadata"
unless defined $self->{federation_metadata_as_hashref};
return 1;
}
## Dumps the SAML metadata content
sub print {
my ($self, $fd) = @_;
$fd = \*STDOUT unless $fd;
my $root = $self->{doc}->documentElement();
print $fd $root->toString();
}
## Parse a SAML federation metadata file
sub _parse_saml_metadata {
my ($self, %args) = @_;
my $root = $args{metadata_as_xml};
my @extracted_array; my @extracted_array;
foreach my $EntityDescriptor ( foreach my $EntityDescriptor (
@{ $root->getElementsByLocalName('EntityDescriptor') }) @{ $self->{doc}->getElementsByLocalName('EntityDescriptor') })
{ {
my $extracted_data = {}; my $extracted_data = {};
...@@ -85,9 +52,8 @@ sub _parse_saml_metadata { ...@@ -85,9 +52,8 @@ sub _parse_saml_metadata {
} }
} }
next next if ($args{entity_id}
if ($args{filter_entity_id} && ($args{entity_id} ne $extracted_data->{entityid}));
&& ($args{filter_entity_id} ne $extracted_data->{entityid}));
$extracted_data->{xml_md} = $extracted_data->{xml_md} =
IdPAccountManager::Tools::escape_xml($EntityDescriptor->toString()); IdPAccountManager::Tools::escape_xml($EntityDescriptor->toString());
...@@ -283,6 +249,15 @@ sub _parse_saml_metadata { ...@@ -283,6 +249,15 @@ sub _parse_saml_metadata {
return \@extracted_array; return \@extracted_array;
} }
## Dumps the SAML metadata content
sub print {
my ($self, $fd) = @_;
$fd = \*STDOUT unless $fd;
my $root = $self->{doc}->documentElement();
print $fd $root->toString();
}
1; 1;
__END__ __END__
......
...@@ -249,7 +249,7 @@ sub req_account_wizard { ...@@ -249,7 +249,7 @@ sub req_account_wizard {
} }
eval { eval {
$federation_metadata->parse(); $self->{param_out} = $federation_metadata->parse();
}; };
if ($EVAL_ERROR) { if ($EVAL_ERROR) {
push @{ $self->{param_out}->{errors} }, "internal"; push @{ $self->{param_out}->{errors} }, "internal";
...@@ -260,9 +260,6 @@ sub req_account_wizard { ...@@ -260,9 +260,6 @@ sub req_account_wizard {
return undef; return undef;
} }
$self->{param_out}->{federation_metadata_as_hashref} =
$federation_metadata->{federation_metadata_as_hashref};
return 1; return 1;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment