Apache2-AuthAny
view release on metacpan or search on metacpan
examples/demo/index.php view on Meta::CPAN
515253545556575859606162636465666768697071Apache2::AuthAny (optionally) uses a database table (userIdent) to
resolve the identities provided by the identity providers. Multiple
provider identities can resolve to a single AuthAny identity.
This AuthAny identity can then be used
for
authorization purposes.
</p>
<h2>Trial logins</h2>
<p>
To make it possible to show the authentication and authorization
capabilities to anyone coming to this site, several
"basic auth"
accounts/passwords have been set
up. The password field should be left blank
<ul>
<li><b>aatest1</b> - This user name is not in the identity table. The access provided will be similar
to what you will get
if
an unknown user (you) logs in
with
Google or Shibboleth.
</li>
<li><b>aatest2</b> - This user name IS in
our
userIdent and user
tables. The user's name and roles are available.
</li>
<li><b>aatest3</b> - This user name is linked to the same user as
"aatest2"
.</li>
lib/Apache2/AuthAny/DB.pm view on Meta::CPAN
9101112131415161718192021222324252627282930313233my
$dbHandle
;
our
$VERSION
=
'0.201'
;
sub
new {
my
$class
=
shift
;
my
$self
= {};
unless
(
$dbHandle
) {
my
$dbUser
=
$ENV
{AUTH_ANY_DB_USER} ||
die
"Env variable AUTH_ANY_DB_USER required"
;
my
$dbPasswordFile
=
$ENV
{AUTH_ANY_DB_PW_FILE} ||
die
"Env variable AUTH_ANY_DB_PW_FILE required"
;
open
(PWD,
"<$dbPasswordFile"
) ||
die
"Could not read password file, '$dbPasswordFile'. $!"
;
my
$dbPassword
= <PWD>;
close
(PWD) ||
die
"ouch $!"
;
chomp
$dbPassword
;
#remove the trailing new line
die
"Could not get password"
unless
$dbPassword
;
my
$dbName
=
$ENV
{AUTH_ANY_DB_NAME} ||
die
"Env variable AUTH_ANY_DB_NAME required"
;
my
$db
;
$db
=
$ENV
{AUTH_ANY_DB} ||
"mysql"
;
my
$dsn
=
"database=$dbName"
;
my
$dbHost
=
$ENV
{AUTH_ANY_DB_HOST};
$dsn
.=
";host=$dbHost"
if
$dbHost
;
$dbHandle
= DBI->
connect
(
"DBI:$db:$dsn"
,
$dbUser
,
$dbPassword
) or
die
"user: $dbUser, errstr: $DBI::errstr"
;
$dbHandle
->
do
(
'SET CHARACTER SET utf8'
);
}
lib/Apache2/AuthAny/DB.pm view on Meta::CPAN
190191192193194195196197198199200201202203204205206207208209210
AND authId = ? AND authProvider = ? limit 1';
$self
->useDB();
return
$dbHandle
->selectrow_hashref(
$getUserSql
,
undef
,
$authId
,
$authProvider
);
}
sub
getBasicUser {
my
$self
=
shift
;
my
(
$user
) =
@_
;
my
$sql
=
'select user, password from basicAuth WHERE user = ?'
;
$self
->useDB();
return
$dbHandle
->selectrow_hashref(
$sql
,
undef
,
$user
);
}
sub
getUserRoles {
my
$self
=
shift
;
my
(
$UID
) =
@_
;
my
$getRoleSql
=
'select role from userRole WHERE UID = ?'
;
lib/Apache2/AuthAny/RequestConfig.pm view on Meta::CPAN
206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261sub
get_scripted_pid {
my
$r
=
shift
;
my
$cf
=
shift
;
if
(
$cf
->{AuthAnyBasicAuthUserFile}) {
unless
(
open
(HTPASSWD,
$cf
->{AuthAnyBasicAuthUserFile})) {
my
$msg
=
"Cannot read '$cf->{AuthAnyBasicAuthUserFile}' $!"
;
die
$msg
;
}
my
(
$http_user
,
$http_password
) = get_user_and_password(
$r
);
if
(
$http_user
&&
$http_password
) {
my
$stored_passwd
;
while
(<HTPASSWD>) {
chomp
;
my
(
$username
,
$crypt_passwd
) =
split
(
":"
,
$_
, 2);
if
(
$username
eq
$http_user
) {
if
(
crypt
(
$http_password
,
$crypt_passwd
) eq
$crypt_passwd
) {
$r
->
log
->info(
"RequestConfig: From HTTP header: $username"
);
return
{
PID
=>
'unused'
,
SID
=>
'unused'
,
logoutKey
=>
'unused'
,
state
=>
'authenticated'
,
scripted
=> 1,
authId
=>
$username
,
authProvider
=>
'basic'
,
last
=> 2298416724,
# time in the future
};
}
else
{
my
$msg
=
"RequestConfig: Basic user found in "
.
"$cf->{AuthAnyBasicAuthUserFile}, however password is incorrect"
;
$r
->
log
->
warn
(
$msg
);
last
;
}
}
}
}
}
}
sub
get_user_and_password {
my
$r
=
shift
;
my
$Authorization
=
$r
->headers_in->{Authorization};
if
(
$Authorization
) {
my
(
$type
,
$hash
) =
split
" "
,
$Authorization
;
my
$u_and_p
= decode_base64(
$hash
);
if
(
$u_and_p
) {
my
(
$user
,
$password
) =
split
(/:/,
$u_and_p
, 2);
return
(
$user
,
$password
);
}
}
return
undef
;
}
1;
( run in 0.369 second using v1.01-cache-2.11-cpan-87723dcf8b7 )