SimpleSAMLErrorError: UNHANDLEDEXCEPTION
Backtrace:
1 www/_include.php:17 (SimpleSAML_exception_handler)
0 [builtin] (N/A)
Caused by: SimpleSAMLErrorException: Missing or invalid password option in config.
Backtrace:
7 modules/fabricModule/lib/Auth/Source/fabricAuth.php:29 (SimpleSAMLModulefabricModuleAuthSourcefabricAuth::__construct)
6 lib/SimpleSAML/Auth/Source.php:336 (SimpleSAMLAuthSource::parseAuthSource)
5 lib/SimpleSAML/Auth/Source.php:381 (SimpleSAMLAuthSource::getById)
4 lib/SimpleSAML/Auth/Simple.php:68 (SimpleSAMLAuthSimple::getAuthSource)
3 lib/SimpleSAML/Auth/Simple.php:168 (SimpleSAMLAuthSimple::login)
2 modules/core/www/authenticate.php:38 (require)
1 lib/SimpleSAML/Module.php:266 (SimpleSAMLModule::process)
0 www/module.php:10 (N/A)
我正在尝试将我的simplesamlphp与MySQL数据库连接起来。我只是从数据库中检索用户名和密码。我为此创建了一个自定义身份验证模块。我的主要目标是创建一个自定义身份验证模块。我遵循了SimpleSAMLphp自定义身份验证文档。这是我的代码:
<?php
namespace SimpleSAMLModulefabricModuleAuthSource;
use Exception;
class fabricAuth extends SimpleSAMLModulecoreAuthUserPassBase {
/* The database DSN.
* See the documentation for the various database drivers for information about the syntax:
* http://www.php.net/manual/en/pdo.drivers.php
*/
private $dsn;
// The database username, password & option
private $username;
private $password;
private $options;
public function __construct($info, $config){
parent::__construct($info, $config);
if(!is_string($config['dsn'])){
throw new SimpleSAMLErrorException('Missing or invalid dsn option in config.');
}
$this->dsn = $config['dsn'];
if(!is_string($config['username'])){
throw new SimpleSAMLErrorException('Missing or invalid username option in config.');
}
$this->username = $config['username'];
if(!is_string($config['passwword'])){
throw new SimpleSAMLErrorException('Missing or invalid password option in config.');
}
$this->password = $config['password'];
if((isset($config['options']))){
if(!is_array($config['options'])){
throw new SimpleSAMLErrorException('Missing or invalid options option in config.');
}
$this->options = $config['options'];
}
}
/**
* A helper function for validating a password hash.
*
* In this example we check a SSHA-password, where the database
* contains a base64 encoded byte string, where the first 20 bytes
* from the byte string is the SHA1 sum, and the remaining bytes is
* the salt.
*/
private function checkPassword($passwordHash, $password){
$passwordHash = base64_decode($passwordHash);
$digest = substr($passwordHash, 0, 20);
$salt = substr($passwordHash, 20);
$checkDigest = sha1($password, $salt, TRUE);
return $digest === $checkDigest;
}
protected function login($username, $password){
// Connect to the database
$db = new PDO($this->dsn, $this->username, $this->password, $this->options);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
/* Ensure that we are operating with UTF-8 encoding.
* This command is for MySQL. Other databases may need different commands.
*/
$db->exec("SET NAMES 'utf8'");
/* With PDO we use prepared statements. This saves us from having to escape
* the username in the database query.
*/
$st = $db->prepare('SELECT username, password_hash, full_name FROM userdb WHERE username=:username');
if(!$st->execute(['username'=>$username])){
throw new SimpleSAMLErrorException('Failed to query database for user.');
}
// Retrieve the row from the database.
$row = $st->fetch(PDO::FETCH_ASSOC);
if(!row){
// user not found
SimpleSAMLLogger::warning('fabricAuth: Could not find user ' . var_export($username, TRUE) . '.');
throw new SimpleSAMLErrorException('Failed to query database for user.');
}
// check the password
if(!$this->checkPassword($row['password_hash'], $password)){
// invalid password
SimpleSAMLLogger::warning('fabricAuth: Wrong password for user ' . var_export($username, TRUE) . '.');
throw new SimpleSAMLErrorError('WRONGUSERPASS');
}
// Create the attribute array of the user.
$attributes =[
'uid'=> [$username],
'displayName'=>[$row['full_name']],
'eduPersonAffiliation'=>['member', 'employee'],
];
// return the attributes
return $attributes;
}
}
你能告诉我为什么我会得到这个例外吗?提前谢谢。
您在中拼写错误密码
if(!is_string($config['passwword'])){
这可能与$config
中的密码设置不一致