Commit 8f423fd2 authored by Clément OUDOT's avatar Clément OUDOT

Move setGroups in UserDB

parent 84c02a1c
......@@ -527,9 +527,9 @@ sub _deleteSession {
##@method boolean process()
# Main method.
# process() call functions issued from :
# - itself : controlUrlOrigin, controlExistingSession, setMacros, setGroups, store, buildCookie, log, autoredirect
# - itself : controlUrlOrigin, controlExistingSession, setMacros, setLocalGroups, store, buildCookie, log, autoredirect
# - authentication module : extractFormInfo, setAuthSessionInfo, authenticate
# - user database module : getUser, setSessionInfo
# - user database module : getUser, setSessionInfo, setGroups
# - password database module : modifyPassword, resetPasswordByMail
#@return 1 if user is all is OK, 0 if session isn't created or a notification has to be done
sub process {
......@@ -539,8 +539,8 @@ sub process {
qw(controlUrlOrigin checkNotifBack controlExistingSession
SAMLForUnAuthUser authInit extractFormInfo userDBInit getUser
setAuthSessionInfo passwordDBInit modifyPassword setSessionInfo
resetPasswordByMail setMacros setGroups authenticate store buildCookie
checkNotification SAMLForAuthUser autoRedirect)
resetPasswordByMail setMacros setLocalGroups setGroups authenticate
store buildCookie checkNotification SAMLForAuthUser autoRedirect)
);
$self->updateStatus;
return ( ( $self->{error} > 0 ) ? 0 : 1 );
......@@ -731,39 +731,25 @@ sub setMacros {
PE_OK;
}
##@apmethod int setGroups()
##@apmethod int setLocalGroups()
# 11) groups mechanism.
# * store all groups name that the user match in
# $self->{sessionInfo}->{groups}
#@return Lemonldap::NG::Portal constant
sub setGroups {
sub setLocalGroups {
local $self = shift;
my $groups;
$self->safe->share('$self');
while ( my ( $group, $expr ) = each %{ $self->{groups} } ) {
$expr =~ s/\$(\w+)/\$self->{sessionInfo}->{$1}/g;
$groups .= "$group " if ( $self->safe->reval($expr) );
}
if ( $self->{ldapGroupBase} ) {
my $mesg = $self->{ldap}->search(
base => $self->{ldapGroupBase},
filter => "(|(member="
. $self->{dn}
. ")(uniqueMember="
. $self->{dn} . "))",
attrs => ["cn"],
);
if ( $mesg->code() == 0 ) {
foreach my $entry ( $mesg->all_entries ) {
my @values = $entry->get_value("cn");
$groups .= $values[0] . " ";
}
}
$groups .= "$group; " if ( $self->safe->reval($expr) );
}
$self->{sessionInfo}->{groups} = $groups;
PE_OK;
}
# . setGroups() : must be implemented in UserDB* module
##@apmethod int authenticate()
# 12. Call authenticate() in Auth* module and call userNotice().
#@return Lemonldap::NG::Portal constant
......
......@@ -103,5 +103,32 @@ sub setSessionInfo {
PE_OK;
}
## @apmethod int setGroups()
# Load all groups in $groups.
# @return Lemonldap::NG::Portal constant
sub setGroups {
my ($self) = @_;
my $groups = $self->{sessionInfo}->{groups};
if ( $self->{ldapGroupBase} ) {
my $mesg = $self->ldap->search(
base => $self->{ldapGroupBase},
filter => "(|(member="
. $self->{dn}
. ")(uniqueMember="
. $self->{dn} . "))",
attrs => ["cn"],
);
if ( $mesg->code() == 0 ) {
foreach my $entry ( $mesg->all_entries ) {
my @values = $entry->get_value("cn");
$groups .= $values[0] . "; ";
}
}
}
$self->{sessionInfo}->{groups} = $groups;
PE_OK;
}
1;
......@@ -17,6 +17,10 @@ sub setSessionInfo {
return $self->_multi->try('setSessionInfo',1);
}
sub setGroups {
my $self = shift;
return $self->_multi->try('setGroups',1);
}
1;
......@@ -29,5 +29,11 @@ sub setSessionInfo {
PE_OK;
}
## @apmethod int setGroups()
# Do nothing
# @return Lemonldap::NG::Portal constant
sub setGroups {
PE_OK;
}
1;
......@@ -20,7 +20,7 @@ use base qw(Lemonldap::NG::Portal::_Remote);
# @return Lemonldap::NG::Portal constant
*getUser = *Lemonldap::NG::Portal::_Remote::checkRemoteId;
## @apmethod int
## @apmethod int setSessionInfos
# @return Lemonldap::NG::Portal constant
sub setSessionInfo {
my $self = shift;
......@@ -29,5 +29,12 @@ sub setSessionInfo {
PE_OK;
}
## @apmethod int setGroups
# @return Lemonldap::NG::Portal constant
sub setGroups {
my $self = shift;
PE_OK;
}
1;
......@@ -39,6 +39,12 @@ sub setSessionInfo {
PE_OK;
}
## @apmethod int setGroups()
# Does nothing
# @return Lemonldap::NG::Portal error code
sub setGroups {
PE_OK;
}
1;
__END__
......
......@@ -102,7 +102,7 @@ sub replay {
my @subs = ();
foreach (
qw(authInit extractFormInfo setAuthSessionInfo userDBInit getUser
setSessionInfo)
setSessionInfo setGroups)
)
{
push @subs, $_;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment