lemonldap-ng/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/UserDB/Demo.pm

90 lines
1.8 KiB
Perl
Raw Normal View History

2016-03-30 07:47:38 +02:00
## @file
# Demo userDB mechanism
## @class
# Demo userDB mechanism class
package Lemonldap::NG::Portal::UserDB::Demo;
use strict;
2016-04-03 18:27:22 +02:00
use Mouse;
use Lemonldap::NG::Portal::Main::Constants qw(PE_OK PE_BADCREDENTIALS);
2016-03-30 07:47:38 +02:00
2016-06-02 23:20:36 +02:00
extends 'Lemonldap::NG::Common::Module';
2016-04-03 18:27:22 +02:00
2019-02-05 18:44:31 +01:00
our $VERSION = '2.0.2';
2016-03-30 07:47:38 +02:00
2017-01-29 10:11:27 +01:00
# Sample accounts from Doctor Who characters
2017-03-01 18:35:12 +01:00
our %demoAccounts = (
'rtyler' => {
'uid' => 'rtyler',
'cn' => 'Rose Tyler',
'mail' => 'rtyler@badwolf.org',
},
'msmith' => {
'uid' => 'msmith',
'cn' => 'Mickey Smith',
'mail' => 'msmith@badwolf.org',
},
'dwho' => {
'uid' => 'dwho',
'cn' => 'Doctor Who',
'mail' => 'dwho@badwolf.org',
},
2017-01-29 10:11:27 +01:00
);
2017-01-14 20:31:48 +01:00
# INITIALIZATION
sub init {
2016-04-03 18:27:22 +02:00
1;
2016-03-30 07:47:38 +02:00
}
2017-01-30 22:00:54 +01:00
# RUNNING METHODS
2016-06-09 20:40:20 +02:00
2016-03-30 07:47:38 +02:00
## @apmethod int getUser()
# Check known accounts
# @return Lemonldap::NG::Portal constant
sub getUser {
2018-01-23 22:41:40 +01:00
my ( $self, $req, %args ) = @_;
2016-03-30 07:47:38 +02:00
2018-01-23 22:41:40 +01:00
if ( $args{useMail} ) {
2016-03-30 07:47:38 +02:00
return PE_OK
if (
2017-01-29 10:11:27 +01:00
( $req->{user} ) =
2018-01-23 22:41:40 +01:00
grep { $demoAccounts{$_}->{mail} eq $req->{user} }
2017-03-01 18:35:12 +01:00
keys %demoAccounts
2016-03-30 07:47:38 +02:00
);
}
2018-01-23 22:41:40 +01:00
else {
return PE_OK
if ( defined $demoAccounts{ $req->user } );
}
2016-03-30 07:47:38 +02:00
eval { $self->p->_authentication->setSecurity($req) };
PE_BADCREDENTIALS;
2016-03-30 07:47:38 +02:00
}
## @apmethod int setSessionInfo()
# Get sample data
# @return Lemonldap::NG::Portal constant
sub setSessionInfo {
my ( $self, $req ) = @_;
my %vars = ( %{ $self->conf->{exportedVars} },
%{ $self->conf->{demoExportedVars} } );
while ( my ( $k, $v ) = each %vars ) {
2017-03-01 18:35:12 +01:00
$req->{sessionInfo}->{$k} = $demoAccounts{ $req->{user} }->{$v}
2016-03-30 07:47:38 +02:00
|| "";
}
PE_OK;
}
## @apmethod int setGroups()
# Do nothing
# @return Lemonldap::NG::Portal constant
sub setGroups {
PE_OK;
}
1;