This commit is contained in:
Maxime Besson 2021-06-29 15:23:02 +02:00
parent ff09c8856f
commit 2c7ba2d057

View File

@ -7,7 +7,6 @@ use LWP::UserAgent;
use MIME::Base64;
use XML::LibXML;
sub toEntityIDkey {
my ( $prefix, $entityID ) = @_;
@ -18,7 +17,6 @@ sub toEntityIDkey {
return ( $prefix . $entityIDKey );
}
#==============================================================================
# Get command line options
#==============================================================================
@ -53,7 +51,8 @@ if ( $opts{help} or !$opts{metadata} ) {
print STDERR "\t-a (--nagios) : output statistics in Nagios format\n";
print STDERR "\t-n (--dry-run): do nothing\n";
print STDERR "\t-v (--verbose): display all actions\n";
print STDERR "\t-r (--remove): remove entityID inside LemonLDAP if was remove inside remote metadata\n";
print STDERR
"\t-r (--remove): remove entityID inside LemonLDAP if was remove inside remote metadata\n";
exit 1;
}
@ -61,9 +60,6 @@ if ( $opts{help} or !$opts{metadata} ) {
# Default values
#==============================================================================
my $spConfKeyPrefix = $opts{spconfprefix} || "sp-";
my $idpConfKeyPrefix = $opts{idpconfprefix} || "idp-";
@ -235,12 +231,13 @@ foreach
# test if IDP entityID is inside the block list
if ( $entityID ~~ @idpIgnorelist ) {
if ( grep { $entityID eq $_ } @idpIgnorelist ) {
if ( $opts{verbose} ) {
print "IDP $entityID won't be update/added \n";
}
$idpCounter->{ignored}++;
}else{
}
else {
# Check if entityID already in configuration
if ( defined $idpList->{$entityID} ) {
@ -253,8 +250,8 @@ foreach
->{ $idpList->{$entityID} } = $exportedAttributes;
# Update options
$lastConf->{samlIDPMetaDataOptions}->{ $idpList->{$entityID} }
= $idpOptions;
$lastConf->{samlIDPMetaDataOptions}
->{ $idpList->{$entityID} } = $idpOptions;
if ( $opts{verbose} ) {
print "Update IDP $entityID in configuration\n";
@ -270,11 +267,12 @@ foreach
->{samlIDPMetaDataXML} = $partner_metadata;
# Attributes
$lastConf->{samlIDPMetaDataExportedAttributes}->{$confKey} =
$exportedAttributes;
$lastConf->{samlIDPMetaDataExportedAttributes}->{$confKey}
= $exportedAttributes;
# Options
$lastConf->{samlIDPMetaDataOptions}->{$confKey} = $idpOptions;
$lastConf->{samlIDPMetaDataOptions}->{$confKey} =
$idpOptions;
if ( $opts{verbose} ) {
print
@ -352,17 +350,18 @@ foreach
my $partner_metadata = $partner->toString;
$partner_metadata =~ s/\n//g;
# test if IDP entityID is inside the block list
if ( $entityID ~~ @spIgnorelist ) {
if ( grep { $entityID eq $_ } @spIgnorelist ) {
if ( $opts{verbose} ) {
print "SP $entityID won't be update/added \n";
}
$spCounter->{ignored}++;
}else{
}
else {
# Check if entityID already in configuration
if ( defined $spList->{$entityID} ) {
# Update metadata
$lastConf->{samlSPMetaDataXML}->{ $spList->{$entityID} }
->{samlSPMetaDataXML} = $partner_metadata;
@ -375,8 +374,8 @@ foreach
# $lastConf->{samlSPMetaDataOptions}->{ $spList->{$entityID} } =
# $spOptions;
# FIX AGA
$lastConf->{samlSPMetaDataOptions}->{ $spList->{$entityID} } =
{ %{$spOptions } };
$lastConf->{samlSPMetaDataOptions}->{ $spList->{$entityID} }
= { %{$spOptions} };
if ( $opts{verbose} ) {
print "Update SP $entityID in configuration\n";
@ -388,8 +387,8 @@ foreach
my $confKey = toEntityIDkey( $spConfKeyPrefix, $entityID );
# Metadata
$lastConf->{samlSPMetaDataXML}->{$confKey}->{samlSPMetaDataXML}
= $partner_metadata;
$lastConf->{samlSPMetaDataXML}->{$confKey}
->{samlSPMetaDataXML} = $partner_metadata;
# Attributes
$lastConf->{samlSPMetaDataExportedAttributes}->{$confKey} =
@ -399,7 +398,8 @@ foreach
# $lastConf->{samlSPMetaDataOptions}->{$confKey} = $spOptions;
# FIX AGA
$lastConf->{samlSPMetaDataOptions}->{$confKey} = { %{$spOptions } };
$lastConf->{samlSPMetaDataOptions}->{$confKey} =
{ %{$spOptions} };
if ( $opts{verbose} ) {
print
@ -407,10 +407,12 @@ foreach
}
$spCounter->{created}++;
}
# handle eduPersonTargetedID
if ( $requestedAttributes->{eduPersonTargetedID} ) {
delete $requestedAttributes->{eduPersonTargetedID};
$lastConf->{samlSPMetaDataOptions}->{ $spList->{$entityID} }->{samlSPMetaDataOptionsNameIDFormat} = 'persistent';
$lastConf->{samlSPMetaDataOptions}->{ $spList->{$entityID} }
->{samlSPMetaDataOptionsNameIDFormat} = 'persistent';
}
}
@ -429,10 +431,10 @@ foreach
# Remove partners
if ( $opts{remove} ) {
foreach ( keys %$idpList ) {
my $idpConfKey = $idpList->{$_};
unless ( defined $mdIdpList->{$_} ) {
if ( $_ ~~ @idpIgnorelist ) {
foreach my $entityID ( keys %$idpList ) {
my $idpConfKey = $idpList->{$entityID};
unless ( defined $mdIdpList->{$entityID} ) {
if ( grep { $entityID eq $_ } @idpIgnorelist ) {
$idpCounter->{ignored}++;
if ( $opts{verbose} ) {
print "IDP $idpConfKey won't be deleted \n";
@ -451,10 +453,10 @@ if ( $opts{remove} ) {
}
}
foreach ( keys %$spList ) {
my $spConfKey = $spList->{$_};
unless ( defined $mdSpList->{$_} ) {
if ( $_ ~~ @spIgnorelist ) {
foreach my $entityID ( keys %$spList ) {
my $spConfKey = $spList->{$entityID};
unless ( defined $mdSpList->{$entityID} ) {
if ( grep { $entityID eq $_ } @spIgnorelist ) {
$spCounter->{ignored}++;
if ( $opts{verbose} ) {
print "SP $spConfKey won't be deleted \n";
@ -462,7 +464,8 @@ if ( $opts{remove} ) {
}
else {
delete $lastConf->{samlSPMetaDataXML}->{$spConfKey};
delete $lastConf->{samlSPMetaDataExportedAttributes}->{$spConfKey};
delete $lastConf->{samlSPMetaDataExportedAttributes}
->{$spConfKey};
delete $lastConf->{samlSPMetaDataOptions}->{$spConfKey};
$spCounter->{removed}++;
if ( $opts{verbose} ) {
@ -498,21 +501,35 @@ else {
}
}
if ( $opts{nagios} ) {
print "Metadata loaded inside Conf: [".$numConf."]|idp_found=".$idpCounter->{found}
.", idp_updated=".$idpCounter->{updated}
.", idp_created=".$idpCounter->{created}
.", idp_removed=".$idpCounter->{removed}
.", idp_rejected=".$idpCounter->{rejected}
.", idp_ignored=".$idpCounter->{ignored}
.", sp_found=".$spCounter->{found}
.", sp_updated=".$spCounter->{updated}
.", sp_created=".$spCounter->{created}
.", sp_removed=".$spCounter->{removed}
.", sp_rejected=".$spCounter->{rejected}
.", sp_ignored=".$spCounter->{ignored}."\n";
}else{
print "Metadata loaded inside Conf: ["
. $numConf
. "]|idp_found="
. $idpCounter->{found}
. ", idp_updated="
. $idpCounter->{updated}
. ", idp_created="
. $idpCounter->{created}
. ", idp_removed="
. $idpCounter->{removed}
. ", idp_rejected="
. $idpCounter->{rejected}
. ", idp_ignored="
. $idpCounter->{ignored}
. ", sp_found="
. $spCounter->{found}
. ", sp_updated="
. $spCounter->{updated}
. ", sp_created="
. $spCounter->{created}
. ", sp_removed="
. $spCounter->{removed}
. ", sp_rejected="
. $spCounter->{rejected}
. ", sp_ignored="
. $spCounter->{ignored} . "\n";
}
else {
print "[IDP]\tFound: "
. $idpCounter->{found}
. "\tUpdated: "
@ -539,6 +556,5 @@ if ( $opts{nagios} ) {
. $spCounter->{ignored} . "\n";
}
exit $exitCode;