diff --git a/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Attributes.pm b/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Attributes.pm index eb2686bf9..4f7ae29f7 100644 --- a/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Attributes.pm +++ b/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Attributes.pm @@ -437,7 +437,7 @@ qr/^(?:(?:(?:(?:[a-zA-Z0-9][-a-zA-Z0-9]*)?[a-zA-Z0-9])[.])*(?:[a-zA-Z][-a-zA-Z0- }, 'grantSessionRules' => { 'keyTest' => sub { "DUMMY" }, - 'type' => 'keyTextContainer' + 'type' => 'grantContainer' }, 'groups' => { 'default' => {}, diff --git a/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Build/Attributes.pm b/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Build/Attributes.pm index 207a73e1d..fa06b9011 100644 --- a/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Build/Attributes.pm +++ b/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Build/Attributes.pm @@ -355,7 +355,7 @@ sub attributes { documentation => 'Check XSS', }, grantSessionRules => { - type => 'keyTextContainer', + type => 'grantContainer', keyTest => $perlExpr, }, hiddenAttributes => { diff --git a/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Conf.pm b/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Conf.pm index 8df3a3d1e..cee9deb65 100644 --- a/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Conf.pm +++ b/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Conf.pm @@ -35,7 +35,7 @@ sub addRoutes { ->addRoute( confs => { ':cfgNum' => [ - qw(virtualHosts samlIDPMetaDataNodes samlSPMetaDataNodes applicationList oidcOPMetaDataNodes oidcRPMetaDataNodes authChoiceModules) + qw(virtualHosts samlIDPMetaDataNodes samlSPMetaDataNodes applicationList oidcOPMetaDataNodes oidcRPMetaDataNodes authChoiceModules grantSessionRules) ] }, ['GET'] @@ -441,9 +441,10 @@ sub oidcRPMetaDataNodes { return $self->_oidcMetaDataNodes( 'RP', $req, @path ); } -## @method PSGI-JSON-response authChoiceModules(key) +## @method PSGI-JSON-response authChoiceModules($req,$key) # Returns authChoiceModules keys splitted in arrays # +#@param $req Lemonldap::NG::PSGI::Request #@param key optional subkey #@return PSGI JSON response sub authChoiceModules { @@ -468,6 +469,41 @@ sub authChoiceModules { } } +## @method PSGI-JSON-response $grantSessionRules($req) +#Respond to `/conf/:cfgNum` requests by sending configuration metadatas +# +#@param $req Lemonldap::NG::PSGI::Request +#@return PSGI JSON response +sub grantSessionRules { + my ( $self, $req, $key ) = splice @_; + return $self->sendError( 'Subkeys forbidden for grantSessionRules', 400 ) + if ($key); + my $value = $self->getConfKey( $req, 'grantSessionRules' ); + my @res; + + sub _sort { + my $A = ( $a =~ /^.*?##(.*)$/ )[0]; + my $B = ( $b =~ /^.*?##(.*)$/ )[0]; + return !$A ? 1 : !$B ? -1 : $A cmp $B; + } + my $id = 0; + foreach my $k ( sort _sort keys %$value ) { + my $r = $k; + my $c = ( $r =~ s/^(.*)?##(.*)$/$1/ ? $2 : '' ); + $id++; + push @res, + { + id => "grantSessionRules/$id", + title => $c || $r, + re => $r, + comment => $c, + data => $value->{$k}, + type => 'grant' + }; + } + return $self->sendJSONresponse( $req, \@res ); +} + ## @method PSGI-JSON-response metadatas($req) #Respond to `/conf/:cfgNum` requests by sending configuration metadatas # @@ -659,7 +695,8 @@ sub newConf { # "message" fields: note that words enclosed by "__" (__word__) will be translated $res->{message} = $parser->{message}; foreach my $t (qw(errors warnings changes)) { - $res->{details}->{'__'.$t.'__'} = $parser->$t if ( @{ $parser->$t } ); + $res->{details}->{ '__' . $t . '__' } = $parser->$t + if ( @{ $parser->$t } ); } if ( $res->{result} ) { if ( $self->{demoMode} ) { diff --git a/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/ConfParser.pm b/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/ConfParser.pm index 0c364b411..ebccaee41 100644 --- a/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/ConfParser.pm +++ b/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/ConfParser.pm @@ -432,6 +432,51 @@ sub _scanNodes { } next; } + elsif ( $leaf->{id} eq 'grantSessionRules' ) { + hdebug('grantSessionRules'); + if ( $leaf->{cnodes} ) { + hdebug(' unopened'); + $self->newConf->{$name} = $self->refConf->{$name} // {}; + } + else { + hdebug(' opened'); + $subNodes //= []; + my $count = 0; + my $ref = $self->refConf->{grantSessionRules}; + my $new = $self->newConf->{grantSessionRules}; + my @old = ref $ref ? keys %$ref : (); + $self->newConf->{grantSessionRules} = {}; + foreach my $n (@$subNodes) { + hdebug(" looking at $n subnode"); + my $k = + $n->{re} . ( $n->{comment} ? "##$n->{comment}" : '' ); + $self->newConf->{grantSessionRules}->{$k} = $n->{data}; + $count++; + unless ( defined $ref->{$k} ) { + $self->confChanged(1); + push @{ $self->changes }, + { keys => 'grantSessionRules', new => $k }; + } + elsif ( $ref->{$k} ne $n->{data} ) { + $self->confChanged(1); + push @{ $self->changes }, + { + key => "grantSessionRules, $k", + old => $self->refConf->{grantSessionRules}->{$k}, + new => $n->{data} + }; + } + @old = grep { $_ ne $k } @old; + } + if (@old) { + $self->confChanged(1); + push @{ $self->changes }, + { key => 'grantSessionRules', old => $_, } + foreach (@old); + } + } + next; + } #################### # Other hash nodes # diff --git a/lemonldap-ng-manager/site/static/forms/grant.html b/lemonldap-ng-manager/site/static/forms/grant.html new file mode 100644 index 000000000..5304d6327 --- /dev/null +++ b/lemonldap-ng-manager/site/static/forms/grant.html @@ -0,0 +1,29 @@ +
+
+

+

+ + + + + + + + + + + + +