Skip to content
GitLab
Explore
Projects
Groups
Snippets
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Wolfgang Knopki
simplesamlphp_sqlauthbcrypt
Commits
5f8d03fe
Commit
5f8d03fe
authored
4 years ago
by
Wolfgang Knopki
Browse files
Options
Download
Email Patches
Plain Diff
added compatibility with simplesamlphp 1.19
parent
8e8e5b35
master
deploy_testing
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/Auth/Source/SQL.php
+216
-210
lib/Auth/Source/SQL.php
with
216 additions
and
210 deletions
+216
-210
lib/Auth/Source/SQL.php
+
216
-
210
View file @
5f8d03fe
...
...
@@ -12,8 +12,13 @@
* @package simpleSAMLphp
* @version $Id$
*/
class
sspmod_sqlauthBcrypt_Auth_Source_SQL
extends
sspmod_core_Auth_UserPassBase
{
/*
class sspmod_sqlauthBcrypt_Auth_Source_SQL extends sspmod_core_Auth_UserPassBase {
*/
namespace
SimpleSAML\Module\sqlauthbcrypt\Auth\Source
;
class
sql
extends
\
SimpleSAML\Module\core\Auth\UserPassBase
{
/**
* The DSN we should connect to.
...
...
@@ -68,12 +73,12 @@ class sspmod_sqlauthBcrypt_Auth_Source_SQL extends sspmod_core_Auth_UserPassBase
/* Make sure that all required parameters are present. */
foreach
(
array
(
'dsn'
,
'username'
,
'password'
,
'query'
,
'pepper'
)
as
$param
)
{
if
(
!
array_key_exists
(
$param
,
$config
))
{
throw
new
Exception
(
'Missing required attribute \''
.
$param
.
throw
new
\
Exception
(
'Missing required attribute \''
.
$param
.
'\' for authentication source '
.
$this
->
authId
);
}
if
(
!
is_string
(
$config
[
$param
]))
{
throw
new
Exception
(
'Expected parameter \''
.
$param
.
throw
new
\
Exception
(
'Expected parameter \''
.
$param
.
'\' for authentication source '
.
$this
->
authId
.
' to be a string. Instead it was: '
.
var_export
(
$config
[
$param
],
TRUE
));
...
...
@@ -96,13 +101,13 @@ class sspmod_sqlauthBcrypt_Auth_Source_SQL extends sspmod_core_Auth_UserPassBase
*/
private
function
connect
()
{
try
{
$db
=
new
PDO
(
$this
->
dsn
,
$this
->
username
,
$this
->
password
);
}
catch
(
PDOException
$e
)
{
throw
new
Exception
(
'sqlauthBcrypt:'
.
$this
->
authId
.
$db
=
new
\
PDO
(
$this
->
dsn
,
$this
->
username
,
$this
->
password
);
}
catch
(
\
PDOException
$e
)
{
throw
new
\
Exception
(
'sqlauthBcrypt:'
.
$this
->
authId
.
': - Failed to connect to \''
.
$this
->
dsn
.
'\': '
.
$e
->
getMessage
());
}
$db
->
setAttribute
(
PDO
::
ATTR_ERRMODE
,
PDO
::
ERRMODE_EXCEPTION
);
$db
->
setAttribute
(
\
PDO
::
ATTR_ERRMODE
,
\
PDO
::
ERRMODE_EXCEPTION
);
$driver
=
explode
(
':'
,
$this
->
dsn
,
2
);
...
...
@@ -137,7 +142,7 @@ class sspmod_sqlauthBcrypt_Auth_Source_SQL extends sspmod_core_Auth_UserPassBase
* @param string $password The password the user wrote.
* @return array Associative array with the users attributes.
*/
protected
function
login
(
$username
,
$password
)
{
protected
function
login
(
string
$username
,
string
$password
)
:
array
{
assert
(
'is_string($username)'
);
assert
(
'is_string($password)'
);
...
...
@@ -145,33 +150,33 @@ class sspmod_sqlauthBcrypt_Auth_Source_SQL extends sspmod_core_Auth_UserPassBase
try
{
$sth
=
$db
->
prepare
(
$this
->
query
);
}
catch
(
PDOException
$e
)
{
throw
new
Exception
(
'sqlauthBcrypt:'
.
$this
->
authId
.
}
catch
(
\
PDOException
$e
)
{
throw
new
\
Exception
(
'sqlauthBcrypt:'
.
$this
->
authId
.
': - Failed to prepare query: '
.
$e
->
getMessage
());
}
try
{
$res
=
$sth
->
execute
(
array
(
'username'
=>
$username
));
}
catch
(
PDOException
$e
)
{
throw
new
Exception
(
'sqlauthBcrypt:'
.
$this
->
authId
.
}
catch
(
\
PDOException
$e
)
{
throw
new
\
Exception
(
'sqlauthBcrypt:'
.
$this
->
authId
.
': - Failed to execute query: '
.
$e
->
getMessage
());
}
try
{
$data
=
$sth
->
fetchAll
(
PDO
::
FETCH_ASSOC
);
}
catch
(
PDOException
$e
)
{
throw
new
Exception
(
'sqlauth:'
.
$this
->
authId
.
$data
=
$sth
->
fetchAll
(
\
PDO
::
FETCH_ASSOC
);
}
catch
(
\
PDOException
$e
)
{
throw
new
\
Exception
(
'sqlauth:'
.
$this
->
authId
.
': - Failed to fetch result set: '
.
$e
->
getMessage
());
}
SimpleSAML
_
Logger
::
info
(
'sqlauthBcrypt:'
.
$this
->
authId
.
\
SimpleSAML
\
Logger
::
info
(
'sqlauthBcrypt:'
.
$this
->
authId
.
': Got '
.
count
(
$data
)
.
' rows from database'
);
if
(
count
(
$data
)
===
0
)
{
/* No rows returned - invalid username */
SimpleSAML
_
Logger
::
error
(
'sqlauthBcrypt:'
.
$this
->
authId
.
\
SimpleSAML
\
Logger
::
error
(
'sqlauthBcrypt:'
.
$this
->
authId
.
': No rows in result set. Wrong username or sqlauthBcrypt is misconfigured.'
);
throw
new
SimpleSAML
_
Error
_
Error
(
'WRONGUSERPASS'
);
throw
new
\
SimpleSAML
\
Error
\
Error
(
'WRONGUSERPASS'
);
}
/* Validate stored password hash (must be in first row of resultset) */
...
...
@@ -179,9 +184,9 @@ class sspmod_sqlauthBcrypt_Auth_Source_SQL extends sspmod_core_Auth_UserPassBase
if
(
$password_hash
!==
crypt
(
$password
.
$this
->
pepper
,
$password_hash
))
{
/* Invalid password */
SimpleSAML
_
Logger
::
error
(
'sqlauthBcrypt:'
.
$this
->
authId
.
\
SimpleSAML
\
Logger
::
error
(
'sqlauthBcrypt:'
.
$this
->
authId
.
': Hash does not match. Wrong password or sqlauthBcrypt is misconfigured.'
);
throw
new
SimpleSAML
_
Error
_
Error
(
'WRONGUSERPASS'
);
throw
new
\
SimpleSAML
\
Error
\
Error
(
'WRONGUSERPASS'
);
}
/* Extract attributes. We allow the resultset to consist of multiple rows. Attributes
...
...
@@ -216,7 +221,7 @@ class sspmod_sqlauthBcrypt_Auth_Source_SQL extends sspmod_core_Auth_UserPassBase
}
}
SimpleSAML
_
Logger
::
info
(
'sqlauthBcrypt:'
.
$this
->
authId
.
\
SimpleSAML
\
Logger
::
info
(
'sqlauthBcrypt:'
.
$this
->
authId
.
': Attributes: '
.
implode
(
','
,
array_keys
(
$attributes
)));
return
$attributes
;
...
...
@@ -225,3 +230,4 @@ class sspmod_sqlauthBcrypt_Auth_Source_SQL extends sspmod_core_Auth_UserPassBase
}
?>
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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
Menu
Explore
Projects
Groups
Snippets