2013-06-07 11:44:37 +02:00
|
|
|
<?php
|
2013-06-10 17:03:01 +02:00
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
2013-06-07 11:44:37 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Icinga Authentication User class
|
|
|
|
*
|
|
|
|
* @package Icinga\Authentication
|
|
|
|
*/
|
|
|
|
namespace Icinga\Authentication;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This class represents a user object
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @copyright Copyright (c) 2013 Icinga-Web Team <info@icinga.org>
|
|
|
|
* @author Icinga-Web Team <info@icinga.org>
|
|
|
|
* @package Icinga\Application
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU General Public License
|
|
|
|
*/
|
2013-06-10 13:28:54 +02:00
|
|
|
class User
|
2013-06-07 11:44:37 +02:00
|
|
|
{
|
2013-06-24 18:46:45 +02:00
|
|
|
public $username = "";
|
|
|
|
public $firstname = "";
|
|
|
|
public $lastname = "";
|
|
|
|
public $email = "";
|
|
|
|
public $domain = "";
|
|
|
|
public $additionalInformation = array();
|
2013-06-10 13:28:54 +02:00
|
|
|
|
2013-06-24 18:46:45 +02:00
|
|
|
public $permissions = array();
|
|
|
|
public $groups = array();
|
2013-06-10 13:28:54 +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-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;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setGroups(array $groups)
|
|
|
|
{
|
|
|
|
$this->groups = $groups;
|
2013-06-07 11:44:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function isMemberOf(Group $group)
|
|
|
|
{
|
2013-06-10 13:28:54 +02:00
|
|
|
return in_array($group, $this->groups);
|
2013-06-07 11:44:37 +02:00
|
|
|
}
|
|
|
|
|
2013-06-10 13:28:54 +02:00
|
|
|
public function getPermissions()
|
2013-06-07 11:44:37 +02:00
|
|
|
{
|
|
|
|
return $this->permissions;
|
|
|
|
}
|
|
|
|
|
2013-06-10 13:28:54 +02:00
|
|
|
public function getUsername()
|
2013-06-07 11:44:37 +02:00
|
|
|
{
|
2013-06-10 13:28:54 +02:00
|
|
|
return $this->username;
|
|
|
|
}
|
2013-06-07 11:44:37 +02:00
|
|
|
|
2013-06-10 13:28:54 +02:00
|
|
|
public function setUsername($name)
|
|
|
|
{
|
|
|
|
$this->username = $name;
|
2013-06-07 11:44:37 +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;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setFirstname($name)
|
|
|
|
{
|
|
|
|
$this->firstname = $name;
|
|
|
|
}
|
2013-06-07 11:44:37 +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-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;
|
|
|
|
}
|
2013-06-07 11:44:37 +02:00
|
|
|
|
2013-06-10 13:28:54 +02:00
|
|
|
public function getEmail()
|
|
|
|
{
|
|
|
|
return $this->email;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setEmail($mail)
|
|
|
|
{
|
|
|
|
if (filter_var($mail, FILTER_VALIDATE_EMAIL)) {
|
|
|
|
$this->mail = $mail;
|
|
|
|
} else {
|
|
|
|
throw new InvalidArgumentException("Invalid mail given for user $this->username: $mail");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setDomain($domain)
|
|
|
|
{
|
|
|
|
$this->domain = $domain;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getDomain()
|
|
|
|
{
|
|
|
|
return $this->domain;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setAdditional($key, $value)
|
|
|
|
{
|
|
|
|
$this->additionalInformation[$key] = $value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getAdditional($key)
|
|
|
|
{
|
|
|
|
if (isset($this->additionalInformation[$key])) {
|
|
|
|
return $this->additionalInformation[$key];
|
|
|
|
}
|
|
|
|
return null;
|
2013-06-07 11:44:37 +02:00
|
|
|
}
|
|
|
|
}
|