Add per-service macros to API (#2034)

Moo
Maxime Besson 5 years ago
parent 53a1e61394
commit 369c08337c
  1. 22
      lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Api/Providers/OidcRp.pm
  2. 22
      lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Api/Providers/SamlSp.pm
  3. 13
      lemonldap-ng-manager/t/04-providers-api.t

@ -222,6 +222,7 @@ sub deleteOidcRp {
delete $conf->{oidcRPMetaDataOptions}->{$confKey}; delete $conf->{oidcRPMetaDataOptions}->{$confKey};
delete $conf->{oidcRPMetaDataExportedVars}->{$confKey}; delete $conf->{oidcRPMetaDataExportedVars}->{$confKey};
delete $conf->{oidcRPMetaDataOptionsExtraClaims}->{$confKey}; delete $conf->{oidcRPMetaDataOptionsExtraClaims}->{$confKey};
delete $conf->{oidcRPMetaDataMacros}->{$confKey};
# Save configuration # Save configuration
$self->_confAcc->saveConf($conf); $self->_confAcc->saveConf($conf);
@ -246,6 +247,9 @@ sub _getOidcRpByConfKey {
# Get extra claim # Get extra claim
my $extraClaims = $conf->{oidcRPMetaDataOptionsExtraClaims}->{$confKey}; my $extraClaims = $conf->{oidcRPMetaDataOptionsExtraClaims}->{$confKey};
# Get macros
my $macros = $conf->{oidcRPMetaDataMacros}->{$confKey} || {};
# Get options # Get options
my $options = $conf->{oidcRPMetaDataOptions}->{$confKey}; my $options = $conf->{oidcRPMetaDataOptions}->{$confKey};
@ -254,6 +258,7 @@ sub _getOidcRpByConfKey {
clientId => $clientId, clientId => $clientId,
exportedVars => $exportedVars, exportedVars => $exportedVars,
extraClaims => $extraClaims, extraClaims => $extraClaims,
macros => $macros,
options => $options options => $options
}; };
} }
@ -296,6 +301,7 @@ sub _pushOidcRp {
$conf->{oidcRPMetaDataOptions}->{$confKey} = {}; $conf->{oidcRPMetaDataOptions}->{$confKey} = {};
$conf->{oidcRPMetaDataExportedVars}->{$confKey} = {}; $conf->{oidcRPMetaDataExportedVars}->{$confKey} = {};
$conf->{oidcRPMetaDataOptionsExtraClaims}->{$confKey} = {}; $conf->{oidcRPMetaDataOptionsExtraClaims}->{$confKey} = {};
$conf->{oidcRPMetaDataMacros}->{$confKey} = {};
$push->{options} = $push->{options} =
$self->_setDefaultValues( $push->{options}, 'oidcRPMetaDataNode' ); $self->_setDefaultValues( $push->{options}, 'oidcRPMetaDataNode' );
} }
@ -331,6 +337,22 @@ sub _pushOidcRp {
} }
} }
if ( defined $push->{macros} ) {
if ( $self->_isSimpleKeyValueHash( $push->{macros} ) ) {
foreach ( keys %{ $push->{macros} } ) {
$conf->{oidcRPMetaDataMacros}->{$confKey}->{$_} =
$push->{macros}->{$_};
}
}
else {
return {
res => 'ko',
msg =>
"Invalid input: macros is not a hash object with \"key\":\"value\" attributes"
};
}
}
if ( defined $push->{extraClaims} ) { if ( defined $push->{extraClaims} ) {
if ( $self->_isSimpleKeyValueHash( $push->{extraClaims} ) ) { if ( $self->_isSimpleKeyValueHash( $push->{extraClaims} ) ) {
foreach ( keys %{ $push->{extraClaims} } ) { foreach ( keys %{ $push->{extraClaims} } ) {

@ -225,6 +225,7 @@ sub deleteSamlSp {
delete $conf->{samlSPMetaDataXML}->{$confKey}; delete $conf->{samlSPMetaDataXML}->{$confKey};
delete $conf->{samlSPMetaDataOptions}->{$confKey}; delete $conf->{samlSPMetaDataOptions}->{$confKey};
delete $conf->{samlSPMetaDataExportedAttributes}->{$confKey}; delete $conf->{samlSPMetaDataExportedAttributes}->{$confKey};
delete $conf->{samlSPMetaDataMacros}->{$confKey};
# Save configuration # Save configuration
$self->_confAcc->saveConf($conf); $self->_confAcc->saveConf($conf);
@ -245,10 +246,14 @@ sub _getSamlSpByConfKey {
# Get options # Get options
my $options = $conf->{samlSPMetaDataOptions}->{$confKey}; my $options = $conf->{samlSPMetaDataOptions}->{$confKey};
# Get macros
my $macros = $conf->{samlSPMetaDataMacros}->{$confKey} || {};
my $samlSp = { my $samlSp = {
confKey => $confKey, confKey => $confKey,
metadata => $metadata, metadata => $metadata,
exportedAttributes => {}, exportedAttributes => {},
macros => $macros,
options => $options options => $options
}; };
@ -347,6 +352,7 @@ sub _pushSamlSp {
if ($replace) { if ($replace) {
$conf->{samlSPMetaDataXML}->{$confKey} = {}; $conf->{samlSPMetaDataXML}->{$confKey} = {};
$conf->{samlSPMetaDataOptions}->{$confKey} = {}; $conf->{samlSPMetaDataOptions}->{$confKey} = {};
$conf->{samlSPMetaDataMacros}->{$confKey} = {};
$conf->{samlSPMetaDataExportedAttributes}->{$confKey} = {}; $conf->{samlSPMetaDataExportedAttributes}->{$confKey} = {};
$push->{options} = $push->{options} =
$self->_setDefaultValues( $push->{options}, 'samlSPMetaDataNode' ); $self->_setDefaultValues( $push->{options}, 'samlSPMetaDataNode' );
@ -366,6 +372,22 @@ sub _pushSamlSp {
} }
} }
if ( defined $push->{macros} ) {
if ( $self->_isSimpleKeyValueHash( $push->{macros} ) ) {
foreach ( keys %{ $push->{macros} } ) {
$conf->{samlSPMetaDataMacros}->{$confKey}->{$_} =
$push->{macros}->{$_};
}
}
else {
return {
res => 'ko',
msg =>
"Invalid input: macros is not a hash object with \"key\":\"value\" attributes"
};
}
}
if ( defined $push->{exportedAttributes} ) { if ( defined $push->{exportedAttributes} ) {
my $res = my $res =
$self->_readSamlSpExportedAttributes( $push->{exportedAttributes}, $self->_readSamlSpExportedAttributes( $push->{exportedAttributes},

@ -289,9 +289,12 @@ my $oidcRp = {
family_name => "sn", family_name => "sn",
given_name => "givenName" given_name => "givenName"
}, },
macros => {
given_name => '$cn',
},
extraClaims => { extraClaims => {
phone => 'telephoneNumber', phone => 'telephoneNumber',
email => 'mail' email => 'mail',
}, },
options => { options => {
oidcRPMetaDataOptionsClientSecret => 'secret', oidcRPMetaDataOptionsClientSecret => 'secret',
@ -319,6 +322,7 @@ $oidcRp->{options}->{oidcRPMetaDataOptionsIDTokenSignAlg} = 'RS512';
delete $oidcRp->{options}->{oidcRPMetaDataOptionsIcon}; delete $oidcRp->{options}->{oidcRPMetaDataOptionsIcon};
delete $oidcRp->{extraClaims}; delete $oidcRp->{extraClaims};
delete $oidcRp->{exportedVars}; delete $oidcRp->{exportedVars};
$oidcRp->{macros}->{given_name} = '$givenName';
$oidcRp->{exportedVars}->{cn} = 'cn'; $oidcRp->{exportedVars}->{cn} = 'cn';
checkUpdate( $test, 'oidc/rp', 'myOidcRp1', $oidcRp ); checkUpdate( $test, 'oidc/rp', 'myOidcRp1', $oidcRp );
checkGet( $test, 'oidc/rp', 'myOidcRp1', checkGet( $test, 'oidc/rp', 'myOidcRp1',
@ -329,6 +333,7 @@ checkGet( $test, 'oidc/rp', 'myOidcRp1', 'options/oidcRPMetaDataOptionsIcon',
'web.png' ); 'web.png' );
checkGet( $test, 'oidc/rp', 'myOidcRp1', 'exportedVars/cn', 'cn' ); checkGet( $test, 'oidc/rp', 'myOidcRp1', 'exportedVars/cn', 'cn' );
checkGet( $test, 'oidc/rp', 'myOidcRp1', 'exportedVars/family_name', 'sn' ); checkGet( $test, 'oidc/rp', 'myOidcRp1', 'exportedVars/family_name', 'sn' );
checkGet( $test, 'oidc/rp', 'myOidcRp1', 'macros/given_name', '$givenName' );
checkGet( $test, 'oidc/rp', 'myOidcRp1', 'extraClaims/phone', checkGet( $test, 'oidc/rp', 'myOidcRp1', 'extraClaims/phone',
'telephoneNumber' ); 'telephoneNumber' );
@ -440,6 +445,9 @@ my $samlSp = {
name => "givenName" name => "givenName"
} }
}, },
macros => {
given_name => '$givenName',
},
options => { options => {
samlSPMetaDataOptionsCheckSLOMessageSignature => 0, samlSPMetaDataOptionsCheckSLOMessageSignature => 0,
samlSPMetaDataOptionsEncryptionMode => "assertion", samlSPMetaDataOptionsEncryptionMode => "assertion",
@ -466,6 +474,7 @@ $samlSp->{options}->{samlSPMetaDataOptionsCheckSLOMessageSignature} = 1;
$samlSp->{options}->{samlSPMetaDataOptionsEncryptionMode} = 'nameid'; $samlSp->{options}->{samlSPMetaDataOptionsEncryptionMode} = 'nameid';
delete $samlSp->{options}->{samlSPMetaDataOptionsSessionNotOnOrAfterTimeout}; delete $samlSp->{options}->{samlSPMetaDataOptionsSessionNotOnOrAfterTimeout};
delete $samlSp->{exportedAttributes}; delete $samlSp->{exportedAttributes};
$samlSp->{macros}->{family_name} = '$sn',
$samlSp->{exportedAttributes}->{cn}->{name} = "cn", $samlSp->{exportedAttributes}->{cn}->{name} = "cn",
$samlSp->{exportedAttributes}->{cn}->{friendlyName} = "common_name", $samlSp->{exportedAttributes}->{cn}->{friendlyName} = "common_name",
$samlSp->{exportedAttributes}->{cn}->{mandatory} = "false", $samlSp->{exportedAttributes}->{cn}->{mandatory} = "false",
@ -483,6 +492,8 @@ checkGet( $test, 'saml/sp', 'mySamlSp1', 'exportedAttributes/cn/mandatory',
checkGet( $test, 'saml/sp', 'mySamlSp1', 'exportedAttributes/cn/name', 'uid' ); checkGet( $test, 'saml/sp', 'mySamlSp1', 'exportedAttributes/cn/name', 'uid' );
checkGet( $test, 'saml/sp', 'mySamlSp1', 'exportedAttributes/given_name/name', checkGet( $test, 'saml/sp', 'mySamlSp1', 'exportedAttributes/given_name/name',
'givenName' ); 'givenName' );
checkGet( $test, 'saml/sp', 'mySamlSp1', 'macros/family_name', '$sn' );
checkGet( $test, 'saml/sp', 'mySamlSp1', 'macros/given_name', '$givenName' );
$test = "SamlSp - Update should fail on non existing options"; $test = "SamlSp - Update should fail on non existing options";
$samlSp->{options}->{playingPossum} = 'elephant'; $samlSp->{options}->{playingPossum} = 'elephant';

Loading…
Cancel
Save