ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
SimpleSAML\SessionHandlerCookie Class Reference
+ Inheritance diagram for SimpleSAML\SessionHandlerCookie:
+ Collaboration diagram for SimpleSAML\SessionHandlerCookie:

Public Member Functions

 newSessionId ()
 Create a new session id. More...
 
 getCookieSessionId ()
 Retrieve the session ID saved in the session cookie, if there's one. More...
 
 getSessionCookieName ()
 Retrieve the session cookie name. More...
 
 hasSessionCookie ()
 Check whether the session cookie is set. More...
 
 setCookie ($sessionName, $sessionID, array $cookieParams=null)
 Set a session cookie. More...
 
- Public Member Functions inherited from SimpleSAML\SessionHandler
 newSessionId ()
 Create a new session id. More...
 
 getCookieSessionId ()
 Retrieve the session ID saved in the session cookie, if there's one. More...
 
 getSessionCookieName ()
 Retrieve the session cookie name. More...
 
 saveSession (\SimpleSAML_Session $session)
 Save the session. More...
 
 loadSession ($sessionId=null)
 Load the session. More...
 
 setCookie ($sessionName, $sessionID, array $cookieParams=null)
 Set a session cookie. More...
 
 hasSessionCookie ()
 Check whether the session cookie is set. More...
 
 getCookieParams ()
 Get the cookie parameters that should be used for session cookies. More...
 

Protected Member Functions

 __construct ()
 This constructor initializes the session id based on what we receive in a cookie. More...
 
- Protected Member Functions inherited from SimpleSAML\SessionHandler
 __construct ()
 This constructor is included in case it is needed in the future. More...
 

Protected Attributes

 $cookie_name
 

Static Private Member Functions

static createSessionID ()
 This static function creates a session id. More...
 
static isValidSessionID ($session_id)
 This static function validates a session id. More...
 

Private Attributes

 $session_id = null
 

Additional Inherited Members

- Static Public Member Functions inherited from SimpleSAML\SessionHandler
static getSessionHandler ()
 This function retrieves the current instance of the session handler. More...
 
- Static Protected Attributes inherited from SimpleSAML\SessionHandler
static $sessionHandler = null
 

Detailed Description

Definition at line 19 of file SessionHandlerCookie.php.

Constructor & Destructor Documentation

◆ __construct()

SimpleSAML\SessionHandlerCookie::__construct ( )
protected

This constructor initializes the session id based on what we receive in a cookie.

We create a new session id and set a cookie with this id if we don't have a session id.

Definition at line 42 of file SessionHandlerCookie.php.

References $config, and SimpleSAML_Configuration\getInstance().

43  {
44  // call the constructor in the base class in case it should become necessary in the future
45  parent::__construct();
46 
48  $this->cookie_name = $config->getString('session.cookie.name', 'SimpleSAMLSessionID');
49  }
static getInstance($instancename='simplesaml')
Get a configuration file by its instance name.
+ Here is the call graph for this function:

Member Function Documentation

◆ createSessionID()

static SimpleSAML\SessionHandlerCookie::createSessionID ( )
staticprivate

This static function creates a session id.

A session id consists of 32 random hexadecimal characters.

Returns
string A random session id.

Definition at line 106 of file SessionHandlerCookie.php.

107  {
108  return bin2hex(openssl_random_pseudo_bytes(16));
109  }

◆ getCookieSessionId()

SimpleSAML\SessionHandlerCookie::getCookieSessionId ( )

Retrieve the session ID saved in the session cookie, if there's one.

Returns
string|null The session id saved in the cookie or null if no session cookie was set.

Definition at line 71 of file SessionHandlerCookie.php.

References $_COOKIE.

72  {
73  if ($this->session_id === null) {
74  if (self::hasSessionCookie()) {
75  // attempt to retrieve the session id from the cookie
76  $this->session_id = $_COOKIE[$this->cookie_name];
77  }
78 
79  // check if we have a valid session id
80  if (!self::isValidSessionID($this->session_id)) {
81  // invalid, disregard this session
82  return null;
83  }
84  }
85 
86  return $this->session_id;
87  }
$_COOKIE['client_id']
Definition: server.php:9

◆ getSessionCookieName()

SimpleSAML\SessionHandlerCookie::getSessionCookieName ( )

Retrieve the session cookie name.

Returns
string The session cookie name.

Definition at line 95 of file SessionHandlerCookie.php.

◆ hasSessionCookie()

SimpleSAML\SessionHandlerCookie::hasSessionCookie ( )

Check whether the session cookie is set.

This function will only return false if is is certain that the cookie isn't set.

Returns
boolean True if it was set, false otherwise.

Definition at line 145 of file SessionHandlerCookie.php.

References $_COOKIE.

146  {
147  return array_key_exists($this->cookie_name, $_COOKIE);
148  }
$_COOKIE['client_id']
Definition: server.php:9

◆ isValidSessionID()

static SimpleSAML\SessionHandlerCookie::isValidSessionID (   $session_id)
staticprivate

This static function validates a session id.

A session id is valid if it only consists of characters which are allowed in a session id and it is the correct length.

Parameters
string$session_idThe session ID we should validate.
Returns
boolean True if this session ID is valid, false otherwise.

Definition at line 120 of file SessionHandlerCookie.php.

121  {
122  if (!is_string($session_id)) {
123  return false;
124  }
125 
126  if (strlen($session_id) != 32) {
127  return false;
128  }
129 
130  if (preg_match('/[^0-9a-f]/', $session_id)) {
131  return false;
132  }
133 
134  return true;
135  }

◆ newSessionId()

SimpleSAML\SessionHandlerCookie::newSessionId ( )

Create a new session id.

Returns
string The new session id.

Definition at line 57 of file SessionHandlerCookie.php.

References SimpleSAML_Session\createSession().

58  {
59  $this->session_id = self::createSessionID();
60  \SimpleSAML_Session::createSession($this->session_id);
61 
62  return $this->session_id;
63  }
static createSession($sessionId)
Create a new session and cache it.
Definition: Session.php:418
+ Here is the call graph for this function:

◆ setCookie()

SimpleSAML\SessionHandlerCookie::setCookie (   $sessionName,
  $sessionID,
array  $cookieParams = null 
)

Set a session cookie.

Parameters
string$sessionNameThe name of the session.
string | null$sessionIDThe session ID to use. Set to null to delete the cookie.
array | null$cookieParamsAdditional parameters to use for the session cookie.
Exceptions

Definition at line 160 of file SessionHandlerCookie.php.

References $params, and $sessionID.

161  {
162  assert('is_string($sessionName)');
163  assert('is_string($sessionID) || is_null($sessionID)');
164 
165  if ($cookieParams !== null) {
166  $params = array_merge($this->getCookieParams(), $cookieParams);
167  } else {
168  $params = $this->getCookieParams();
169  }
170 
171  HTTP::setCookie($sessionName, $sessionID, $params, true);
172  }
$params
Definition: disable.php:11
$sessionID
static setCookie($name, $value, $params=null, $throw=true)
Set a cookie.
Definition: HTTP.php:1107
getCookieParams()
Get the cookie parameters that should be used for session cookies.

Field Documentation

◆ $cookie_name

SimpleSAML\SessionHandlerCookie::$cookie_name
protected

Definition at line 35 of file SessionHandlerCookie.php.

◆ $session_id

SimpleSAML\SessionHandlerCookie::$session_id = null
private

Definition at line 27 of file SessionHandlerCookie.php.


The documentation for this class was generated from the following file: