OtherSuperUserRole.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  */
12 
17 
18 /**
19  * OtherSuperUserRole matches if the user has the super user attribute
20  * and the resource is a user instance with a different login than the user.
21  *
22  * @author ingo herwig <ingo@wemove.com>
23  */
25 
26  private $initialized = false;
27  private $persistenceFacade = null;
28 
29  /**
30  * @see DynamicRole::match()
31  */
32  public function match(User $user, $resource) {
33  if ($user->isSuperUser()) {
34  $extensionRemoved = preg_replace('/\.[^\.]*?$/', '', $resource);
35  if (($oidObj = ObjectId::parse($resource)) !== null || ($oidObj = ObjectId::parse($extensionRemoved)) !== null) {
36  $this->initialize();
37  if (($obj = $this->persistenceFacade->load($oidObj)) !== null && $obj instanceof \wcmf\lib\security\principal\User) {
38  return $user->getLogin() != $obj->getLogin();
39  }
40  }
41  }
42  return false;
43  }
44 
45  private function initialize() {
46  if (!$this->initialized) {
47  $this->persistenceFacade = ObjectFactory::getInstance('persistenceFacade');
48  $this->initialized = true;
49  }
50  }
51 }
52 ?>
ObjectId is the unique identifier of an object.
Definition: ObjectId.php:28
static parse($oid)
Parse a serialized object id string into an ObjectId instance.
Definition: ObjectId.php:135
DynamicRole is the interface for user roles based on attributes.
Definition: DynamicRole.php:20
isSuperUser()
Check if the user is super user (can't be inactive).
static getInstance($name, $dynamicConfiguration=[])
getLogin()
Get the login of the user.
OtherSuperUserRole matches if the user has the super user attribute and the resource is a user instan...
ObjectFactory implements the service locator pattern by wrapping a Factory instance and providing sta...
User is the interface for users.
Definition: User.php:18