2013-06-07 11:44:37 +02:00
|
|
|
<?php
|
2016-02-08 15:41:00 +01:00
|
|
|
/* Icinga Web 2 | (c) 2013 Icinga Development Team | GPLv2+ */
|
2013-06-07 11:44:37 +02:00
|
|
|
|
2013-07-26 15:58:16 +02:00
|
|
|
namespace Icinga;
|
|
|
|
|
2014-04-22 09:43:53 +02:00
|
|
|
use DateTimeZone;
|
|
|
|
use InvalidArgumentException;
|
2015-09-07 12:19:54 +02:00
|
|
|
use Icinga\Application\Config;
|
2016-03-24 15:30:07 +01:00
|
|
|
use Icinga\Authentication\Role;
|
2017-06-07 15:36:19 +02:00
|
|
|
use Icinga\Exception\ProgrammingError;
|
2014-01-22 14:06:59 +01:00
|
|
|
use Icinga\User\Preferences;
|
2015-09-07 12:19:54 +02:00
|
|
|
use Icinga\Web\Navigation\Navigation;
|
2013-11-20 19:10:38 +01:00
|
|
|
|
2013-06-07 11:44:37 +02:00
|
|
|
/**
|
2013-07-26 15:58:16 +02:00
|
|
|
* This class represents an authorized user
|
|
|
|
*
|
2014-04-22 09:43:53 +02:00
|
|
|
* You can retrieve authorization information (@TODO: Not implemented yet) or user information
|
2013-06-07 11:44:37 +02:00
|
|
|
*/
|
2013-06-10 13:28:54 +02:00
|
|
|
class User
|
2013-06-07 11:44:37 +02:00
|
|
|
{
|
2013-07-26 15:58:16 +02:00
|
|
|
/**
|
|
|
|
* Firstname
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2014-04-22 09:43:53 +02:00
|
|
|
protected $firstname;
|
2013-07-26 15:58:16 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Lastname
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2014-04-22 09:43:53 +02:00
|
|
|
protected $lastname;
|
2013-07-26 15:58:16 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Users email address
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2014-04-22 09:43:53 +02:00
|
|
|
protected $email;
|
2013-07-26 15:58:16 +02:00
|
|
|
|
2017-05-31 18:11:37 +02:00
|
|
|
/**
|
|
|
|
* {@link username} without {@link domain}
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $localUsername;
|
|
|
|
|
2013-07-26 15:58:16 +02:00
|
|
|
/**
|
|
|
|
* Domain
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2014-04-22 09:43:53 +02:00
|
|
|
protected $domain;
|
2013-07-26 15:58:16 +02:00
|
|
|
|
|
|
|
/**
|
2014-04-22 09:43:53 +02:00
|
|
|
* More information about this user
|
2013-07-26 15:58:16 +02:00
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2014-04-22 09:43:53 +02:00
|
|
|
protected $additionalInformation = array();
|
2013-07-26 15:58:16 +02:00
|
|
|
|
2014-07-30 12:35:55 +02:00
|
|
|
/**
|
2015-07-29 15:46:53 +02:00
|
|
|
* Information if the user is externally authenticated
|
2014-07-30 12:35:55 +02:00
|
|
|
*
|
|
|
|
* Keys:
|
|
|
|
*
|
|
|
|
* 0: origin username
|
|
|
|
* 1: origin field name
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2015-07-29 15:44:32 +02:00
|
|
|
protected $externalUserInformation = array();
|
2014-07-30 12:35:55 +02:00
|
|
|
|
2013-07-26 15:58:16 +02:00
|
|
|
/**
|
|
|
|
* Set of permissions
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2014-04-22 09:43:53 +02:00
|
|
|
protected $permissions = array();
|
2013-07-26 15:58:16 +02:00
|
|
|
|
2014-01-22 14:06:59 +01:00
|
|
|
/**
|
|
|
|
* Set of restrictions
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2014-04-22 09:43:53 +02:00
|
|
|
protected $restrictions = array();
|
2014-01-22 14:06:59 +01:00
|
|
|
|
2013-07-26 15:58:16 +02:00
|
|
|
/**
|
|
|
|
* Groups for this user
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2014-04-22 09:43:53 +02:00
|
|
|
protected $groups = array();
|
2013-07-26 15:58:16 +02:00
|
|
|
|
2016-03-24 16:34:32 +01:00
|
|
|
/**
|
|
|
|
* Roles of this user
|
|
|
|
*
|
|
|
|
* @var Role[]
|
|
|
|
*/
|
|
|
|
protected $roles = array();
|
|
|
|
|
2013-07-26 15:58:16 +02:00
|
|
|
/**
|
|
|
|
* Preferences object
|
|
|
|
*
|
|
|
|
* @var Preferences
|
|
|
|
*/
|
2014-04-22 09:43:53 +02:00
|
|
|
protected $preferences;
|
2013-07-26 15:58:16 +02:00
|
|
|
|
2015-07-30 09:31:58 +02:00
|
|
|
/**
|
|
|
|
* Whether the user is authenticated using a HTTP authentication mechanism
|
|
|
|
*
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
protected $isHttpUser = false;
|
|
|
|
|
2013-07-26 15:58:16 +02:00
|
|
|
/**
|
|
|
|
* Creates a user object given the provided information
|
|
|
|
*
|
2014-04-22 09:43:53 +02:00
|
|
|
* @param string $username
|
|
|
|
* @param string $firstname
|
|
|
|
* @param string $lastname
|
|
|
|
* @param string $email
|
2013-07-26 15:58:16 +02:00
|
|
|
*/
|
2013-06-11 13:53:42 +02:00
|
|
|
public function __construct($username, $firstname = null, $lastname = null, $email = null)
|
2013-06-10 13:28:54 +02:00
|
|
|
{
|
|
|
|
$this->setUsername($username);
|
2013-06-11 13:53:42 +02:00
|
|
|
|
|
|
|
if ($firstname !== null) {
|
|
|
|
$this->setFirstname($firstname);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($lastname !== null) {
|
|
|
|
$this->setLastname($lastname);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($email !== null) {
|
|
|
|
$this->setEmail($email);
|
|
|
|
}
|
2013-06-07 11:44:37 +02:00
|
|
|
}
|
|
|
|
|
2013-06-27 15:18:24 +02:00
|
|
|
/**
|
2013-07-26 15:58:16 +02:00
|
|
|
* Setter for preferences
|
|
|
|
*
|
2014-04-22 09:43:53 +02:00
|
|
|
* @param Preferences $preferences
|
2017-07-31 15:21:54 +02:00
|
|
|
*
|
|
|
|
* @return $this
|
2013-07-26 15:58:16 +02:00
|
|
|
*/
|
|
|
|
public function setPreferences(Preferences $preferences)
|
|
|
|
{
|
|
|
|
$this->preferences = $preferences;
|
2017-07-31 15:21:54 +02:00
|
|
|
return $this;
|
2013-07-26 15:58:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Getter for preferences
|
|
|
|
*
|
2014-04-22 09:43:53 +02:00
|
|
|
* @return Preferences
|
2013-07-26 15:58:16 +02:00
|
|
|
*/
|
|
|
|
public function getPreferences()
|
|
|
|
{
|
2014-03-04 11:14:20 +01:00
|
|
|
if ($this->preferences === null) {
|
|
|
|
$this->preferences = new Preferences();
|
|
|
|
}
|
2014-04-22 09:43:53 +02:00
|
|
|
|
2013-07-26 15:58:16 +02:00
|
|
|
return $this->preferences;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-07-30 10:47:50 +02:00
|
|
|
* Return all groups this user belongs to
|
2013-07-26 15:58:16 +02:00
|
|
|
*
|
2014-04-22 09:43:53 +02:00
|
|
|
* @return array
|
2013-07-26 15:58:16 +02:00
|
|
|
*/
|
2013-06-10 13:28:54 +02:00
|
|
|
public function getGroups()
|
2013-06-07 11:44:37 +02:00
|
|
|
{
|
2013-06-10 13:28:54 +02:00
|
|
|
return $this->groups;
|
|
|
|
}
|
|
|
|
|
2013-06-27 15:18:24 +02:00
|
|
|
/**
|
2013-07-30 10:47:50 +02:00
|
|
|
* Set the groups this user belongs to
|
2014-04-22 09:43:53 +02:00
|
|
|
*
|
|
|
|
* @param array $groups
|
2017-07-31 15:21:54 +02:00
|
|
|
*
|
|
|
|
* @return $this
|
2013-07-26 15:58:16 +02:00
|
|
|
*/
|
2013-06-10 13:28:54 +02:00
|
|
|
public function setGroups(array $groups)
|
|
|
|
{
|
|
|
|
$this->groups = $groups;
|
2017-07-31 15:21:54 +02:00
|
|
|
return $this;
|
2013-06-07 11:44:37 +02:00
|
|
|
}
|
2013-07-26 15:58:16 +02:00
|
|
|
|
2013-06-27 15:18:24 +02:00
|
|
|
/**
|
2013-07-30 10:47:50 +02:00
|
|
|
* Return true if the user is a member of this group
|
2013-07-26 15:58:16 +02:00
|
|
|
*
|
2014-04-22 09:43:53 +02:00
|
|
|
* @param string $group
|
|
|
|
*
|
|
|
|
* @return boolean
|
2013-07-26 15:58:16 +02:00
|
|
|
*/
|
|
|
|
public function isMemberOf($group)
|
2013-06-07 11:44:37 +02:00
|
|
|
{
|
2013-06-10 13:28:54 +02:00
|
|
|
return in_array($group, $this->groups);
|
2013-06-07 11:44:37 +02:00
|
|
|
}
|
|
|
|
|
2013-06-27 15:18:24 +02:00
|
|
|
/**
|
2014-09-18 14:37:18 +02:00
|
|
|
* Get the user's permissions
|
2013-07-26 15:58:16 +02:00
|
|
|
*
|
2014-09-18 14:37:18 +02:00
|
|
|
* @return array
|
2013-07-26 15:58:16 +02:00
|
|
|
*/
|
2013-06-10 13:28:54 +02:00
|
|
|
public function getPermissions()
|
2013-06-07 11:44:37 +02:00
|
|
|
{
|
|
|
|
return $this->permissions;
|
|
|
|
}
|
|
|
|
|
2014-02-12 17:01:11 +01:00
|
|
|
/**
|
2014-09-18 14:37:18 +02:00
|
|
|
* Set the user's permissions
|
|
|
|
*
|
|
|
|
* @param array $permissions
|
2014-02-12 17:01:11 +01:00
|
|
|
*
|
2014-09-18 14:37:18 +02:00
|
|
|
* @return $this
|
2014-02-12 17:01:11 +01:00
|
|
|
*/
|
|
|
|
public function setPermissions(array $permissions)
|
|
|
|
{
|
2014-09-30 15:50:58 +02:00
|
|
|
if (! empty($permissions)) {
|
2015-01-22 15:20:19 +01:00
|
|
|
natcasesort($permissions);
|
2014-09-30 15:50:58 +02:00
|
|
|
$this->permissions = array_combine($permissions, $permissions);
|
|
|
|
}
|
2014-09-18 14:37:18 +02:00
|
|
|
return $this;
|
2014-02-12 17:01:11 +01:00
|
|
|
}
|
|
|
|
|
2014-01-22 14:06:59 +01:00
|
|
|
/**
|
|
|
|
* Return restriction information for this user
|
|
|
|
*
|
2014-02-12 17:01:11 +01:00
|
|
|
* @param string $name
|
2014-04-22 09:43:53 +02:00
|
|
|
*
|
2014-02-12 17:01:11 +01:00
|
|
|
* @return array
|
2014-01-22 14:06:59 +01:00
|
|
|
*/
|
|
|
|
public function getRestrictions($name)
|
|
|
|
{
|
|
|
|
if (array_key_exists($name, $this->restrictions)) {
|
|
|
|
return $this->restrictions[$name];
|
|
|
|
}
|
2014-04-22 09:43:53 +02:00
|
|
|
|
2014-01-22 14:06:59 +01:00
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
2014-02-12 17:01:11 +01:00
|
|
|
/**
|
2016-03-29 11:18:36 +02:00
|
|
|
* Set the user's restrictions
|
2014-02-12 17:01:11 +01:00
|
|
|
*
|
2016-03-29 11:18:36 +02:00
|
|
|
* @param string[] $restrictions
|
|
|
|
*
|
|
|
|
* @return $this
|
2014-02-12 17:01:11 +01:00
|
|
|
*/
|
|
|
|
public function setRestrictions(array $restrictions)
|
|
|
|
{
|
|
|
|
$this->restrictions = $restrictions;
|
2016-03-29 11:18:36 +02:00
|
|
|
return $this;
|
2014-02-12 17:01:11 +01:00
|
|
|
}
|
|
|
|
|
2016-03-24 15:30:07 +01:00
|
|
|
/**
|
|
|
|
* Get the roles of the user
|
|
|
|
*
|
|
|
|
* @return Role[]
|
|
|
|
*/
|
|
|
|
public function getRoles()
|
|
|
|
{
|
|
|
|
return $this->roles;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the roles of the user
|
|
|
|
*
|
|
|
|
* @param Role[] $roles
|
|
|
|
*
|
|
|
|
* @return $this
|
|
|
|
*/
|
|
|
|
public function setRoles(array $roles)
|
|
|
|
{
|
|
|
|
$this->roles = $roles;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-06-27 15:18:24 +02:00
|
|
|
/**
|
2013-07-26 15:58:16 +02:00
|
|
|
* Getter for username
|
|
|
|
*
|
2014-04-22 09:43:53 +02:00
|
|
|
* @return string
|
2013-07-26 15:58:16 +02:00
|
|
|
*/
|
2013-06-10 13:28:54 +02:00
|
|
|
public function getUsername()
|
2013-06-07 11:44:37 +02:00
|
|
|
{
|
2017-05-31 18:11:37 +02:00
|
|
|
return $this->domain === null ? $this->localUsername : $this->localUsername . '@' . $this->domain;
|
2013-06-10 13:28:54 +02:00
|
|
|
}
|
2013-06-07 11:44:37 +02:00
|
|
|
|
2013-06-27 15:18:24 +02:00
|
|
|
/**
|
2013-07-26 15:58:16 +02:00
|
|
|
* Setter for username
|
|
|
|
*
|
2014-04-22 09:43:53 +02:00
|
|
|
* @param string $name
|
2017-07-31 15:21:54 +02:00
|
|
|
*
|
|
|
|
* @return $this
|
2013-07-26 15:58:16 +02:00
|
|
|
*/
|
2013-06-10 13:28:54 +02:00
|
|
|
public function setUsername($name)
|
|
|
|
{
|
2017-05-31 18:11:37 +02:00
|
|
|
$parts = explode('\\', $name, 2);
|
|
|
|
if (count($parts) === 2) {
|
|
|
|
list($this->domain, $this->localUsername) = $parts;
|
|
|
|
} else {
|
|
|
|
$parts = explode('@', $name, 2);
|
|
|
|
if (count($parts) === 2) {
|
|
|
|
list($this->localUsername, $this->domain) = $parts;
|
|
|
|
} else {
|
|
|
|
$this->localUsername = $name;
|
|
|
|
$this->domain = null;
|
|
|
|
}
|
|
|
|
}
|
2017-07-31 15:21:54 +02:00
|
|
|
|
|
|
|
return $this;
|
2013-06-07 11:44:37 +02:00
|
|
|
}
|
|
|
|
|
2013-06-27 15:18:24 +02:00
|
|
|
/**
|
2013-07-26 15:58:16 +02:00
|
|
|
* Getter for firstname
|
|
|
|
*
|
2014-04-22 09:43:53 +02:00
|
|
|
* @return string
|
2013-07-26 15:58:16 +02:00
|
|
|
*/
|
2013-06-10 13:28:54 +02:00
|
|
|
public function getFirstname()
|
2013-06-07 11:44:37 +02:00
|
|
|
{
|
2013-06-10 13:28:54 +02:00
|
|
|
return $this->firstname;
|
|
|
|
}
|
|
|
|
|
2013-07-26 15:58:16 +02:00
|
|
|
/**
|
|
|
|
* Setter for firstname
|
|
|
|
*
|
2014-04-22 09:43:53 +02:00
|
|
|
* @param string $name
|
2017-07-31 15:21:54 +02:00
|
|
|
*
|
|
|
|
* @return $this
|
2013-07-26 15:58:16 +02:00
|
|
|
*/
|
2013-06-10 13:28:54 +02:00
|
|
|
public function setFirstname($name)
|
|
|
|
{
|
|
|
|
$this->firstname = $name;
|
2017-07-31 15:21:54 +02:00
|
|
|
return $this;
|
2013-06-10 13:28:54 +02:00
|
|
|
}
|
2013-06-07 11:44:37 +02:00
|
|
|
|
2013-06-27 15:18:24 +02:00
|
|
|
/**
|
2013-07-26 15:58:16 +02:00
|
|
|
* Getter for lastname
|
|
|
|
*
|
2014-04-22 09:43:53 +02:00
|
|
|
* @return string
|
2013-07-26 15:58:16 +02:00
|
|
|
*/
|
2013-06-10 13:28:54 +02:00
|
|
|
public function getLastname()
|
|
|
|
{
|
|
|
|
return $this->lastname;
|
2013-06-07 11:44:37 +02:00
|
|
|
}
|
|
|
|
|
2013-06-27 15:18:24 +02:00
|
|
|
/**
|
2013-07-26 15:58:16 +02:00
|
|
|
* Setter for lastname
|
|
|
|
*
|
2014-04-22 09:43:53 +02:00
|
|
|
* @param string $name
|
2017-07-31 15:21:54 +02:00
|
|
|
*
|
|
|
|
* @return $this
|
2013-07-26 15:58:16 +02:00
|
|
|
*/
|
2013-06-10 13:28:54 +02:00
|
|
|
public function setLastname($name)
|
2013-06-07 11:44:37 +02:00
|
|
|
{
|
2013-06-10 13:28:54 +02:00
|
|
|
$this->lastname = $name;
|
2017-07-31 15:21:54 +02:00
|
|
|
return $this;
|
2013-06-10 13:28:54 +02:00
|
|
|
}
|
2013-06-07 11:44:37 +02:00
|
|
|
|
2013-06-27 15:18:24 +02:00
|
|
|
/**
|
2013-07-26 15:58:16 +02:00
|
|
|
* Getter for email
|
|
|
|
*
|
2014-04-22 09:43:53 +02:00
|
|
|
* @return string
|
2013-07-26 15:58:16 +02:00
|
|
|
*/
|
2013-06-10 13:28:54 +02:00
|
|
|
public function getEmail()
|
|
|
|
{
|
|
|
|
return $this->email;
|
|
|
|
}
|
2013-07-26 15:58:16 +02:00
|
|
|
|
2013-06-27 15:18:24 +02:00
|
|
|
/**
|
2013-07-26 15:58:16 +02:00
|
|
|
* Setter for mail
|
|
|
|
*
|
2014-04-22 09:43:53 +02:00
|
|
|
* @param string $mail
|
|
|
|
*
|
2017-07-31 15:21:54 +02:00
|
|
|
* @return $this
|
|
|
|
*
|
2014-04-22 09:43:53 +02:00
|
|
|
* @throws InvalidArgumentException When an invalid mail is provided
|
2013-07-26 15:58:16 +02:00
|
|
|
*/
|
2013-06-10 13:28:54 +02:00
|
|
|
public function setEmail($mail)
|
|
|
|
{
|
2017-07-31 15:21:54 +02:00
|
|
|
if ($mail !== null && !filter_var($mail, FILTER_VALIDATE_EMAIL)) {
|
|
|
|
throw new InvalidArgumentException(
|
|
|
|
sprintf('Invalid mail given for user %s: %s', $this->getUsername(), $mail)
|
|
|
|
);
|
2013-06-10 13:28:54 +02:00
|
|
|
}
|
2017-07-31 15:21:54 +02:00
|
|
|
|
|
|
|
$this->email = $mail;
|
|
|
|
return $this;
|
2013-06-10 13:28:54 +02:00
|
|
|
}
|
2013-07-26 15:58:16 +02:00
|
|
|
|
2013-06-27 15:18:24 +02:00
|
|
|
/**
|
2017-06-07 15:36:19 +02:00
|
|
|
* Set the domain
|
2013-07-26 15:58:16 +02:00
|
|
|
*
|
2014-04-22 09:43:53 +02:00
|
|
|
* @param string $domain
|
2017-06-07 15:36:19 +02:00
|
|
|
*
|
|
|
|
* @return $this
|
2013-07-26 15:58:16 +02:00
|
|
|
*/
|
2013-06-10 13:28:54 +02:00
|
|
|
public function setDomain($domain)
|
|
|
|
{
|
2017-07-11 16:56:35 +02:00
|
|
|
$domain = trim($domain);
|
|
|
|
|
|
|
|
if (strlen($domain)) {
|
|
|
|
$this->domain = $domain;
|
|
|
|
}
|
2017-06-07 15:36:19 +02:00
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get whether the user has a domain
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function hasDomain()
|
|
|
|
{
|
|
|
|
return $this->domain !== null;
|
2013-06-10 13:28:54 +02:00
|
|
|
}
|
|
|
|
|
2013-06-27 15:18:24 +02:00
|
|
|
/**
|
2017-06-07 15:36:19 +02:00
|
|
|
* Get the domain
|
2013-07-26 15:58:16 +02:00
|
|
|
*
|
2014-04-22 09:43:53 +02:00
|
|
|
* @return string
|
2017-06-07 15:36:19 +02:00
|
|
|
*
|
|
|
|
* @throws ProgrammingError If the user does not have a domain
|
2013-07-26 15:58:16 +02:00
|
|
|
*/
|
2013-06-10 13:28:54 +02:00
|
|
|
public function getDomain()
|
|
|
|
{
|
2017-06-07 15:36:19 +02:00
|
|
|
if ($this->domain === null) {
|
|
|
|
throw new ProgrammingError(
|
|
|
|
'User does not have a domain.'
|
|
|
|
. ' Use User::hasDomain() to check whether the user has a domain beforehand.'
|
|
|
|
);
|
|
|
|
}
|
2013-06-10 13:28:54 +02:00
|
|
|
return $this->domain;
|
|
|
|
}
|
|
|
|
|
2017-05-31 18:11:37 +02:00
|
|
|
/**
|
|
|
|
* Get the local username, ie. the username without its domain
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getLocalUsername()
|
|
|
|
{
|
|
|
|
return $this->localUsername;
|
|
|
|
}
|
2014-01-22 14:06:59 +01:00
|
|
|
|
2013-06-27 15:18:24 +02:00
|
|
|
/**
|
2013-07-30 10:47:50 +02:00
|
|
|
* Set additional information about user
|
2013-07-26 15:58:16 +02:00
|
|
|
*
|
2014-04-22 09:43:53 +02:00
|
|
|
* @param string $key
|
|
|
|
* @param string $value
|
2017-07-31 15:21:54 +02:00
|
|
|
*
|
|
|
|
* @return $this
|
2013-07-26 15:58:16 +02:00
|
|
|
*/
|
2013-06-10 13:28:54 +02:00
|
|
|
public function setAdditional($key, $value)
|
|
|
|
{
|
|
|
|
$this->additionalInformation[$key] = $value;
|
2017-07-31 15:21:54 +02:00
|
|
|
return $this;
|
2013-06-10 13:28:54 +02:00
|
|
|
}
|
|
|
|
|
2013-06-27 15:18:24 +02:00
|
|
|
/**
|
2013-07-26 15:58:16 +02:00
|
|
|
* Getter for additional information
|
|
|
|
*
|
2014-04-22 09:43:53 +02:00
|
|
|
* @param string $key
|
|
|
|
* @return mixed|null
|
2013-07-26 15:58:16 +02:00
|
|
|
*/
|
2013-06-10 13:28:54 +02:00
|
|
|
public function getAdditional($key)
|
|
|
|
{
|
|
|
|
if (isset($this->additionalInformation[$key])) {
|
|
|
|
return $this->additionalInformation[$key];
|
|
|
|
}
|
2014-04-22 09:43:53 +02:00
|
|
|
|
2013-06-10 13:28:54 +02:00
|
|
|
return null;
|
2013-06-07 11:44:37 +02:00
|
|
|
}
|
2013-08-06 18:02:40 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve the user's timezone
|
|
|
|
*
|
2013-08-07 17:12:57 +02:00
|
|
|
* If the user did not set a timezone, the default timezone set via config.ini is returned
|
2013-08-06 18:02:40 +02:00
|
|
|
*
|
2013-08-07 17:12:57 +02:00
|
|
|
* @return DateTimeZone
|
2013-08-06 18:02:40 +02:00
|
|
|
*/
|
2013-08-07 01:47:32 +02:00
|
|
|
public function getTimeZone()
|
2013-08-06 18:02:40 +02:00
|
|
|
{
|
|
|
|
$tz = $this->preferences->get('timezone');
|
|
|
|
if ($tz === null) {
|
|
|
|
$tz = date_default_timezone_get();
|
|
|
|
}
|
2014-04-22 09:43:53 +02:00
|
|
|
|
2013-08-07 17:12:57 +02:00
|
|
|
return new DateTimeZone($tz);
|
2013-08-06 18:02:40 +02:00
|
|
|
}
|
2013-11-20 12:01:40 +01:00
|
|
|
|
2014-07-30 12:35:55 +02:00
|
|
|
/**
|
2015-07-29 15:44:32 +02:00
|
|
|
* Set additional external user information
|
2014-07-30 12:35:55 +02:00
|
|
|
*
|
2015-07-29 15:46:53 +02:00
|
|
|
* @param string $username
|
2014-07-30 12:35:55 +02:00
|
|
|
* @param string $field
|
2017-07-31 15:21:54 +02:00
|
|
|
*
|
|
|
|
* @return $this
|
2014-07-30 12:35:55 +02:00
|
|
|
*/
|
2015-07-29 15:44:32 +02:00
|
|
|
public function setExternalUserInformation($username, $field)
|
2014-07-30 12:35:55 +02:00
|
|
|
{
|
2015-07-29 15:44:32 +02:00
|
|
|
$this->externalUserInformation = array($username, $field);
|
2017-07-31 15:21:54 +02:00
|
|
|
return $this;
|
2014-07-30 12:35:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-07-29 15:44:32 +02:00
|
|
|
* Get additional external user information
|
2014-07-30 12:35:55 +02:00
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
2015-07-29 15:44:32 +02:00
|
|
|
public function getExternalUserInformation()
|
2014-07-30 12:35:55 +02:00
|
|
|
{
|
2015-07-29 15:44:32 +02:00
|
|
|
return $this->externalUserInformation;
|
2014-07-30 12:35:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-07-29 15:44:32 +02:00
|
|
|
* Return true if user has external user information set
|
2014-07-30 12:35:55 +02:00
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
2015-07-29 15:44:32 +02:00
|
|
|
public function isExternalUser()
|
2014-07-30 12:35:55 +02:00
|
|
|
{
|
2015-07-29 15:44:32 +02:00
|
|
|
return ! empty($this->externalUserInformation);
|
2014-07-30 12:35:55 +02:00
|
|
|
}
|
2014-09-18 14:37:18 +02:00
|
|
|
|
2015-07-30 09:31:58 +02:00
|
|
|
/**
|
|
|
|
* Get whether the user is authenticated using a HTTP authentication mechanism
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function getIsHttpUser()
|
|
|
|
{
|
|
|
|
return $this->isHttpUser;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set whether the user is authenticated using a HTTP authentication mechanism
|
|
|
|
*
|
|
|
|
* @param bool $isHttpUser
|
|
|
|
*
|
|
|
|
* @return $this
|
|
|
|
*/
|
|
|
|
public function setIsHttpUser($isHttpUser = true)
|
|
|
|
{
|
|
|
|
$this->isHttpUser = (bool) $isHttpUser;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2014-09-18 14:37:18 +02:00
|
|
|
/**
|
|
|
|
* Whether the user has a given permission
|
|
|
|
*
|
2015-05-05 12:36:26 +02:00
|
|
|
* @param string $requiredPermission
|
2014-09-18 14:37:18 +02:00
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
2015-05-05 12:36:26 +02:00
|
|
|
public function can($requiredPermission)
|
2014-09-18 14:37:18 +02:00
|
|
|
{
|
2015-05-05 12:36:26 +02:00
|
|
|
if (isset($this->permissions['*']) || isset($this->permissions[$requiredPermission])) {
|
2014-09-18 14:37:18 +02:00
|
|
|
return true;
|
|
|
|
}
|
2015-08-27 14:24:04 +02:00
|
|
|
|
|
|
|
$requiredWildcard = strpos($requiredPermission, '*');
|
2015-05-05 12:36:26 +02:00
|
|
|
foreach ($this->permissions as $grantedPermission) {
|
2015-08-27 14:24:04 +02:00
|
|
|
if ($requiredWildcard !== false) {
|
|
|
|
if (($grantedWildcard = strpos($grantedPermission, '*')) !== false) {
|
|
|
|
$wildcard = min($requiredWildcard, $grantedWildcard);
|
|
|
|
} else {
|
|
|
|
$wildcard = $requiredWildcard;
|
|
|
|
}
|
2015-03-12 15:27:44 +01:00
|
|
|
} else {
|
2015-05-05 12:36:26 +02:00
|
|
|
$wildcard = strpos($grantedPermission, '*');
|
2015-03-12 15:27:44 +01:00
|
|
|
}
|
2015-08-27 14:24:04 +02:00
|
|
|
|
2014-09-18 14:37:18 +02:00
|
|
|
if ($wildcard !== false) {
|
2015-05-05 12:36:26 +02:00
|
|
|
if (substr($requiredPermission, 0, $wildcard) === substr($grantedPermission, 0, $wildcard)) {
|
2015-02-02 13:41:02 +01:00
|
|
|
return true;
|
|
|
|
}
|
2015-05-05 12:36:26 +02:00
|
|
|
} elseif ($requiredPermission === $grantedPermission) {
|
2015-02-02 13:44:54 +01:00
|
|
|
return true;
|
2014-09-18 14:37:18 +02:00
|
|
|
}
|
|
|
|
}
|
2015-08-27 14:24:04 +02:00
|
|
|
|
2014-09-18 14:37:18 +02:00
|
|
|
return false;
|
2014-07-30 12:35:55 +02:00
|
|
|
}
|
2015-09-07 12:19:54 +02:00
|
|
|
|
2015-09-07 14:01:28 +02:00
|
|
|
/**
|
|
|
|
* Load and return this user's configured navigation of the given type
|
|
|
|
*
|
|
|
|
* @param string $type
|
|
|
|
*
|
|
|
|
* @return Navigation
|
|
|
|
*/
|
|
|
|
public function getNavigation($type)
|
|
|
|
{
|
2015-09-30 11:47:38 +02:00
|
|
|
$config = Config::navigation($type === 'dashboard-pane' ? 'dashlet' : $type, $this->getUsername());
|
2015-09-07 12:19:54 +02:00
|
|
|
|
|
|
|
if ($type === 'dashboard-pane') {
|
|
|
|
$panes = array();
|
2015-09-30 11:38:14 +02:00
|
|
|
foreach ($config as $dashletName => $dashletConfig) {
|
2015-09-07 12:19:54 +02:00
|
|
|
// TODO: Throw ConfigurationError if pane or url is missing
|
|
|
|
$panes[$dashletConfig->pane][$dashletName] = $dashletConfig->url;
|
|
|
|
}
|
|
|
|
|
2015-09-17 13:40:58 +02:00
|
|
|
$navigation = new Navigation();
|
2015-09-07 12:19:54 +02:00
|
|
|
foreach ($panes as $paneName => $dashlets) {
|
|
|
|
$navigation->addItem(
|
|
|
|
$paneName,
|
|
|
|
array(
|
|
|
|
'type' => 'dashboard-pane',
|
|
|
|
'dashlets' => $dashlets
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} else {
|
2015-09-30 11:38:14 +02:00
|
|
|
$navigation = Navigation::fromConfig($config);
|
2015-09-07 12:19:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $navigation;
|
|
|
|
}
|
2013-06-07 11:44:37 +02:00
|
|
|
}
|