FindUser with combination (#1976)

v2.11
Christophe Maudoux 4 years ago
parent 50a35e7588
commit fc6ea96954
  1. 2
      lemonldap-ng-common/lib/Lemonldap/NG/Common/Conf/ReConstants.pm
  2. 2
      lemonldap-ng-manager/MANIFEST
  3. 3
      lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Attributes.pm
  4. 2
      lemonldap-ng-manager/site/htdocs/static/reverseTree.json
  5. 2
      lemonldap-ng-manager/site/htdocs/static/struct.json
  6. 0
      lemonldap-ng-manager/t/71-viewer-without-diff.t
  7. 10
      lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Lib/LDAP.pm
  8. 19
      lemonldap-ng-portal/lib/Lemonldap/NG/Portal/UserDB/DBI.pm
  9. 15
      lemonldap-ng-portal/lib/Lemonldap/NG/Portal/UserDB/Demo.pm
  10. 14
      lemonldap-ng-portal/lib/Lemonldap/NG/Portal/UserDB/REST.pm
  11. 63
      lemonldap-ng-portal/t/68-FindUser-with-DBI.t
  12. 33
      lemonldap-ng-portal/t/68-FindUser-with-Demo.t
  13. 52
      lemonldap-ng-portal/t/68-FindUser-with-LDAP.t
  14. 23
      lemonldap-ng-portal/t/68-FindUser-with-REST.t

@ -54,7 +54,7 @@ our $authParameters = {
proxyParams => [qw(proxyAuthnLevel proxyAuthService proxySessionService remoteCookieName proxyUseSoap)],
radiusParams => [qw(radiusAuthnLevel radiusSecret radiusServer)],
remoteParams => [qw(remotePortal remoteCookieName remoteGlobalStorage remoteGlobalStorageOptions)],
restParams => [qw(restAuthnLevel restAuthUrl restUserDBUrl restPwdConfirmUrl restPwdModifyUrl)],
restParams => [qw(restAuthnLevel restAuthUrl restUserDBUrl restPwdConfirmUrl restPwdModifyUrl restFindUserDBUrl)],
slaveParams => [qw(slaveAuthnLevel slaveUserHeader slaveMasterIP slaveHeaderName slaveHeaderContent slaveDisplayLogo slaveExportedVars)],
sslParams => [qw(SSLAuthnLevel SSLVar SSLVarIf sslByAjax sslHost)],
twitterParams => [qw(twitterAuthnLevel twitterKey twitterSecret twitterAppName twitterUserField)],

@ -258,7 +258,7 @@ t/50-notifications-DBI.t
t/50-notifications.t
t/60-2ndfa.t
t/70-viewer.t
t/71-viewer-with-no-diff.t
t/71-viewer-without-diff.t
t/80-attributes.t
t/90-translations.t
t/99-pod.t

@ -3005,6 +3005,9 @@ qr/(?:(?:https?):\/\/(?:(?:(?:(?:(?:(?:[a-zA-Z0-9][-a-zA-Z0-9]*)?[a-zA-Z0-9])[.]
'default' => 0,
'type' => 'bool'
},
'restFindUserDBUrl' => {
'type' => 'url'
},
'restPasswordServer' => {
'default' => 0,
'type' => 'bool'

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -4,8 +4,11 @@ use strict;
use Mouse;
use Lemonldap::NG::Portal::Lib::Net::LDAP;
use Lemonldap::NG::Portal::Main::Constants qw(
PE_OK PE_LDAPCONNECTFAILED
PE_LDAPERROR PE_BADCREDENTIALS
PE_OK
PE_LDAPERROR
PE_USERNOTFOUND
PE_BADCREDENTIALS
PE_LDAPCONNECTFAILED
);
extends 'Lemonldap::NG::Common::Module';
@ -208,9 +211,10 @@ sub findUser {
[0];
$self->userLogger->info("FindUser: LDAP UserDB returns $entry");
$req->data->{findUser} = $entry;
return PE_OK;
}
return PE_OK;
return PE_USERNOTFOUND;
}
# Validate LDAP connection before use

@ -2,7 +2,12 @@ package Lemonldap::NG::Portal::UserDB::DBI;
use strict;
use Mouse;
use Lemonldap::NG::Portal::Main::Constants qw(PE_OK PE_ERROR PE_BADCREDENTIALS);
use Lemonldap::NG::Portal::Main::Constants qw(
PE_OK
PE_ERROR
PE_USERNOTFOUND
PE_BADCREDENTIALS
);
extends 'Lemonldap::NG::Portal::Lib::DBI';
@ -43,7 +48,8 @@ sub getUser {
eval { $self->p->_authentication->setSecurity($req) };
return PE_BADCREDENTIALS;
}
PE_OK;
return PE_OK;
}
sub findUser {
@ -91,9 +97,10 @@ sub findUser {
$self->userLogger->info(
"FindUser: DBI UserDB returns $results->[$rank]->[0]");
$req->data->{findUser} = $results->[$rank]->[0];
return PE_OK;
}
PE_OK;
return PE_USERNOTFOUND;
}
sub setSessionInfo {
@ -107,11 +114,13 @@ sub setSessionInfo {
$req->{sessionInfo}->{$var} = $req->data->{dbientry}->{$attr}
if ( defined $req->data->{dbientry}->{$attr} );
}
PE_OK;
return PE_OK;
}
sub setGroups {
PE_OK;
return PE_OK;
}
1;

@ -7,7 +7,11 @@ package Lemonldap::NG::Portal::UserDB::Demo;
use strict;
use Mouse;
use Lemonldap::NG::Portal::Main::Constants qw(PE_OK PE_BADCREDENTIALS);
use Lemonldap::NG::Portal::Main::Constants qw(
PE_OK
PE_USERNOTFOUND
PE_BADCREDENTIALS
);
extends 'Lemonldap::NG::Common::Module';
@ -67,7 +71,7 @@ sub getUser {
eval { $self->p->_authentication->setSecurity($req) };
PE_BADCREDENTIALS;
return PE_BADCREDENTIALS;
}
## @apmethod int findUser()
@ -106,9 +110,10 @@ sub findUser {
$self->userLogger->info(
"FindUser: Demo UserDB returns $results[$rank]");
$req->data->{findUser} = $results[$rank];
return PE_OK;
}
PE_OK;
return PE_USERNOTFOUND;
}
## @apmethod int setSessionInfo()
@ -123,7 +128,7 @@ sub setSessionInfo {
$req->{sessionInfo}->{$k} = $demoAccounts{ $req->{user} }->{$v};
}
PE_OK;
return PE_OK;
}
## @apmethod int setGroups()
@ -146,7 +151,7 @@ sub setGroups {
$req->sessionInfo->{groups} = $groups;
$req->sessionInfo->{hGroups} = $hGroups;
PE_OK;
return PE_OK;
}
1;

@ -4,12 +4,16 @@ use strict;
use Mouse;
use JSON qw(from_json to_json);
use Lemonldap::NG::Portal::Main::Constants qw(
PE_ERROR
PE_OK
PE_ERROR
PE_USERNOTFOUND
PE_BADCREDENTIALS
);
extends 'Lemonldap::NG::Common::Module', 'Lemonldap::NG::Portal::Lib::REST';
extends qw(
Lemonldap::NG::Common::Module
Lemonldap::NG::Portal::Lib::REST
);
our $VERSION = '2.0.11';
@ -52,6 +56,7 @@ sub getUser {
return PE_BADCREDENTIALS;
}
$req->data->{restUserDBInfo} = $res->{info} || {};
return PE_OK;
}
@ -93,7 +98,7 @@ sub findUser {
}
unless ( $res->{result} ) {
$self->userLogger->info('FindUser: no user found from REST UserDB');
return PE_OK;
return PE_USERNOTFOUND;
}
my $results = $res->{users};
@ -105,9 +110,10 @@ sub findUser {
$self->userLogger->info(
"FindUser: REST UserDB returns $results->[$rank]");
$req->data->{findUser} = $results->[$rank];
return PE_OK;
}
return PE_OK;
return PE_USERNOTFOUND;
}
sub setSessionInfo {

@ -37,28 +37,33 @@ SKIP: {
);
my $client = LLNG::Manager::Test->new( {
ini => {
logLevel => 'debug',
authentication => 'DBI',
userDB => 'Same',
dbiAuthChain => "dbi:SQLite:dbname=$userdb",
dbiAuthUser => '',
dbiAuthPassword => '',
dbiAuthTable => 'users',
dbiAuthLoginCol => 'uid',
dbiAuthPasswordCol => 'password',
dbiAuthPasswordHash => '',
dbiDynamicHashEnabled => 0,
useSafeJail => 1,
requireToken => 0,
findUser => 1,
impersonationRule => 1,
findUserSearchingAttributes =>
{ uid => 'Login', guy => 'Kind', cn => 'Name', room => 'Room' },
logLevel => 'error',
authentication => 'DBI',
userDB => 'Same',
dbiAuthChain => "dbi:SQLite:dbname=$userdb",
dbiAuthUser => '',
dbiAuthPassword => '',
dbiAuthTable => 'users',
dbiAuthLoginCol => 'uid',
dbiAuthPasswordCol => 'password',
dbiAuthPasswordHash => '',
dbiDynamicHashEnabled => 0,
useSafeJail => 1,
requireToken => 0,
findUser => 1,
impersonationRule => 1,
findUserSearchingAttributes => {
uid => 'Login',
guy => 'Kind',
cn => 'Name',
room => 'Room'
},
findUserExcludingAttributes =>
{ type => 'mutant', uid => 'rtyler' },
}
}
);
use Lemonldap::NG::Portal::Main::Constants 'PE_USERNOTFOUND';
## Simple access
ok( $res = $client->_get( '/', accept => 'text/html' ), 'Get Portal', );
@ -221,10 +226,10 @@ m%<input id="findUser_room" name="room" type="text" autocomplete="off" class="fo
);
ok( $json = eval { from_json( $res->[2]->[0] ) }, 'Response is JSON' )
or print STDERR "$@\n" . Dumper($res);
ok( $json->{result} == 1, ' Good result' )
or explain( $json, 'result => 1' );
ok( $json->{user} eq '', ' No user' )
or explain( $json, 'user => ?' );
ok( $json->{result} == 0, ' Good result' )
or explain( $json, 'result => 0' );
ok( $json->{error} == PE_USERNOTFOUND, ' No user found' )
or explain( $json, 'error => 4' );
$request = 'uid=dalek';
ok(
@ -237,10 +242,10 @@ m%<input id="findUser_room" name="room" type="text" autocomplete="off" class="fo
);
ok( $json = eval { from_json( $res->[2]->[0] ) }, 'Response is JSON' )
or print STDERR "$@\n" . Dumper($res);
ok( $json->{result} == 1, ' Good result' )
or explain( $json, 'result => 1' );
ok( $json->{user} eq '', ' No user' )
or explain( $json, 'user => ?' );
ok( $json->{result} == 0, ' Good result' )
or explain( $json, 'result => 0' );
ok( $json->{error} == PE_USERNOTFOUND, ' No user found' )
or explain( $json, 'error => 4' );
$request = 'uid=rtyler';
ok(
@ -253,10 +258,10 @@ m%<input id="findUser_room" name="room" type="text" autocomplete="off" class="fo
);
ok( $json = eval { from_json( $res->[2]->[0] ) }, 'Response is JSON' )
or print STDERR "$@\n" . Dumper($res);
ok( $json->{result} == 1, ' Good result' )
or explain( $json, 'result => 1' );
ok( $json->{user} eq '', ' No user' )
or explain( $json, 'user => ?' );
ok( $json->{result} == 0, ' Good result' )
or explain( $json, 'result => 0' );
ok( $json->{error} == PE_USERNOTFOUND, ' No user found' )
or explain( $json, 'error => 4' );
$request = 'room=0';
ok(

@ -5,7 +5,7 @@ use IO::String;
require 't/test-lib.pm';
my $maintests = 41;
my $maintests = 42;
my $res;
my $json;
@ -26,6 +26,7 @@ my $client = LLNG::Manager::Test->new( {
}
}
);
use Lemonldap::NG::Portal::Main::Constants 'PE_USERNOTFOUND';
## Simple access
ok( $res = $client->_get( '/', accept => 'text/html' ), 'Get Portal', );
@ -109,8 +110,10 @@ ok(
);
ok( $json = eval { from_json( $res->[2]->[0] ) }, 'Response is JSON' )
or print STDERR "$@\n" . Dumper($res);
ok( $json->{user} eq '', ' No user' )
or explain( $json, "user => ''" );
ok( $json->{result} == 0, ' Good result' )
or explain( $json, 'result => 0' );
ok( $json->{error} == PE_USERNOTFOUND, ' No user found' )
or explain( $json, 'error => 4' );
$request = 'cn=Bad Guy';
ok(
@ -181,10 +184,10 @@ ok(
);
ok( $json = eval { from_json( $res->[2]->[0] ) }, 'Response is JSON' )
or print STDERR "$@\n" . Dumper($res);
ok( $json->{result} == 1, ' Good result' )
or explain( $json, 'result => 1' );
ok( $json->{user} eq '', ' No user' )
or explain( $json, 'user => ?' );
ok( $json->{result} == 0, ' Good result' )
or explain( $json, 'result => 0' );
ok( $json->{error} == PE_USERNOTFOUND, ' No user found' )
or explain( $json, 'error => 4' );
$request = 'uid=dalek';
ok(
@ -197,10 +200,10 @@ ok(
);
ok( $json = eval { from_json( $res->[2]->[0] ) }, 'Response is JSON' )
or print STDERR "$@\n" . Dumper($res);
ok( $json->{result} == 1, ' Good result' )
or explain( $json, 'result => 1' );
ok( $json->{user} eq '', ' No user' )
or explain( $json, 'user => ?' );
ok( $json->{result} == 0, ' Good result' )
or explain( $json, 'result => 0' );
ok( $json->{error} == PE_USERNOTFOUND, ' No user found' )
or explain( $json, 'error => 4' );
$request = 'uid=rtyler';
ok(
@ -213,10 +216,10 @@ ok(
);
ok( $json = eval { from_json( $res->[2]->[0] ) }, 'Response is JSON' )
or print STDERR "$@\n" . Dumper($res);
ok( $json->{result} == 1, ' Good result' )
or explain( $json, 'result => 1' );
ok( $json->{user} eq '', ' No user' )
or explain( $json, 'user => ?' );
ok( $json->{result} == 0, ' Good result' )
or explain( $json, 'result => 0' );
ok( $json->{error} == PE_USERNOTFOUND, ' No user found' )
or explain( $json, 'error => 4' );
count($maintests);
done_testing( count() );

@ -8,7 +8,7 @@ require 't/test-lib.pm';
my $res;
my $json;
my $request;
my $maintests = 41;
my $maintests = 42;
SKIP: {
skip 'LLNGTESTLDAP is not set', $maintests unless ( $ENV{LLNGTESTLDAP} );
@ -16,15 +16,15 @@ SKIP: {
my $client = LLNG::Manager::Test->new( {
ini => {
logLevel => 'error',
authentication => 'LDAP',
portal => 'http://auth.example.com/',
userDB => 'Same',
ldapServer => 'ldap://127.0.0.1:19389/',
ldapBase => 'ou=users,dc=example,dc=com',
managerDn => 'cn=admin,dc=example,dc=com',
managerPassword => 'admin',
ldapExportedVars => {
logLevel => 'error',
authentication => 'LDAP',
portal => 'http://auth.example.com/',
userDB => 'Same',
ldapServer => 'ldap://127.0.0.1:19389/',
ldapBase => 'ou=users,dc=example,dc=com',
managerDn => 'cn=admin,dc=example,dc=com',
managerPassword => 'admin',
ldapExportedVars => {
uid => 'uid',
cn => 'cn',
sn => 'sn',
@ -42,6 +42,8 @@ SKIP: {
}
}
);
use Lemonldap::NG::Portal::Main::Constants 'PE_USERNOTFOUND';
## Simple access
ok( $res = $client->_get( '/', accept => 'text/html' ), 'Get Portal', );
my ( $host, $url, $query ) =
@ -125,8 +127,10 @@ m%<input id="findUser_cn" name="cn" type="text" autocomplete="off" class="form-c
);
ok( $json = eval { from_json( $res->[2]->[0] ) }, 'Response is JSON' )
or print STDERR "$@\n" . Dumper($res);
ok( $json->{user} eq '', ' No user' )
or explain( $json, "user => ''" );
ok( $json->{result} == 0, ' Good result' )
or explain( $json, 'result => 0' );
ok( $json->{error} == PE_USERNOTFOUND, ' No user found' )
or explain( $json, 'error => 4' );
$request = 'cn=Rose Tyler';
ok(
@ -197,10 +201,10 @@ m%<input id="findUser_cn" name="cn" type="text" autocomplete="off" class="form-c
);
ok( $json = eval { from_json( $res->[2]->[0] ) }, 'Response is JSON' )
or print STDERR "$@\n" . Dumper($res);
ok( $json->{result} == 1, ' Good result' )
or explain( $json, 'result => 1' );
ok( $json->{user} eq '', ' No user' )
or explain( $json, 'user => ?' );
ok( $json->{result} == 0, ' Good result' )
or explain( $json, 'result => 0' );
ok( $json->{error} == PE_USERNOTFOUND, ' No user found' )
or explain( $json, 'error => 4' );
$request = 'uid=russian';
ok(
@ -213,10 +217,10 @@ m%<input id="findUser_cn" name="cn" type="text" autocomplete="off" class="form-c
);
ok( $json = eval { from_json( $res->[2]->[0] ) }, 'Response is JSON' )
or print STDERR "$@\n" . Dumper($res);
ok( $json->{result} == 1, ' Good result' )
or explain( $json, 'result => 1' );
ok( $json->{user} eq '', ' No user' )
or explain( $json, 'user => ?' );
ok( $json->{result} == 0, ' Good result' )
or explain( $json, 'result => 0' );
ok( $json->{error} == PE_USERNOTFOUND, ' No user found' )
or explain( $json, 'error => 4' );
$request = 'uid=french';
ok(
@ -229,10 +233,10 @@ m%<input id="findUser_cn" name="cn" type="text" autocomplete="off" class="form-c
);
ok( $json = eval { from_json( $res->[2]->[0] ) }, 'Response is JSON' )
or print STDERR "$@\n" . Dumper($res);
ok( $json->{result} == 1, ' Good result' )
or explain( $json, 'result => 1' );
ok( $json->{user} eq '', ' No user' )
or explain( $json, 'user => ?' );
ok( $json->{result} == 0, ' Good result' )
or explain( $json, 'result => 0' );
ok( $json->{error} == PE_USERNOTFOUND, ' No user found' )
or explain( $json, 'error => 4' );
clean_sessions();
}

@ -48,17 +48,12 @@ LWP::Protocol::PSGI->register(
return [
200,
[ 'Content-Type' => 'application/json' ],
['{"result":true,"users":[]}']
['{"result":0,"users":[]}']
];
}
elsif ( $res->{searchingAttributes} eq
'[{"guy":"good"}]' )
{
ok(
$res->{searchingAttributes} eq
'[{"guy":"good"}]',
' guy:good'
);
elsif ( $res->{searchingAttributes} eq '[{"guy":"good"}]' ) {
ok( $res->{searchingAttributes} eq '[{"guy":"good"}]',
' guy:good' );
count(1);
return [
200,
@ -97,6 +92,7 @@ my $client = LLNG::Manager::Test->new( {
}
}
);
use Lemonldap::NG::Portal::Main::Constants 'PE_USERNOTFOUND';
$request = 'uid=dwho';
ok(
@ -125,13 +121,12 @@ ok(
),
'Post null response FindFuser request'
);
expectOK($res);
ok( $json = eval { from_json( $res->[2]->[0] ) }, 'Response is JSON' )
or print STDERR "$@\n" . Dumper($res);
ok( $json->{user} eq '', ' Empty user' )
or explain( $json, "user => ''" );
ok( $json->{result} == 1, ' result => 1' )
or explain( $json, 'Result => 1' );
ok( $json->{result} == 0, ' Good result' )
or explain( $json, 'result => 0' );
ok( $json->{error} == PE_USERNOTFOUND, ' No user found' )
or explain( $json, 'error => 4' );
count(4);
$request = 'other=dwho';

Loading…
Cancel
Save