DefaultAuthenticationManager.php
1 <?php
2 /**
3  * wCMF - wemove Content Management Framework
4  * Copyright (C) 2005-2015 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 
16 
17 /**
18  * DefaultAuthenticationManager uses PrincipalFactory to get a User instance
19  * that matches the given login/password combination.
20  *
21  * @author ingo herwig <ingo@wemove.com>
22  */
24 
25  private $_principalFactory = null;
26 
27  /**
28  * Constructor
29  * @param $principalFactory PrincipalFactory instance
30  */
31  public function __construct(PrincipalFactory $principalFactory) {
32  $this->_principalFactory = $principalFactory;
33  }
34 
35  /**
36  * @see AuthenticationManager::login()
37  */
38  public function login($login, $password) {
39  $config = ObjectFactory::getInstance('configuration');
40 
41  // try to receive the user with given credentials
42  $user = $this->_principalFactory->getUser($login, true);
43 
44  // check if user exists
45  $loginOk = false;
46  if ($user != null) {
47  // check password
48  $loginOk = $user->verifyPassword($password, $user->getPassword());
49  if ($loginOk) {
50  // load user config initially
51  $userConfig = $user->getConfig();
52  if (strlen($userConfig) > 0) {
53  $config->addConfiguration($userConfig);
54  }
55  return $user;
56  }
57  }
58  return null;
59  }
60 }
61 ?>
AuthenticationManager implementations are used to handle all authentication requests.
DefaultAuthenticationManager uses PrincipalFactory to get a User instance that matches the given logi...
static getInstance($name, $dynamicConfiguration=array())
PrincipalFactory implementations are used to retrieve User and Role instances.
__construct(PrincipalFactory $principalFactory)
Constructor.