| 1 |
package Lemonldap::NG::Common::Conf::Compact; |
| 2 |
|
| 3 |
use strict; |
| 4 |
use Mouse; |
| 5 |
use Lemonldap::NG::Common::Conf::ReConstants; |
| 6 |
|
| 7 |
our $VERSION = '2.0.15'; |
| 8 |
|
| 9 |
sub compactConf { |
| 10 |
my ( $self, $conf ) = @_; |
| 11 |
|
| 12 |
return $conf unless $conf->{compactConf}; |
| 13 |
|
| 14 |
# Remove unused auth parameters |
| 15 |
my %keep; |
| 16 |
foreach my $type (qw(authentication userDB passwordDB registerDB)) { |
| 17 |
my $mod = $conf->{$type} || 'Null'; |
| 18 |
$mod =~ s/OpenIDConnect/oidc/i; |
| 19 |
$mod = lc($mod); |
| 20 |
$keep{$mod} = 1; |
| 21 |
if ( $mod eq "ad" ) { $keep{'ldap'} = 1; } |
| 22 |
} |
| 23 |
if ( $keep{combination} ) { |
| 24 |
foreach my $md ( keys %{ $conf->{combModules} } ) { |
| 25 |
$_ = $conf->{combModules}->{$md}->{type}; |
| 26 |
s/^(\w+).*$/lc($1)/e; |
| 27 |
s/OpenIDConnect/oidc/i; |
| 28 |
$keep{$_} = 1; |
| 29 |
if ( $_ eq "ad" ) { $keep{'ldap'} = 1; } |
| 30 |
} |
| 31 |
} |
| 32 |
if ( $keep{choice} ) { |
| 33 |
foreach my $key ( values %{ $conf->{authChoiceModules} } ) { |
| 34 |
my @tmp = split /[;|\|]/, $key; |
| 35 |
foreach (@tmp) { |
| 36 |
s/^(\w+).*$/lc($1)/e; |
| 37 |
s/OpenIDConnect/oidc/i; |
| 38 |
$keep{$_} = 1; |
| 39 |
if ( $_ eq "ad" ) { $keep{'ldap'} = 1; } |
| 40 |
} |
| 41 |
} |
| 42 |
} |
| 43 |
foreach my $key ( keys %$authParameters ) { |
| 44 |
my $mod = $key; |
| 45 |
$mod =~ s/Params$//; |
| 46 |
unless ( $keep{$mod} ) { |
| 47 |
delete $conf->{$_} foreach ( @{ $authParameters->{$key} } ); |
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
# Disabled for now: |
| 52 |
|
| 53 |
# Remove unused issuerDB parameters except options |
| 54 |
foreach my $k ( keys %$issuerParameters ) { |
| 55 |
unless ( $conf->{ $k . "Activation" } ) { |
| 56 |
foreach ( @{ $issuerParameters->{$k} } ) { |
| 57 |
delete $conf->{$_} unless ( $_ =~ /^issuers/ ); |
| 58 |
} |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
# Remove SAML service unless used |
| 63 |
unless ( $keep{saml} or $conf->{issuerDBSAMLActivation} ) { |
| 64 |
delete $conf->{$_} foreach (@$samlServiceParameters); |
| 65 |
} |
| 66 |
|
| 67 |
# Remove OpenID-Connect service unless used |
| 68 |
unless ( $keep{oidc} or $conf->{issuerDBOpenIDConnectActivation} ) { |
| 69 |
delete $conf->{$_} foreach (@$oidcServiceParameters); |
| 70 |
} |
| 71 |
return $conf; |
| 72 |
} |
| 73 |
|
| 74 |
1; |