forked from vufind-org/vufind
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
176 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
; This file controls the behavior of the SimulatedSSO authentication module, | ||
; which is intended for testing/development use only. This can be used to | ||
; log in a specific user account as if single sign-on was triggered, which is | ||
; useful for evaluating VuFind's SSO behavior when a real environment is not | ||
; available. | ||
[General] | ||
; What username should be returned? (Set to false to throw an exception instead). | ||
username = fakeuser1 | ||
|
||
; Map of user attributes to set (corresponding to columns in the user table). | ||
; Comment this out to use defaults, and set "attributes = false" to disable all | ||
; attributes. | ||
attributes[firstname] = Test | ||
attributes[lastname] = User | ||
attributes[email] = "[email protected]" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,8 @@ | |
use Laminas\Http\PhpEnvironment\Request; | ||
use VuFind\Exception\Auth as AuthException; | ||
|
||
use function is_array; | ||
|
||
/** | ||
* Simulated single sign-on authentication module (for testing purposes only). | ||
* | ||
|
@@ -50,14 +52,34 @@ class SimulatedSSO extends AbstractBase | |
*/ | ||
protected $getSessionInitiatorCallback; | ||
|
||
/** | ||
* Configuration settings | ||
* | ||
* @var array | ||
*/ | ||
protected $simulatedSSOConfig; | ||
|
||
/** | ||
* Default user attributes, if not overridden by configuration. | ||
* | ||
* @var array | ||
*/ | ||
protected $defaultAttributes = [ | ||
'firstname' => 'Test', | ||
'lastname' => 'User', | ||
'email' => '[email protected]', | ||
]; | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param callable $url Session initiator URL callback | ||
* @param callable $url Session initiator URL callback | ||
* @param array $config Configuration settings | ||
*/ | ||
public function __construct($url) | ||
public function __construct($url, array $config = []) | ||
{ | ||
$this->getSessionInitiatorCallback = $url; | ||
$this->simulatedSSOConfig = $config; | ||
} | ||
|
||
/** | ||
|
@@ -71,10 +93,36 @@ public function __construct($url) | |
public function authenticate($request) | ||
{ | ||
// If we made it this far, we should log in the user! | ||
$user = $this->getUserTable()->getByUsername('fakeuser1'); | ||
$user->firstname = 'Test'; | ||
$user->lastname = 'User'; | ||
$user->email = '[email protected]'; | ||
$username = $this->simulatedSSOConfig['General']['username'] ?? 'fakeuser1'; | ||
if (!$username) { | ||
throw new AuthException('Simulated failure'); | ||
} | ||
$user = $this->getUserTable()->getByUsername($username); | ||
|
||
// Get attribute configuration -- use defaults if no value is set, and use an | ||
// empty array if something invalid was provided. | ||
$attribs = $this->simulatedSSOConfig['General']['attributes'] | ||
?? $this->defaultAttributes; | ||
if (!is_array($attribs)) { | ||
$attribs = []; | ||
} | ||
|
||
$catPassword = null; | ||
foreach ($attribs as $attribute => $value) { | ||
if ($attribute == 'email') { | ||
$user->updateEmail($value); | ||
} elseif ($attribute != 'cat_password') { | ||
$user->$attribute = $value ?? ''; | ||
} else { | ||
$catPassword = $value; | ||
} | ||
} | ||
if (!empty($user->cat_username)) { | ||
$user->saveCredentials( | ||
$user->cat_username, | ||
empty($catPassword) ? $user->getCatPassword() : $catPassword | ||
); | ||
} | ||
|
||
// Save and return the user object: | ||
$user->save(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters