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;
/** /**
...@@ -20,13 +22,15 @@ class SimpleSAML_AuthMemCookie { ...@@ -20,13 +22,15 @@ class SimpleSAML_AuthMemCookie {
*/ */
private $amcConfig; private $amcConfig;
/** /**
* This function is used to retrieve the singleton instance of this class. * This function is used to retrieve the singleton instance of this class.
* *
* @return SimpleSAML_AuthMemCookie The singleton instance of this class. * @return SimpleSAML_AuthMemCookie The singleton instance of this class.
*/ */
public static function getInstance() { public static function getInstance()
if(self::$instance === NULL) { {
if (self::$instance === null) {
self::$instance = new SimpleSAML_AuthMemCookie(); self::$instance = new SimpleSAML_AuthMemCookie();
} }
...@@ -37,8 +41,9 @@ class SimpleSAML_AuthMemCookie { ...@@ -37,8 +41,9 @@ class SimpleSAML_AuthMemCookie {
/** /**
* This function implements the constructor for this class. It loads the Auth MemCookie configuration. * This function implements the constructor for this class. It loads the Auth MemCookie configuration.
*/ */
private function __construct() { private function __construct()
/* Load Auth MemCookie configuration. */ {
// load AuthMemCookie configuration
$this->amcConfig = SimpleSAML_Configuration::getConfig('authmemcookie.php'); $this->amcConfig = SimpleSAML_Configuration::getConfig('authmemcookie.php');
} }
...@@ -48,8 +53,8 @@ class SimpleSAML_AuthMemCookie { ...@@ -48,8 +53,8 @@ class SimpleSAML_AuthMemCookie {
* *
* @return string The login type which should be used for Auth MemCookie. * @return string The login type which should be used for Auth MemCookie.
*/ */
public function getAuthSource() { public function getAuthSource()
{
return $this->amcConfig->getString('authsource'); return $this->amcConfig->getString('authsource');
} }
...@@ -58,11 +63,15 @@ class SimpleSAML_AuthMemCookie { ...@@ -58,11 +63,15 @@ class SimpleSAML_AuthMemCookie {
* This function retrieves the name of the cookie from the configuration. * This function retrieves the name of the cookie from the configuration.
* *
* @return string The name of the cookie. * @return string The name of the cookie.
* @throws Exception If the value of the 'cookiename' configuration option is invalid.
*/ */
public function getCookieName() { public function getCookieName()
{
$cookieName = $this->amcConfig->getString('cookiename', 'AuthMemCookie'); $cookieName = $this->amcConfig->getString('cookiename', 'AuthMemCookie');
if (!is_string($cookieName) || strlen($cookieName) === 0) { if (!is_string($cookieName) || strlen($cookieName) === 0) {
throw new Exception('Configuration option \'cookiename\' contains an invalid value. This option should be a string.'); throw new Exception(
"Configuration option 'cookiename' contains an invalid value. This option should be a string."
);
} }
return $cookieName; return $cookieName;
...@@ -74,8 +83,9 @@ class SimpleSAML_AuthMemCookie { ...@@ -74,8 +83,9 @@ class SimpleSAML_AuthMemCookie {
* *
* @return string The name of the attribute which contains the username. * @return string The name of the attribute which contains the username.
*/ */
public function getUsernameAttr() { public function getUsernameAttr()
$usernameAttr = $this->amcConfig->getString('username', NULL); {
$usernameAttr = $this->amcConfig->getString('username', null);
return $usernameAttr; return $usernameAttr;
} }
...@@ -86,8 +96,9 @@ class SimpleSAML_AuthMemCookie { ...@@ -86,8 +96,9 @@ class SimpleSAML_AuthMemCookie {
* *
* @return string The name of the attribute which contains the groups. * @return string The name of the attribute which contains the groups.
*/ */
public function getGroupsAttr() { public function getGroupsAttr()
$groupsAttr = $this->amcConfig->getString('groups', NULL); {
$groupsAttr = $this->amcConfig->getString('groups', null);
return $groupsAttr; return $groupsAttr;
} }
...@@ -98,8 +109,8 @@ class SimpleSAML_AuthMemCookie { ...@@ -98,8 +109,8 @@ class SimpleSAML_AuthMemCookie {
* *
* @return Memcache A Memcache object initialized from our configuration. * @return Memcache A Memcache object initialized from our configuration.
*/ */
public function getMemcache() { public function getMemcache()
{
$memcacheHost = $this->amcConfig->getString('memcache.host', '127.0.0.1'); $memcacheHost = $this->amcConfig->getString('memcache.host', '127.0.0.1');
$memcachePort = $this->amcConfig->getInteger('memcache.port', 11211); $memcachePort = $this->amcConfig->getInteger('memcache.port', 11211);
...@@ -116,31 +127,32 @@ class SimpleSAML_AuthMemCookie { ...@@ -116,31 +127,32 @@ class SimpleSAML_AuthMemCookie {
/** /**
* This function logs the user out by deleting the session information from memcache. * This function logs the user out by deleting the session information from memcache.
*/ */
private function doLogout() { private function doLogout()
{
$cookieName = $this->getCookieName(); $cookieName = $this->getCookieName();
/* Check if we have a valid cookie. */ // check if we have a valid cookie
if (!array_key_exists($cookieName, $_COOKIE)) { if (!array_key_exists($cookieName, $_COOKIE)) {
return; return;
} }
$sessionID = $_COOKIE[$cookieName]; $sessionID = $_COOKIE[$cookieName];
/* Delete the session from memcache. */ // delete the session from memcache
$memcache = $this->getMemcache(); $memcache = $this->getMemcache();
$memcache->delete($sessionID); $memcache->delete($sessionID);
/* Delete the session cookie. */ // delete the session cookie
$sessionHandler = SimpleSAML_SessionHandler::getSessionHandler(); $sessionHandler = SimpleSAML_SessionHandler::getSessionHandler();
$sessionHandler->setCookie($cookieName, NULL); $sessionHandler->setCookie($cookieName, null);
} }
/** /**
* This function implements the logout handler. It deletes the information from Memcache. * This function implements the logout handler. It deletes the information from Memcache.
*/ */
public static function logoutHandler() { public static function logoutHandler()
{
self::getInstance()->doLogout(); self::getInstance()->doLogout();
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment