Compact.pm 1.83 KB
Newer Older
Yadd's avatar
Yadd committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
package Lemonldap::NG::Common::Conf::Compact;

use strict;
use Mouse;
use Lemonldap::NG::Common::Conf::ReConstants;

our $VERSION = '2.0.0';

sub compactConf {
    my ( $self, $conf ) = @_;

    # Remove unused auth parameters
    my %keep;
    foreach my $type (qw(authentication userDB passwordDB)) {
        my $mod = $conf->{$type} || 'Null';
        $mod =~ s/OpenIDConnect/oidc/i;
        $mod = lc($mod);
        $keep{$mod} = 1;
    }
Yadd's avatar
Yadd committed
20
    if ( $keep{combination} ) {
Yadd's avatar
Yadd committed
21
        foreach my $md ( keys %{ $conf->{combModules} } ) {
Yadd's avatar
Yadd committed
22 23 24 25
            $_ = $conf->{combModules}->{$md}->{type};
            s/^(\w+).*$/lc($1)/e;
            s/OpenIDConnect/oidc/i;
            $keep{$_} = 1;
Yadd's avatar
Yadd committed
26 27 28 29 30 31 32 33 34 35 36 37
        }
    }
    if ( $keep{choice} ) {
        foreach my $key ( values %{ $conf->{authChoiceModules} } ) {
            my @tmp = split /[;|\|]/, $key;
            foreach (@tmp) {
                s/^(\w+).*$/lc($1)/e;
                s/OpenIDConnect/oidc/i;
                $keep{$_} = 1;
            }
        }
    }
Yadd's avatar
Yadd committed
38
    foreach my $key ( keys %$authParameters ) {
Yadd's avatar
Yadd committed
39 40 41 42 43 44 45 46 47
        my $mod = $key;
        $mod =~ s/Params$//;
        unless ( $keep{$mod} ) {
            delete $conf->{$_} foreach ( @{ $authParameters->{$key} } );
        }
    }

    # Disabled for now:

Yadd's avatar
Yadd committed
48 49 50 51 52 53
    # Remove unused issuerDB parameters
    foreach my $k ( keys %$issuerParameters ) {
        unless ( $conf->{ $k . "Activation" } ) {
            delete $conf->{$_} foreach ( @{ $issuerParameters->{$k} } );
        }
    }
Yadd's avatar
Yadd committed
54

Yadd's avatar
Yadd committed
55 56 57 58
    # Remove SAML service unless used
    unless ( $keep{saml} or $conf->{issuerDBSAMLActivation} ) {
        delete $conf->{$_} foreach (@$samlServiceParameters);
    }
Yadd's avatar
Yadd committed
59

Yadd's avatar
Yadd committed
60 61 62 63
    # Remove OpenID-Connect service unless used
    unless ( $keep{oidc} or $conf->{issuerDBOpenIDConnectActivation} ) {
        delete $conf->{$_} foreach (@$oidcServiceParameters);
    }
Yadd's avatar
Yadd committed
64 65 66 67
    return $conf;
}

1;