2013-06-07 11:44:37 +02:00
|
|
|
<?php
|
2013-06-10 17:03:01 +02:00
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
2013-06-28 16:47:30 +02:00
|
|
|
/**
|
|
|
|
* Icinga 2 Web - Head for multiple monitoring frontends
|
|
|
|
* Copyright (C) 2013 Icinga Development Team
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
|
|
|
* @author Icinga Development Team <info@icinga.org>
|
|
|
|
*/
|
2013-06-10 17:03:01 +02:00
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
2013-06-07 11:44:37 +02:00
|
|
|
|
|
|
|
namespace Icinga\Authentication;
|
|
|
|
|
|
|
|
/**
|
2013-06-27 15:18:24 +02:00
|
|
|
* This class represents an authorized user and can be used
|
|
|
|
* to retrieve authorization information (@TODO: Not implemented yet) or
|
|
|
|
* to retrieve 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-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-27 15:18:24 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a user object given the provided information
|
|
|
|
*
|
|
|
|
* @param String $username
|
|
|
|
* @param String $firstname
|
|
|
|
* @param String $lastname
|
|
|
|
* @param String $email
|
|
|
|
**/
|
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
|
|
|
/**
|
|
|
|
* Returns all groups this user belongs to
|
|
|
|
*
|
|
|
|
* @return Array
|
|
|
|
**/
|
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
|
|
|
/**
|
|
|
|
* Sets the groups this user belongs to
|
|
|
|
*
|
|
|
|
* @return Array
|
|
|
|
**/
|
2013-06-10 13:28:54 +02:00
|
|
|
public function setGroups(array $groups)
|
|
|
|
{
|
|
|
|
$this->groups = $groups;
|
2013-06-07 11:44:37 +02:00
|
|
|
}
|
2013-06-27 15:18:24 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if the user is a member of this group
|
|
|
|
*
|
|
|
|
* @return Boolean
|
|
|
|
**/
|
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-27 15:18:24 +02:00
|
|
|
/**
|
|
|
|
* Returns permission information for this user
|
|
|
|
*
|
|
|
|
* @return Array
|
|
|
|
**/
|
2013-06-10 13:28:54 +02:00
|
|
|
public function getPermissions()
|
2013-06-07 11:44:37 +02:00
|
|
|
{
|
|
|
|
return $this->permissions;
|
|
|
|
}
|
|
|
|
|
2013-06-27 15:18:24 +02:00
|
|
|
/**
|
|
|
|
* @return String
|
|
|
|
**/
|
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-27 15:18:24 +02:00
|
|
|
/**
|
|
|
|
* @param String $name
|
|
|
|
**/
|
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-27 15:18:24 +02:00
|
|
|
/**
|
|
|
|
* @return String
|
|
|
|
**/
|
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-06-27 15:18:24 +02:00
|
|
|
/*+
|
|
|
|
* @param String $name
|
|
|
|
**/
|
2013-06-10 13:28:54 +02:00
|
|
|
public function setFirstname($name)
|
|
|
|
{
|
|
|
|
$this->firstname = $name;
|
|
|
|
}
|
2013-06-07 11:44:37 +02:00
|
|
|
|
2013-06-27 15:18:24 +02:00
|
|
|
/**
|
|
|
|
* @return String
|
|
|
|
**/
|
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
|
|
|
/**
|
|
|
|
* @param String $name
|
|
|
|
**/
|
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-27 15:18:24 +02:00
|
|
|
/**
|
|
|
|
* @return String
|
|
|
|
**/
|
2013-06-10 13:28:54 +02:00
|
|
|
public function getEmail()
|
|
|
|
{
|
|
|
|
return $this->email;
|
|
|
|
}
|
2013-06-27 15:18:24 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param String $mail
|
|
|
|
*
|
|
|
|
* @throws \InvalidArgumentException When an invalid mail is provided
|
|
|
|
**/
|
2013-06-10 13:28:54 +02:00
|
|
|
public function setEmail($mail)
|
|
|
|
{
|
|
|
|
if (filter_var($mail, FILTER_VALIDATE_EMAIL)) {
|
|
|
|
$this->mail = $mail;
|
|
|
|
} else {
|
2013-06-27 15:18:24 +02:00
|
|
|
throw new \InvalidArgumentException("Invalid mail given for user $this->username: $mail");
|
2013-06-10 13:28:54 +02:00
|
|
|
}
|
|
|
|
}
|
2013-06-27 15:18:24 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param String $domain
|
|
|
|
**/
|
2013-06-10 13:28:54 +02:00
|
|
|
public function setDomain($domain)
|
|
|
|
{
|
|
|
|
$this->domain = $domain;
|
|
|
|
}
|
|
|
|
|
2013-06-27 15:18:24 +02:00
|
|
|
/**
|
|
|
|
* @return String
|
|
|
|
**/
|
2013-06-10 13:28:54 +02:00
|
|
|
public function getDomain()
|
|
|
|
{
|
|
|
|
return $this->domain;
|
|
|
|
}
|
|
|
|
|
2013-06-27 15:18:24 +02:00
|
|
|
/**
|
|
|
|
* @param String $key
|
|
|
|
* @param String $value
|
|
|
|
**/
|
2013-06-10 13:28:54 +02:00
|
|
|
public function setAdditional($key, $value)
|
|
|
|
{
|
|
|
|
$this->additionalInformation[$key] = $value;
|
|
|
|
}
|
|
|
|
|
2013-06-27 15:18:24 +02:00
|
|
|
/**
|
|
|
|
* @return mixed
|
|
|
|
**/
|
2013-06-10 13:28:54 +02:00
|
|
|
public function getAdditional($key)
|
|
|
|
{
|
|
|
|
if (isset($this->additionalInformation[$key])) {
|
|
|
|
return $this->additionalInformation[$key];
|
|
|
|
}
|
|
|
|
return null;
|
2013-06-07 11:44:37 +02:00
|
|
|
}
|
|
|
|
}
|