ILIAS  trunk Revision v11.0_alpha-1851-ga8564da6fed
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilAuthSession Class Reference
+ Collaboration diagram for ilAuthSession:

Public Member Functions

 init ()
 Start auth session. More...
 
 isValid ()
 Check if current session is valid (authenticated and not expired) More...
 
 regenerateId ()
 Regenerate id. More...
 
 logout ()
 Logout user => stop session. More...
 
 isAuthenticated ()
 Check if session is authenticated. More...
 
 setAuthenticated (bool $a_status, int $a_user_id)
 Set authenticated. More...
 
 isExpired ()
 Check if current is or was expired in last request. More...
 
 setExpired (bool $a_status)
 Set session expired. More...
 
 setUserId (int $a_id)
 Set authenticated user id. More...
 
 getUserId ()
 Get authenticated user id. More...
 
 getId ()
 get session id More...
 

Static Public Member Functions

static getInstance (\ilLogger $logger)
 Get instance. More...
 

Protected Member Functions

 getLogger ()
 
 validateExpiration ()
 Check expired value of session. More...
 
 setId (string $a_id)
 Set id. More...
 

Private Member Functions

 __construct (\ilLogger $logger)
 

Private Attributes

const SESSION_AUTH_AUTHENTICATED = '_authsession_authenticated'
 
const SESSION_AUTH_USER_ID = '_authsession_user_id'
 
const SESSION_AUTH_EXPIRED = '_authsession_expired'
 
ilLogger $logger
 
string $id = ''
 
int $user_id = 0
 
bool $expired = false
 
bool $authenticated = false
 

Static Private Attributes

static ilAuthSession $instance = null
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilAuthSession::__construct ( \ilLogger  $logger)
private

Definition at line 39 of file class.ilAuthSession.php.

References $logger, and ILIAS\Repository\logger().

40  {
41  $this->logger = $logger;
42  }
+ Here is the call graph for this function:

Member Function Documentation

◆ getId()

ilAuthSession::getId ( )

get session id

Definition at line 214 of file class.ilAuthSession.php.

References $id.

Referenced by regenerateId(), and validateExpiration().

214  : string
215  {
216  return $this->id;
217  }
+ Here is the caller graph for this function:

◆ getInstance()

static ilAuthSession::getInstance ( \ilLogger  $logger)
static

Get instance.

Parameters

Definition at line 49 of file class.ilAuthSession.php.

References $logger.

Referenced by ilInitialisation\initSession().

50  {
51  if (self::$instance) {
52  return self::$instance;
53  }
54  return self::$instance = new self($logger);
55  }
+ Here is the caller graph for this function:

◆ getLogger()

ilAuthSession::getLogger ( )
protected
Returns
ilLogger

Definition at line 60 of file class.ilAuthSession.php.

References $logger.

Referenced by init(), logout(), and regenerateId().

60  : ilLogger
61  {
62  return $this->logger;
63  }
+ Here is the caller graph for this function:

◆ getUserId()

ilAuthSession::getUserId ( )

Get authenticated user id.

Definition at line 181 of file class.ilAuthSession.php.

References $user_id.

Referenced by logout(), and ilAuthFrontend\migrateAccount().

181  : int
182  {
183  return $this->user_id;
184  }
+ Here is the caller graph for this function:

◆ init()

ilAuthSession::init ( )

Start auth session.

Definition at line 68 of file class.ilAuthSession.php.

References ANONYMOUS_USER_ID, ilLogLevel\ERROR, ilSession\get(), getLogger(), ILIAS\Repository\int(), setId(), setUserId(), and validateExpiration().

Referenced by logout().

68  : bool
69  {
70  if (session_status() === PHP_SESSION_ACTIVE) {
71  $this->getLogger()->error(__METHOD__ . ' called with active session.');
72  $this->getLogger()->logStack(ilLogLevel::ERROR);
73  return false;
74  }
75 
76  session_start();
77 
78  $this->setId(session_id());
79 
80  $user_id = (int) (ilSession::get(self::SESSION_AUTH_USER_ID) ?? ANONYMOUS_USER_ID);
81 
82  if ($user_id) {
83  $this->getLogger()->debug('Resuming old session for user: ' . $user_id);
84  $this->setUserId($user_id);
85  $this->expired = (bool) ilSession::get(self::SESSION_AUTH_EXPIRED);
86  $this->authenticated = (bool) ilSession::get(self::SESSION_AUTH_AUTHENTICATED);
87 
88  $this->validateExpiration();
89  } else {
90  $this->getLogger()->debug('Started new session.');
92  $this->expired = false;
93  $this->authenticated = false;
94  }
95  return true;
96  }
static get(string $a_var)
setUserId(int $a_id)
Set authenticated user id.
const ANONYMOUS_USER_ID
Definition: constants.php:27
validateExpiration()
Check expired value of session.
setId(string $a_id)
Set id.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isAuthenticated()

ilAuthSession::isAuthenticated ( )

Check if session is authenticated.

Definition at line 133 of file class.ilAuthSession.php.

References ANONYMOUS_USER_ID, and ILIAS\Repository\int().

Referenced by isValid(), and ilAuthFrontend\migrateAccount().

133  : bool
134  {
135  return $this->authenticated || $this->user_id === (int) ANONYMOUS_USER_ID;
136  }
const ANONYMOUS_USER_ID
Definition: constants.php:27
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isExpired()

ilAuthSession::isExpired ( )

Check if current is or was expired in last request.

Definition at line 156 of file class.ilAuthSession.php.

References ANONYMOUS_USER_ID, and ILIAS\Repository\int().

Referenced by isValid(), and validateExpiration().

156  : bool
157  {
158  return $this->expired && $this->user_id !== (int) ANONYMOUS_USER_ID;
159  }
const ANONYMOUS_USER_ID
Definition: constants.php:27
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isValid()

ilAuthSession::isValid ( )

Check if current session is valid (authenticated and not expired)

Definition at line 101 of file class.ilAuthSession.php.

References isAuthenticated(), and isExpired().

101  : bool
102  {
103  return !$this->isExpired() && $this->isAuthenticated();
104  }
isExpired()
Check if current is or was expired in last request.
isAuthenticated()
Check if session is authenticated.
+ Here is the call graph for this function:

◆ logout()

ilAuthSession::logout ( )

Logout user => stop session.

Definition at line 120 of file class.ilAuthSession.php.

References ANONYMOUS_USER_ID, getLogger(), getUserId(), init(), and setAuthenticated().

120  : void
121  {
122  $this->getLogger()->debug('Logout called for: ' . $this->getUserId());
123  session_regenerate_id(true);
124  session_destroy();
125 
126  $this->init();
127  $this->setAuthenticated(true, ANONYMOUS_USER_ID);
128  }
const ANONYMOUS_USER_ID
Definition: constants.php:27
getUserId()
Get authenticated user id.
init()
Start auth session.
setAuthenticated(bool $a_status, int $a_user_id)
Set authenticated.
+ Here is the call graph for this function:

◆ regenerateId()

ilAuthSession::regenerateId ( )

Regenerate id.

Definition at line 109 of file class.ilAuthSession.php.

References getId(), getLogger(), and setId().

Referenced by setAuthenticated().

109  : void
110  {
111  $old_session_id = session_id();
112  session_regenerate_id(true);
113  $this->setId(session_id());
114  $this->getLogger()->info('Session regenerate id: [' . substr($old_session_id, 0, 5) . '] -> [' . substr($this->getId(), 0, 5) . ']');
115  }
getId()
get session id
setId(string $a_id)
Set id.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setAuthenticated()

ilAuthSession::setAuthenticated ( bool  $a_status,
int  $a_user_id 
)

Set authenticated.

Definition at line 141 of file class.ilAuthSession.php.

References regenerateId(), ilSession\set(), and setExpired().

Referenced by logout().

141  : void
142  {
143  $this->authenticated = $a_status;
144  $this->user_id = $a_user_id;
145  ilSession::set(self::SESSION_AUTH_AUTHENTICATED, $a_status);
146  ilSession::set(self::SESSION_AUTH_USER_ID, $a_user_id);
147  $this->setExpired(false);
148  if ($a_status) {
149  $this->regenerateId();
150  }
151  }
regenerateId()
Regenerate id.
setExpired(bool $a_status)
Set session expired.
static set(string $a_var, $a_val)
Set a value.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setExpired()

ilAuthSession::setExpired ( bool  $a_status)

Set session expired.

Definition at line 164 of file class.ilAuthSession.php.

References ilSession\set().

Referenced by setAuthenticated(), and validateExpiration().

164  : void
165  {
166  $this->expired = $a_status;
167  ilSession::set(self::SESSION_AUTH_EXPIRED, (int) $a_status);
168  }
static set(string $a_var, $a_val)
Set a value.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setId()

ilAuthSession::setId ( string  $a_id)
protected

Set id.

Definition at line 206 of file class.ilAuthSession.php.

Referenced by init(), and regenerateId().

206  : void
207  {
208  $this->id = $a_id;
209  }
+ Here is the caller graph for this function:

◆ setUserId()

ilAuthSession::setUserId ( int  $a_id)

Set authenticated user id.

Definition at line 173 of file class.ilAuthSession.php.

Referenced by init().

173  : void
174  {
175  $this->user_id = $a_id;
176  }
+ Here is the caller graph for this function:

◆ validateExpiration()

ilAuthSession::validateExpiration ( )
protected

Check expired value of session.

Definition at line 189 of file class.ilAuthSession.php.

References getId(), isExpired(), ilSession\lookupExpireTime(), and setExpired().

Referenced by init().

189  : bool
190  {
191  if ($this->isExpired()) {
192  // keep status
193  return false;
194  }
195 
196  if (time() > ilSession::lookupExpireTime($this->getId())) {
197  $this->setExpired(true);
198  return false;
199  }
200  return true;
201  }
isExpired()
Check if current is or was expired in last request.
static lookupExpireTime(string $a_session_id)
Lookup expire time for a specific session.
setExpired(bool $a_status)
Set session expired.
getId()
get session id
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $authenticated

bool ilAuthSession::$authenticated = false
private

Definition at line 37 of file class.ilAuthSession.php.

◆ $expired

bool ilAuthSession::$expired = false
private

Definition at line 36 of file class.ilAuthSession.php.

◆ $id

string ilAuthSession::$id = ''
private

Definition at line 34 of file class.ilAuthSession.php.

Referenced by getId().

◆ $instance

ilAuthSession ilAuthSession::$instance = null
staticprivate

Definition at line 30 of file class.ilAuthSession.php.

◆ $logger

ilLogger ilAuthSession::$logger
private

Definition at line 32 of file class.ilAuthSession.php.

Referenced by __construct(), getInstance(), and getLogger().

◆ $user_id

int ilAuthSession::$user_id = 0
private

Definition at line 35 of file class.ilAuthSession.php.

Referenced by getUserId().

◆ SESSION_AUTH_AUTHENTICATED

const ilAuthSession::SESSION_AUTH_AUTHENTICATED = '_authsession_authenticated'
private

Definition at line 26 of file class.ilAuthSession.php.

◆ SESSION_AUTH_EXPIRED

const ilAuthSession::SESSION_AUTH_EXPIRED = '_authsession_expired'
private

Definition at line 28 of file class.ilAuthSession.php.

◆ SESSION_AUTH_USER_ID

const ilAuthSession::SESSION_AUTH_USER_ID = '_authsession_user_id'
private

Definition at line 27 of file class.ilAuthSession.php.


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