diff --git a/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Api.pm b/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Api.pm index aed1d2c09..de58ec940 100644 --- a/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Api.pm +++ b/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Api.pm @@ -39,6 +39,9 @@ sub addRoutes { oidc => { rp => { ':confKey' => 'getOidcRpByConfKey' }, }, + saml => { + sp => { ':confKey' => 'getSamlSpByConfKey' }, + }, }, }, ['GET'] diff --git a/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Api/Providers.pm b/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Api/Providers.pm index ff48cbf0e..97476c267 100644 --- a/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Api/Providers.pm +++ b/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Api/Providers.pm @@ -22,7 +22,7 @@ sub getOidcRpByConfKey { # Check if confKey is defined if ( !defined $conf->{oidcRPMetaDataOptions}->{$confKey} ) { - return $self->sendError( $req, 'Service Provider not found', 404 ); + return $self->sendError( $req, "OIDC relying party '$confKey' not found", 404 ); } # Get Client ID @@ -50,4 +50,72 @@ sub getOidcRpByConfKey { ); } +sub getSamlSpByConfKey { + my ( $self, $req ) = @_; + + my $confKey = $req->params('confKey') + or return $self->sendError( $req, 'confKey is missing', 400 ); + + $self->logger->debug("[API] SAML SP $confKey configuration requested"); + + # Get latest configuration + my $conf = $self->_confAcc->getConf; + + # Check if confKey is defined + if ( !defined $conf->{samlSPMetaDataXML}->{$confKey} ) { + return $self->sendError( $req, "SAML service Provider '$confKey' not found", 404 ); + } + + # Get metadata + my $metadata = $conf->{samlSPMetaDataXML}->{$confKey} + ->{samlSPMetaDataXML}; + + # Get exported attributes + my %exportedAttributes; + foreach ( + keys %{ + $conf->{samlSPMetaDataExportedAttributes} + ->{$confKey} + } + ) + { + # Extract fields from exportedAttr value + my ( $mandatory, $name, $format, $friendly_name ) = + split( /;/, + $conf->{samlSPMetaDataExportedAttributes} + ->{$confKey}->{$_} ); + + $mandatory = !!$mandatory ? 'true' : 'false'; + + $exportedAttributes->{$_} = { + name => $name, + mandatory => $mandatory + }; + + if (defined $friendly_name && $friendly_name ne '') { + $exportedAttributes->{$_}->{friendlyName} = $friendly_name; + } + + if (defined $format && $format ne '') { + $exportedAttributes->{$_}->{format} = $format; + } + } + + # Dump object + use Data::Dumper; print STDERR Dumper($exportedAttributes); + + # Get options + my $options = $conf->{samlSPMetaDataOptions}->{$confKey}; + + return $self->sendJSONresponse( + $req, + { + confKey => $confKey, + metadata => $metadata, + exportedAttributes => $exportedAttributes, + options => $options + } + ); +} + 1;