2016-04-20 07:09:23 +02:00
|
|
|
package Lemonldap::NG::Portal::UserDB::LDAP;
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use Mouse;
|
2018-12-20 17:56:10 +01:00
|
|
|
use utf8;
|
2019-06-17 21:14:37 +02:00
|
|
|
use Lemonldap::NG::Portal::Main::Constants qw(PE_OK);
|
2016-04-20 07:09:23 +02:00
|
|
|
|
2017-01-15 14:18:01 +01:00
|
|
|
extends 'Lemonldap::NG::Portal::Lib::LDAP';
|
2016-04-20 07:09:23 +02:00
|
|
|
|
2019-09-12 21:56:49 +02:00
|
|
|
our $VERSION = '2.0.6';
|
2016-04-28 22:07:35 +02:00
|
|
|
|
|
|
|
has ldapGroupAttributeNameSearch => (
|
|
|
|
is => 'rw',
|
2017-03-27 18:51:18 +02:00
|
|
|
lazy => 1,
|
2016-04-28 22:07:35 +02:00
|
|
|
builder => sub {
|
2017-12-04 14:21:17 +01:00
|
|
|
my $attributes = [];
|
|
|
|
@$attributes =
|
|
|
|
split( /\s+/, $_[0]->{conf}->{ldapGroupAttributeNameSearch} )
|
|
|
|
if $_[0]->{conf}->{ldapGroupAttributeNameSearch};
|
|
|
|
push( @$attributes, $_[0]->{conf}->{ldapGroupAttributeNameGroup} )
|
|
|
|
if ( $_[0]->{conf}->{ldapGroupRecursive}
|
|
|
|
and $_[0]->{conf}->{ldapGroupAttributeNameGroup} ne "dn" );
|
|
|
|
return $attributes;
|
2016-04-28 22:07:35 +02:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2016-06-09 20:40:20 +02:00
|
|
|
# RUNNING METHODS
|
2019-06-17 21:14:37 +02:00
|
|
|
#
|
|
|
|
# getUser is provided by Portal::Lib::LDAP
|
2016-04-28 22:07:35 +02:00
|
|
|
|
|
|
|
# Load all parameters included in exportedVars parameter.
|
|
|
|
# Multi-value parameters are loaded in a single string with
|
|
|
|
# a separator (param multiValuesSeparator)
|
|
|
|
# @return Lemonldap::NG::Portal constant
|
|
|
|
sub setSessionInfo {
|
|
|
|
my ( $self, $req ) = @_;
|
2018-07-05 22:56:16 +02:00
|
|
|
$req->{sessionInfo}->{_dn} = $req->data->{dn};
|
2016-04-28 22:07:35 +02:00
|
|
|
|
|
|
|
my %vars = ( %{ $self->conf->{exportedVars} },
|
|
|
|
%{ $self->conf->{ldapExportedVars} } );
|
|
|
|
while ( my ( $k, $v ) = each %vars ) {
|
2019-11-08 11:25:27 +01:00
|
|
|
|
2020-12-07 17:48:15 +01:00
|
|
|
my $value = $self->ldap->getLdapValue( $req->data->{ldapentry}, $v );
|
|
|
|
|
2019-11-08 11:25:27 +01:00
|
|
|
# getLdapValue returns an empty string for missing attribute
|
|
|
|
# but we really want to return undef so they don't get stored in session
|
2020-12-07 17:48:15 +01:00
|
|
|
# This has to be a string comparison because "0" is a valid attribute
|
|
|
|
# value. See #2403
|
|
|
|
$value = undef if ( $value eq "" );
|
2016-04-28 22:07:35 +02:00
|
|
|
|
2020-12-07 17:48:15 +01:00
|
|
|
$req->sessionInfo->{$k} = $value;
|
|
|
|
}
|
2016-04-28 22:07:35 +02:00
|
|
|
PE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Load all groups in $groups.
|
|
|
|
# @return Lemonldap::NG::Portal constant
|
|
|
|
sub setGroups {
|
|
|
|
my ( $self, $req ) = @_;
|
|
|
|
my $groups = $req->{sessionInfo}->{groups};
|
|
|
|
my $hGroups = $req->{sessionInfo}->{hGroups};
|
|
|
|
|
|
|
|
if ( $self->conf->{ldapGroupBase} ) {
|
|
|
|
|
|
|
|
# Get value for group search
|
2019-08-06 21:54:41 +02:00
|
|
|
my $group_value = $self->ldap->getLdapValue( $req->data->{ldapentry},
|
2016-04-28 22:07:35 +02:00
|
|
|
$self->conf->{ldapGroupAttributeNameUser} );
|
|
|
|
|
2019-02-02 10:48:55 +01:00
|
|
|
if ( $self->conf->{ldapGroupDecodeSearchedValue} ) {
|
|
|
|
utf8::decode($group_value);
|
|
|
|
}
|
|
|
|
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->logger->debug( "Searching LDAP groups in "
|
2017-10-18 17:37:59 +02:00
|
|
|
. $self->conf->{ldapGroupBase}
|
2017-02-15 07:41:50 +01:00
|
|
|
. " for $group_value" );
|
2016-04-28 22:07:35 +02:00
|
|
|
|
|
|
|
# Call searchGroups
|
|
|
|
my $ldapGroups = $self->ldap->searchGroups(
|
|
|
|
$self->conf->{ldapGroupBase},
|
|
|
|
$self->conf->{ldapGroupAttributeName},
|
2018-01-15 12:27:10 +01:00
|
|
|
$group_value,
|
|
|
|
$self->ldapGroupAttributeNameSearch,
|
|
|
|
$req->{ldapGroupDuplicateCheck}
|
2016-04-28 22:07:35 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
foreach ( keys %$ldapGroups ) {
|
|
|
|
my $groupName = $_;
|
|
|
|
$hGroups->{$groupName} = $ldapGroups->{$groupName};
|
|
|
|
my $groupValues = [];
|
|
|
|
foreach ( @{ $self->ldapGroupAttributeNameSearch } ) {
|
|
|
|
next if $_ =~ /^name$/;
|
|
|
|
my $firstValue = $ldapGroups->{$groupName}->{$_}->[0];
|
|
|
|
push @$groupValues, $firstValue;
|
|
|
|
}
|
2017-12-04 14:21:17 +01:00
|
|
|
$groups .= $self->conf->{multiValuesSeparator} if $groups;
|
|
|
|
$groups .= join( '|', @$groupValues );
|
2016-04-28 22:07:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-12-04 14:21:17 +01:00
|
|
|
$req->{sessionInfo}->{groups} = $groups;
|
2017-11-30 22:25:00 +01:00
|
|
|
$req->{sessionInfo}->{hGroups} = $hGroups;
|
2016-04-28 22:07:35 +02:00
|
|
|
PE_OK;
|
|
|
|
}
|
|
|
|
|
2016-04-20 07:09:23 +02:00
|
|
|
1;
|