ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
AuthMemCookie.php
Go to the documentation of this file.
1 <?php
2 
3 
14 {
15 
19  private static $instance = null;
20 
21 
25  private $amcConfig;
26 
27 
33  public static function getInstance()
34  {
35  if (self::$instance === null) {
36  self::$instance = new SimpleSAML_AuthMemCookie();
37  }
38 
39  return self::$instance;
40  }
41 
42 
46  private function __construct()
47  {
48  // load AuthMemCookie configuration
49  $this->amcConfig = SimpleSAML_Configuration::getConfig('authmemcookie.php');
50  }
51 
52 
58  public function getAuthSource()
59  {
60  return $this->amcConfig->getString('authsource');
61  }
62 
63 
70  public function getCookieName()
71  {
72  $cookieName = $this->amcConfig->getString('cookiename', 'AuthMemCookie');
73  if (!is_string($cookieName) || strlen($cookieName) === 0) {
74  throw new Exception(
75  "Configuration option 'cookiename' contains an invalid value. This option should be a string."
76  );
77  }
78 
79  return $cookieName;
80  }
81 
82 
88  public function getUsernameAttr()
89  {
90  $usernameAttr = $this->amcConfig->getString('username', null);
91 
92  return $usernameAttr;
93  }
94 
95 
101  public function getGroupsAttr()
102  {
103  $groupsAttr = $this->amcConfig->getString('groups', null);
104 
105  return $groupsAttr;
106  }
107 
108 
115  public function getMemcache()
116  {
117  $memcacheHost = $this->amcConfig->getString('memcache.host', '127.0.0.1');
118  $memcachePort = $this->amcConfig->getInteger('memcache.port', 11211);
119 
120  $class = class_exists('Memcache') ? 'Memcache' : (class_exists('Memcached') ? 'Memcached' : FALSE);
121  if (!$class) {
122  throw new Exception('Missing Memcached implementation. You must install either the Memcache or Memcached extension.');
123  }
124 
125  // Create the Memcache(d) object.
126  $memcache = new $class();
127 
128  foreach (explode(',', $memcacheHost) as $memcacheHost) {
129  $memcache->addServer($memcacheHost, $memcachePort);
130  }
131 
132  return $memcache;
133  }
134 
135 
139  private function doLogout()
140  {
141  $cookieName = $this->getCookieName();
142 
143  // check if we have a valid cookie
144  if (!array_key_exists($cookieName, $_COOKIE)) {
145  return;
146  }
147 
149 
150  // delete the session from memcache
151  $memcache = $this->getMemcache();
152  $memcache->delete($sessionID);
153 
154  // delete the session cookie
156  }
157 
158 
162  public static function logoutHandler()
163  {
164  self::getInstance()->doLogout();
165  }
166 }
foreach($authData as $name=> $values) $memcache
$_COOKIE['client_id']
Definition: server.php:9
getCookieName()
This function retrieves the name of the cookie from the configuration.
$groupsAttr
__construct()
This function implements the constructor for this class.
$sessionID
getMemcache()
This function creates and initializes a Memcache object from our configuration.
static getInstance()
This function is used to retrieve the singleton instance of this class.
getAuthSource()
Retrieve the authentication source that should be used to authenticate the user.
$cookieName
static setCookie($name, $value, $params=null, $throw=true)
Set a cookie.
Definition: HTTP.php:1107
$usernameAttr
getUsernameAttr()
This function retrieves the name of the attribute which contains the username from the configuration...
static getConfig($filename='config.php', $configSet='simplesaml')
Load a configuration file from a configuration set.
getGroupsAttr()
This function retrieves the name of the attribute which contains the groups from the configuration...
doLogout()
This function logs the user out by deleting the session information from memcache.
static logoutHandler()
This function implements the logout handler.