« blib/lib/Lemonldap/NG/Portal/Password/LDAP.pm
↑ Summary
blib/lib/Lemonldap/NG/Portal/2F/Register/TOTP.pm »
| 1 | package Lemonldap::NG::Portal::UserDB::LDAP; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use Mouse; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use utf8; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Lemonldap::NG::Portal::Main::Constants qw(PE_OK); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 1 | extends qw( | |||||||||||||||||||||||||||
| 9 | Lemonldap::NG::Portal::Main::UserDB | ||||||||||||||||||||||||||||
| 10 | Lemonldap::NG::Portal::Lib::LDAP | ||||||||||||||||||||||||||||
| 11 | ); | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 1 | our $VERSION = '2.23.0'; | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | has ldapGroupAttributeNameSearch => ( | ||||||||||||||||||||||||||||
| 16 | is => 'rw', | ||||||||||||||||||||||||||||
| 17 | lazy => 1, | ||||||||||||||||||||||||||||
| 18 | 0 | ▶ | builder => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 19 | 0 | my $attributes = []; | |||||||||||||||||||||||||||
| 20 | @$attributes = | ||||||||||||||||||||||||||||
| 21 | split( /\s+/, $_[0]->{conf}->{ldapGroupAttributeNameSearch} ) | ||||||||||||||||||||||||||||
| 22 | 0 | ▶ | if $_[0]->{conf}->{ldapGroupAttributeNameSearch}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 23 | push( @$attributes, $_[0]->{conf}->{ldapGroupAttributeNameGroup} ) | ||||||||||||||||||||||||||||
| 24 | if ( $_[0]->{conf}->{ldapGroupRecursive} | ||||||||||||||||||||||||||||
| 25 | 0 | ▶ | and $_[0]->{conf}->{ldapGroupAttributeNameGroup} ne "dn" ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$_[0]{"conf"}{"ldapGroupRecursive"} and $_[0]{"conf"}{"ldapGroupAttributeNameGroup"} ne "dn"
MC/DC0%0/2
$_[0]{"conf"}{"ldapGroupRecursive"} and $_[0]{"conf"}{"ldapGroupAttributeNameGroup"} ne "dn"
$_[0]{"conf"}{"ldapGroupRecursive"}
$_[0]{"conf"}{"ldapGroupAttributeNameGroup"} ne "dn"
Truth table0%0/3
A and B
A= $_[0]{"conf"}{"ldapGroupRecursive"}B= $_[0]{"conf"}{"ldapGroupAttributeNameGroup"} ne "dn"
| |||||||||||||||||||||||||||||
| 26 | 0 | return $attributes; | |||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | 1 | ); | |||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | # RUNNING METHODS | ||||||||||||||||||||||||||||
| 31 | # | ||||||||||||||||||||||||||||
| 32 | # getUser is provided by Portal::Lib::LDAP | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | # Load all parameters included in exportedVars parameter. | ||||||||||||||||||||||||||||
| 35 | # Multi-value parameters are loaded in a single string with | ||||||||||||||||||||||||||||
| 36 | # a separator (param multiValuesSeparator) | ||||||||||||||||||||||||||||
| 37 | # @return Lemonldap::NG::Portal constant | ||||||||||||||||||||||||||||
| 38 | 0 | ▶ | sub setSessionInfo { | ||||||||||||||||||||||||||
|
Subroutine
setSessionInfo: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 39 | 0 | my ( $self, $req ) = @_; | |||||||||||||||||||||||||||
| 40 | 0 | $req->{sessionInfo}->{_dn} = $req->data->{dn}; | |||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | my %vars = ( | ||||||||||||||||||||||||||||
| 43 | 0 | %{ $self->conf->{exportedVars} }, | |||||||||||||||||||||||||||
| 44 | 0 | %{ $self->conf->{ldapExportedVars} } | |||||||||||||||||||||||||||
| 45 | ); | ||||||||||||||||||||||||||||
| 46 | 0 | ▶ | while ( my ( $k, $v ) = each %vars ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 0 | my $value = $self->ldap->getLdapValue( $req->data->{ldapentry}, $v ); | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | # getLdapValue returns an empty string for missing attribute | ||||||||||||||||||||||||||||
| 51 | # but we really want to return undef so they don't get stored in session | ||||||||||||||||||||||||||||
| 52 | # This has to be a string comparison because "0" is a valid attribute | ||||||||||||||||||||||||||||
| 53 | # value. See #2403 | ||||||||||||||||||||||||||||
| 54 | 0 | ▶ | $value = undef if ( $value eq "" ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 0 | $req->sessionInfo->{$k} = $value; | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 0 | return PE_OK; | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | # Load all groups in $groups. | ||||||||||||||||||||||||||||
| 63 | # @return Lemonldap::NG::Portal constant | ||||||||||||||||||||||||||||
| 64 | 0 | ▶ | sub setGroups { | ||||||||||||||||||||||||||
|
Subroutine
setGroups: not called CC=10 SCAR=47.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 65 | 0 | my ( $self, $req ) = @_; | |||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | # Bail out if we are being called out of sequence | ||||||||||||||||||||||||||||
| 68 | 0 | ▶ | return PE_OK unless ( $req->data->{ldapentry} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 0 | ▶ | my $groups = $req->{sessionInfo}->{groups} || ''; | ||||||||||||||||||||||||||
|
Condition0%0/2
$req->{'sessionInfo'}{'groups'} || ''
MC/DC0%0/1
$req->{'sessionInfo'}{'groups'} || ''
$req->{'sessionInfo'}{'groups'}
Truth table0%0/2
A
A= $req->{'sessionInfo'}{'groups'}
| |||||||||||||||||||||||||||||
| 71 | 0 | ▶ | my $hGroups = $req->{sessionInfo}->{hGroups} || {}; | ||||||||||||||||||||||||||
|
Condition0%0/2
$req->{'sessionInfo'}{'hGroups'} || {}
MC/DC0%0/1
$req->{'sessionInfo'}{'hGroups'} || {}
$req->{'sessionInfo'}{'hGroups'}
Truth table0%0/2
A
A= $req->{'sessionInfo'}{'hGroups'}
| |||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 0 | ▶ | if ( $self->conf->{ldapGroupBase} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | # Get value for group search | ||||||||||||||||||||||||||||
| 76 | my $group_value = $self->ldap->getLdapValue( $req->data->{ldapentry}, | ||||||||||||||||||||||||||||
| 77 | 0 | $self->conf->{ldapGroupAttributeNameUser} ); | |||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 0 | ▶ | if ( $self->conf->{ldapGroupDecodeSearchedValue} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | 0 | utf8::decode($group_value); | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | $self->logger->debug( "Searching LDAP groups in " | ||||||||||||||||||||||||||||
| 84 | . $self->conf->{ldapGroupBase} | ||||||||||||||||||||||||||||
| 85 | 0 | . " for $group_value" ); | |||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | # Call searchGroups | ||||||||||||||||||||||||||||
| 88 | my $ldapGroups = $self->ldap->searchGroups( | ||||||||||||||||||||||||||||
| 89 | $self->conf->{ldapGroupBase}, | ||||||||||||||||||||||||||||
| 90 | $self->conf->{ldapGroupAttributeName}, | ||||||||||||||||||||||||||||
| 91 | $group_value, | ||||||||||||||||||||||||||||
| 92 | $self->ldapGroupAttributeNameSearch, | ||||||||||||||||||||||||||||
| 93 | $req->{ldapGroupDuplicateCheck} | ||||||||||||||||||||||||||||
| 94 | 0 | ); | |||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 0 | foreach ( keys %$ldapGroups ) { | |||||||||||||||||||||||||||
| 97 | 0 | my $groupName = $_; | |||||||||||||||||||||||||||
| 98 | 0 | $hGroups->{$groupName} = $ldapGroups->{$groupName}; | |||||||||||||||||||||||||||
| 99 | 0 | my $groupValues = []; | |||||||||||||||||||||||||||
| 100 | 0 | foreach ( @{ $self->ldapGroupAttributeNameSearch } ) { | |||||||||||||||||||||||||||
| 101 | 0 | ▶ | next if $_ =~ /^name$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | 0 | my $firstValue = $ldapGroups->{$groupName}->{$_}->[0]; | |||||||||||||||||||||||||||
| 103 | 0 | push @$groupValues, $firstValue; | |||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | 0 | ▶ | $groups .= $self->conf->{multiValuesSeparator} if $groups; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | 0 | $groups .= join( '|', @$groupValues ); | |||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 0 | $req->{sessionInfo}->{groups} = $groups; | |||||||||||||||||||||||||||
| 112 | 0 | $req->{sessionInfo}->{hGroups} = $hGroups; | |||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 0 | return PE_OK; | |||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 1 | 1; | |||||||||||||||||||||||||||