Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Maxime Besson
lemonldap-ng
Commits
64523473
Commit
64523473
authored
Mar 28, 2016
by
Yadd
Browse files
Portal PSGI in progress
parent
43cf53b2
Changes
1
Hide whitespace changes
Inline
Side-by-side
lemonldap-ng-portal/lib/Lemonldap/NG/Portal/PSGI.pm
View file @
64523473
...
...
@@ -16,9 +16,18 @@ use constant HANDLER => 'Lemonldap::NG::Handler::PSGI::API';
extends
'
Lemonldap::NG::Handler::PSGI::Try
';
# Configuration storage
has
localConfig
=>
(
is
=>
'
rw
',
default
=>
sub
{
{}
}
);
has
conf
=>
(
is
=>
'
rw
',
default
=>
sub
{
{}
}
);
# Sub modules
has
_authentication
=>
(
is
=>
'
rw
'
);
has
_userDB
=>
(
is
=>
'
rw
'
);
has
_passwordDB
=>
(
is
=>
'
rw
'
);
has
_registerDB
=>
(
is
=>
'
rw
'
);
has
_issuers
=>
(
is
=>
'
rw
'
);
sub
init
{
my
(
$self
,
$args
)
=
@_
;
$args
||=
{};
...
...
@@ -46,7 +55,7 @@ sub checkConf {
# Load conf in portal object
foreach
my
$key
(
keys
%$conf
)
{
$self
->
conf
->
{
$key
}
=
$localConfig
->
{
$key
}
//
$conf
->
{
$key
};
$self
->
conf
->
{
$key
}
=
$
self
->
localConfig
->
{
$key
}
//
$conf
->
{
$key
};
}
# Initialize session DBs
...
...
@@ -75,25 +84,26 @@ sub checkConf {
$self
->
conf
->
{
domain
}
=~
s/^([^\.])/.$1/
;
# Load authentication/userDB/passwordDB modules
# ---------------------------------------------
for
my
$type
(
qw(authentication userDB passwordDB registerDB)
)
{
unless
(
$self
->
conf
->
{
$type
}
)
{
$self
->
error
("
$type
is not set
");
return
0
;
}
my
$module
=
ucfirst
(
$type
)
.
$self
->
conf
->
{
$
db_
type
};
my
$module
=
ucfirst
(
$type
)
.
$self
->
conf
->
{
$type
};
$module
=~
s/\s.*$//
;
$module
=~
s/^Authentication/Auth/
;
$module
=
"
Lemonldap::NG::Portal::
$module
";
unless
(
$self
->
loadModule
(
$module
)
)
{
$self
->
error
("
Unable to load
$module_name
");
return
0
;
}
# $self->conf->{authentication} and $self->conf->{userDB} can
contains arguments
#
(key1 = scalar_value; key2 = ...)
my
(
$tmp
,
%h
)
=
split
(
/\s*[=;]\s*/
,
$self
->
conf
->
{
$
db_
type
}
);
# $self->conf->{authentication} and $self->conf->{userDB} can
# contains arguments
(key1 = scalar_value; key2 = ...)
my
(
$tmp
,
%h
)
=
split
(
/\s*[=;]\s*/
,
$self
->
conf
->
{
$type
}
);
%
{
$self
->
{
conf
}
}
=
(
%h
,
%
{
$self
->
{
conf
}
}
)
if
(
%h
);
return
0
unless
(
$self
->
loadModule
(
$module
,
"
_
$type
"
)
);
}
# Load issuer modules
# -------------------
foreach
my
$issuerDBtype
(
qw(SAML OpenID CAS OpenIDConnect)
)
{
my
$module
=
'
Lemonldap::NG::Portal::IssuerDB
'
.
$issuerDBtype
;
$self
->
lmLog
(
...
...
@@ -116,10 +126,26 @@ sub checkConf {
);
next
;
}
$self
->
addAuthRoute
(
$path
,
"
${issuerDBtype}
ForAuthUser
",
[
qw(GET POST PUT DELETE)
]
);
$self
->
addUnauthRoute
(
$path
,
"
${issuerDBtype}
ForUnauthUser
",
[
qw(GET POST PUT DELETE)
]
);
return
0
unless
(
$self
->
loadModule
(
$module
,
'
tmp
'
)
);
$self
->
{
issuers
}
->
{
$issuerDBtype
}
=
$self
->
{
tmp
};
delete
$self
->
{
tmp
};
$self
->
addAuthRoute
(
$path
,
sub
{
my
$self
=
shift
;
return
$self
->
issuerForAuthUser
(
$issuerDBtype
,
@
_
);
},
[
qw(GET POST PUT DELETE)
]
);
$self
->
addUnauthRoute
(
$path
,
sub
{
my
$self
=
shift
;
return
$self
->
issuerForUnauthUser
(
$issuerDBtype
,
@
_
);
},
[
qw(GET POST PUT DELETE)
]
);
# TODO "check the path"
}
...
...
@@ -145,45 +171,33 @@ sub checkConf {
# @param ignoreError set to 1 if error should not appear in logs
# @return boolean
sub
loadModule
{
my
(
$self
,
$module
,
$ignoreError
)
=
@_
;
return
1
unless
$module
;
my
(
$self
,
$module
,
$keyname
)
=
@_
;
# Load module test
eval
"
require
$module
";
if
(
$@
)
{
$self
->
lmLog
(
"
$module
load error: $@
"
,
'
error
'
)
unless
$ignoreError
;
$self
->
error
(
"
$module
load error: $@
"
)
;
return
0
;
}
push
@
{
$self
->
{
ISA
},
$module
;
}
$self
->
lmLog
(
"
Module
$module
loaded
",
'
debug
'
);
eval
{
$self
->
{
$keyname
}
=
$module
->
new
(
{
p
=>
$self
,
conf
=>
$self
->
conf
}
);
};
if
(
$@
)
{
$self
->
error
("
Unable to build
$module
object: $@
");
return
0
;
}
return
0
unless
(
$self
->
{
$keyname
}
);
$self
->
lmLog
(
"
Module
$module
loaded
",
'
debug
'
);
return
1
;
}
sub
SAMLForAuthUser
{
}
sub
SAMLForUnauthUser
{
}
sub
OpenIDForAuthUser
{
}
sub
OpenIDForUnauthUser
{
}
sub
CASForAuthUser
{
}
sub
CASForUnauthUser
{
}
sub
OpenIDConnectForAuthUser
{
sub
issuerForAuthUser
{
my
(
$self
,
$type
,
$req
)
=
@_
;
}
sub
OpenIDConnectForUnauthUser
{
sub
issuerForUnauthUser
{
my
(
$self
,
$type
,
$req
)
=
@_
;
}
# TODO in run
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment