DefaultAuthenticationManager.php
1 <?php
2 /**
3  * wCMF - wemove Content Management Framework
4  * Copyright (C) 2005-2020 wemove digital solutions GmbH
5  *
6  * Licensed under the terms of the MIT License.
7  *
8  * See the LICENSE file distributed with this work for
9  * additional information.
10  */
11 namespace wcmf\lib\security\impl;
12 
17 
18 /**
19  * DefaultAuthenticationManager uses PrincipalFactory to get a User instance
20  * that matches the given login/password combination.
21  *
22  * @author ingo herwig <ingo@wemove.com>
23  */
25 
26  private $principalFactory = null;
27 
28  /**
29  * Constructor
30  * @param $principalFactory PrincipalFactory instance
31  */
32  public function __construct(PrincipalFactory $principalFactory) {
33  $this->principalFactory = $principalFactory;
34  }
35 
36  /**
37  * @see AuthenticationManager::login()
38  *
39  * @param $credentials Associative array with the keys 'login' and 'password'
40  */
41  public function login($credentials) {
42  if (!isset($credentials['login']) || !isset($credentials['password'])) {
43  throw new IllegalArgumentException("The parameters 'login' and 'password' are required");
44  }
45  $config = ObjectFactory::getInstance('configuration');
46 
47  $login = $credentials['login'];
48  $password = $credentials['password'];
49 
50  // try to receive the user with given credentials
51  $user = $this->principalFactory->getUser($login, true);
52 
53  // check if user exists
54  $loginOk = false;
55  if ($user != null && $user->isActive()) {
56  // check password
57  $loginOk = $user->verifyPassword($password);
58  if ($loginOk) {
59  // load user config initially
60  $userConfig = $user->getConfig();
61  if (strlen($userConfig) > 0) {
62  $config->addConfiguration($userConfig);
63  }
64  return $user;
65  }
66  }
67  return null;
68  }
69 }
70 ?>
IllegalArgumentException signals an exception in method arguments.
DefaultAuthenticationManager uses PrincipalFactory to get a User instance that matches the given logi...
AuthenticationManager implementations are used to handle all authentication requests.
__construct(PrincipalFactory $principalFactory)
Constructor.
static getInstance($name, $dynamicConfiguration=[])
PrincipalFactory implementations are used to retrieve User and Role instances.
ObjectFactory implements the service locator pattern by wrapping a Factory instance and providing sta...