Skip to content
Snippets Groups Projects
Commit 13a2ca61 authored by Jaime Perez Crespo's avatar Jaime Perez Crespo
Browse files

Reformat SimpleSAML_AuthMemCookie.

parent f04f9a2b
No related branches found
No related tags found
No related merge requests found
<?php <?php
/** /**
* This is a helper class for the Auth MemCookie module. * This is a helper class for the Auth MemCookie module.
* It handles the configuration, and implements the logout handler. * It handles the configuration, and implements the logout handler.
* *
* @author Olav Morken, UNINETT AS. * @author Olav Morken, UNINETT AS.
* @package simpleSAMLphp * @package SimpleSAMLphp
*/ */
class SimpleSAML_AuthMemCookie { class SimpleSAML_AuthMemCookie
{
/**
* @var SimpleSAML_AuthMemCookie This is the singleton instance of this class. /**
*/ * @var SimpleSAML_AuthMemCookie This is the singleton instance of this class.
private static $instance = NULL; */
private static $instance = null;
/**
* @var SimpleSAML_Configuration The configuration for Auth MemCookie. /**
*/ * @var SimpleSAML_Configuration The configuration for Auth MemCookie.
private $amcConfig; */
private $amcConfig;
/**
* This function is used to retrieve the singleton instance of this class.
* /**
* @return SimpleSAML_AuthMemCookie The singleton instance of this class. * This function is used to retrieve the singleton instance of this class.
*/ *
public static function getInstance() { * @return SimpleSAML_AuthMemCookie The singleton instance of this class.
if(self::$instance === NULL) { */
self::$instance = new SimpleSAML_AuthMemCookie(); public static function getInstance()
} {
if (self::$instance === null) {
return self::$instance; self::$instance = new SimpleSAML_AuthMemCookie();
} }
return self::$instance;
/** }
* This function implements the constructor for this class. It loads the Auth MemCookie configuration.
*/
private function __construct() { /**
/* Load Auth MemCookie configuration. */ * This function implements the constructor for this class. It loads the Auth MemCookie configuration.
$this->amcConfig = SimpleSAML_Configuration::getConfig('authmemcookie.php'); */
} private function __construct()
{
// load AuthMemCookie configuration
/** $this->amcConfig = SimpleSAML_Configuration::getConfig('authmemcookie.php');
* Retrieve the authentication source that should be used to authenticate the user. }
*
* @return string The login type which should be used for Auth MemCookie.
*/ /**
public function getAuthSource() { * Retrieve the authentication source that should be used to authenticate the user.
*
return $this->amcConfig->getString('authsource'); * @return string The login type which should be used for Auth MemCookie.
} */
public function getAuthSource()
{
/** return $this->amcConfig->getString('authsource');
* This function retrieves the name of the cookie from the configuration. }
*
* @return string The name of the cookie.
*/ /**
public function getCookieName() { * This function retrieves the name of the cookie from the configuration.
$cookieName = $this->amcConfig->getString('cookiename', 'AuthMemCookie'); *
if(!is_string($cookieName) || strlen($cookieName) === 0) { * @return string The name of the cookie.
throw new Exception('Configuration option \'cookiename\' contains an invalid value. This option should be a string.'); * @throws Exception If the value of the 'cookiename' configuration option is invalid.
} */
public function getCookieName()
return $cookieName; {
} $cookieName = $this->amcConfig->getString('cookiename', 'AuthMemCookie');
if (!is_string($cookieName) || strlen($cookieName) === 0) {
throw new Exception(
/** "Configuration option 'cookiename' contains an invalid value. This option should be a string."
* This function retrieves the name of the attribute which contains the username from the configuration. );
* }
* @return string The name of the attribute which contains the username.
*/ return $cookieName;
public function getUsernameAttr() { }
$usernameAttr = $this->amcConfig->getString('username', NULL);
return $usernameAttr; /**
} * This function retrieves the name of the attribute which contains the username from the configuration.
*
* @return string The name of the attribute which contains the username.
/** */
* This function retrieves the name of the attribute which contains the groups from the configuration. public function getUsernameAttr()
* {
* @return string The name of the attribute which contains the groups. $usernameAttr = $this->amcConfig->getString('username', null);
*/
public function getGroupsAttr() { return $usernameAttr;
$groupsAttr = $this->amcConfig->getString('groups', NULL); }
return $groupsAttr;
} /**
* This function retrieves the name of the attribute which contains the groups from the configuration.
*
/** * @return string The name of the attribute which contains the groups.
* This function creates and initializes a Memcache object from our configuration. */
* public function getGroupsAttr()
* @return Memcache A Memcache object initialized from our configuration. {
*/ $groupsAttr = $this->amcConfig->getString('groups', null);
public function getMemcache() {
return $groupsAttr;
$memcacheHost = $this->amcConfig->getString('memcache.host', '127.0.0.1'); }
$memcachePort = $this->amcConfig->getInteger('memcache.port', 11211);
$memcache = new Memcache; /**
* This function creates and initializes a Memcache object from our configuration.
foreach (explode(',', $memcacheHost) as $memcacheHost) { *
$memcache->addServer($memcacheHost, $memcachePort); * @return Memcache A Memcache object initialized from our configuration.
} */
public function getMemcache()
return $memcache; {
} $memcacheHost = $this->amcConfig->getString('memcache.host', '127.0.0.1');
$memcachePort = $this->amcConfig->getInteger('memcache.port', 11211);
/** $memcache = new Memcache;
* This function logs the user out by deleting the session information from memcache.
*/ foreach (explode(',', $memcacheHost) as $memcacheHost) {
private function doLogout() { $memcache->addServer($memcacheHost, $memcachePort);
}
$cookieName = $this->getCookieName();
return $memcache;
/* Check if we have a valid cookie. */ }
if(!array_key_exists($cookieName, $_COOKIE)) {
return;
} /**
* This function logs the user out by deleting the session information from memcache.
$sessionID = $_COOKIE[$cookieName]; */
private function doLogout()
/* Delete the session from memcache. */ {
$memcache = $this->getMemcache(); $cookieName = $this->getCookieName();
$memcache->delete($sessionID);
// check if we have a valid cookie
/* Delete the session cookie. */ if (!array_key_exists($cookieName, $_COOKIE)) {
$sessionHandler = SimpleSAML_SessionHandler::getSessionHandler(); return;
$sessionHandler->setCookie($cookieName, NULL); }
}
$sessionID = $_COOKIE[$cookieName];
/** // delete the session from memcache
* This function implements the logout handler. It deletes the information from Memcache. $memcache = $this->getMemcache();
*/ $memcache->delete($sessionID);
public static function logoutHandler() {
self::getInstance()->doLogout(); // delete the session cookie
} $sessionHandler = SimpleSAML_SessionHandler::getSessionHandler();
$sessionHandler->setCookie($cookieName, null);
}
/**
* This function implements the logout handler. It deletes the information from Memcache.
*/
public static function logoutHandler()
{
self::getInstance()->doLogout();
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment