ILIAS  release_8 Revision v8.24
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().

+ Here is the call graph for this function:

Member Function Documentation

◆ getId()

ilAuthSession::getId ( )

get session id

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

208 : string
209 {
210 return $this->id;
211 }

References $id.

Referenced by regenerateId(), and validateExpiration().

+ Here is the caller graph for this function:

◆ getInstance()

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

Get instance.

Parameters

ilLogger

Returns
ilAuthSession

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

50 {
51 if (self::$instance) {
52 return self::$instance;
53 }
54 return self::$instance = new self($logger);
55 }
static ilAuthSession $instance

References $instance, and $logger.

Referenced by ilInitialisation\initSession().

+ Here is the caller graph for this function:

◆ getLogger()

ilAuthSession::getLogger ( )
protected
Returns
ilLogger

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

60 : ilLogger
61 {
62 return $this->logger;
63 }
Component logger with individual log levels by component id.

References $logger.

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

+ Here is the caller graph for this function:

◆ getUserId()

ilAuthSession::getUserId ( )

Get authenticated user id.

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

175 : int
176 {
177 return $this->user_id;
178 }

References $user_id.

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

+ Here is the caller graph for this function:

◆ init()

ilAuthSession::init ( )

Start auth session.

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

68 : bool
69 {
70 session_start();
71
72 $this->setId(session_id());
73
74 $user_id = (int) ilSession::get(self::SESSION_AUTH_USER_ID);
75
76 if ($user_id) {
77 $this->getLogger()->debug('Resuming old session for user: ' . $user_id);
78 $this->setUserId((int) ilSession::get(self::SESSION_AUTH_USER_ID));
79 $this->expired = (bool) ilSession::get(self::SESSION_AUTH_EXPIRED);
80 $this->authenticated = (bool) ilSession::get(self::SESSION_AUTH_AUTHENTICATED);
81
82 $this->validateExpiration();
83 } else {
84 $this->getLogger()->debug('Started new session.');
86 $this->expired = false;
87 $this->authenticated = false;
88 }
89 return true;
90 }
validateExpiration()
Check expired value of session.
setUserId(int $a_id)
Set authenticated user id.
setId(string $a_id)
Set id.
static get(string $a_var)
const ANONYMOUS_USER_ID
Definition: constants.php:27

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

Referenced by logout().

+ 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 127 of file class.ilAuthSession.php.

127 : bool
128 {
130 }

References $authenticated.

Referenced by isValid().

+ Here is the caller graph for this function:

◆ isExpired()

ilAuthSession::isExpired ( )

Check if current is or was expired in last request.

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

150 : bool
151 {
152 return $this->expired;
153 }

References $expired.

Referenced by isValid(), and validateExpiration().

+ Here is the caller graph for this function:

◆ isValid()

ilAuthSession::isValid ( )

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

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

95 : bool
96 {
97 return !$this->isExpired() && $this->isAuthenticated();
98 }
isExpired()
Check if current is or was expired in last request.
isAuthenticated()
Check if session is authenticated.

References isAuthenticated(), and isExpired().

+ Here is the call graph for this function:

◆ logout()

ilAuthSession::logout ( )

Logout user => stop session.

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

114 : void
115 {
116 $this->getLogger()->debug('Logout called for: ' . $this->getUserId());
117 session_regenerate_id(true);
118 session_destroy();
119
120 $this->init();
122 }
init()
Start auth session.
getUserId()
Get authenticated user id.
setAuthenticated(bool $a_status, int $a_user_id)
Set authenticated.

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

+ Here is the call graph for this function:

◆ regenerateId()

ilAuthSession::regenerateId ( )

Regenerate id.

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

103 : void
104 {
105 $old_session_id = session_id();
106 session_regenerate_id(true);
107 $this->setId(session_id());
108 $this->getLogger()->info('Session regenerate id: [' . substr($old_session_id, 0, 5) . '] -> [' . substr($this->getId(), 0, 5) . ']');
109 }
getId()
get session id

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

Referenced by setAuthenticated().

+ 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 135 of file class.ilAuthSession.php.

135 : void
136 {
137 $this->authenticated = $a_status;
138 $this->user_id = $a_user_id;
139 ilSession::set(self::SESSION_AUTH_AUTHENTICATED, $a_status);
140 ilSession::set(self::SESSION_AUTH_USER_ID, $a_user_id);
141 $this->setExpired(false);
142 if ($a_status) {
143 $this->regenerateId();
144 }
145 }
regenerateId()
Regenerate id.
setExpired(bool $a_status)
Set session expired.
static set(string $a_var, $a_val)
Set a value.

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

Referenced by logout().

+ 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 158 of file class.ilAuthSession.php.

158 : void
159 {
160 $this->expired = $a_status;
161 ilSession::set(self::SESSION_AUTH_EXPIRED, (int) $a_status);
162 }

References ilSession\set().

Referenced by setAuthenticated(), and validateExpiration().

+ 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 200 of file class.ilAuthSession.php.

200 : void
201 {
202 $this->id = $a_id;
203 }

Referenced by init(), and regenerateId().

+ Here is the caller graph for this function:

◆ setUserId()

ilAuthSession::setUserId ( int  $a_id)

Set authenticated user id.

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

167 : void
168 {
169 $this->user_id = $a_id;
170 }

Referenced by init().

+ Here is the caller graph for this function:

◆ validateExpiration()

ilAuthSession::validateExpiration ( )
protected

Check expired value of session.

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

183 : bool
184 {
185 if ($this->isExpired()) {
186 // keep status
187 return false;
188 }
189
190 if (time() > ilSession::lookupExpireTime($this->getId())) {
191 $this->setExpired(true);
192 return false;
193 }
194 return true;
195 }
static lookupExpireTime(string $a_session_id)
Lookup expire time for a specific session.

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

Referenced by init().

+ 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.

Referenced by isAuthenticated().

◆ $expired

bool ilAuthSession::$expired = false
private

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

Referenced by isExpired().

◆ $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.

Referenced by getInstance().

◆ $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(), and init().

◆ 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: