ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables 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 ($a_status, $a_user_id)
 Set authenticated. More...
 
 isExpired ()
 Check if current is or was expired in last request. More...
 
 setExpired ($a_status)
 Set session expired. More...
 
 setUserId ($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...
 

Data Fields

const SESSION_AUTH_AUTHENTICATED = '_authsession_authenticated'
 
const SESSION_AUTH_USER_ID = '_authsession_user_id'
 
const SESSION_AUTH_EXPIRED = '_authsession_expired'
 

Protected Member Functions

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

Private Member Functions

 __construct (\ilLogger $logger)
 Consctructor. More...
 

Private Attributes

 $logger = null
 
 $id = ''
 
 $user_id = 0
 
 $expired = false
 
 $authenticated = false
 

Static Private Attributes

static $instance = null
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilAuthSession::__construct ( \ilLogger  $logger)
private

Consctructor.

Parameters

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

References $logger.

36  {
37  $this->logger = $logger;
38  }

Member Function Documentation

◆ getId()

ilAuthSession::getId ( )

get session id

Returns
string

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

References $id.

Referenced by regenerateId(), and validateExpiration().

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

◆ getInstance()

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

Get instance.

Parameters

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

References $logger.

Referenced by ilInitialisation\initSession().

46  {
47  if (self::$instance) {
48  return self::$instance;
49  }
50  return self::$instance = new self($logger);
51  }
+ Here is the caller graph for this function:

◆ getLogger()

ilAuthSession::getLogger ( )
protected
Returns
ilLogger

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

References $logger.

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

57  {
58  return $this->logger;
59  }
+ Here is the caller graph for this function:

◆ getUserId()

ilAuthSession::getUserId ( )

Get authenticated user id.

Returns
int

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

References $user_id.

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

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

◆ init()

ilAuthSession::init ( )

Start auth session.

Returns
boolean

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

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

Referenced by logout().

66  {
67  session_start();
68 
69  $this->setId(session_id());
70 
71  $user_id = (int) ilSession::get(self::SESSION_AUTH_USER_ID);
72 
73  if ($user_id) {
74  $this->getLogger()->debug('Resuming old session for user: ' . $user_id);
75  $this->setUserId(ilSession::get(self::SESSION_AUTH_USER_ID));
76  $this->expired = (int) ilSession::get(self::SESSION_AUTH_EXPIRED);
77  $this->authenticated = (int) ilSession::get(self::SESSION_AUTH_AUTHENTICATED);
78 
79  $this->validateExpiration();
80  } else {
81  $this->getLogger()->debug('Started new session.');
83  $this->expired = false;
84  $this->authenticated = false;
85  }
86  return true;
87  }
const ANONYMOUS_USER_ID
Definition: constants.php:25
static get($a_var)
Get a value.
setUserId($a_id)
Set authenticated user id.
validateExpiration()
Check expired value of session.
setId($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 125 of file class.ilAuthSession.php.

References $authenticated.

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

126  {
127  return $this->authenticated;
128  }
+ Here is the caller graph for this function:

◆ isExpired()

ilAuthSession::isExpired ( )

Check if current is or was expired in last request.

Returns
type

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

References $expired.

Referenced by isValid(), and validateExpiration().

152  {
153  return (bool) $this->expired;
154  }
+ Here is the caller graph for this function:

◆ isValid()

ilAuthSession::isValid ( )

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

Returns
bool

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

References isAuthenticated(), and isExpired().

94  {
95  return !$this->isExpired() && $this->isAuthenticated();
96  }
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 112 of file class.ilAuthSession.php.

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

Referenced by ilSessionControl\checkCurrentSessionIsAllowed().

113  {
114  $this->getLogger()->debug('Logout called for: ' . $this->getUserId());
115  session_regenerate_id(true);
116  session_destroy();
117 
118  $this->init();
119  $this->setAuthenticated(true, ANONYMOUS_USER_ID);
120  }
setAuthenticated($a_status, $a_user_id)
Set authenticated.
const ANONYMOUS_USER_ID
Definition: constants.php:25
getUserId()
Get authenticated user id.
init()
Start auth session.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ regenerateId()

ilAuthSession::regenerateId ( )

Regenerate id.

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

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

Referenced by setAuthenticated().

102  {
103  $old_session_id = session_id();
104  session_regenerate_id(true);
105  $this->setId(session_id());
106  $this->getLogger()->info('Session regenerate id: [' . substr($old_session_id, 0, 5) . '] -> [' . substr($this->getId(), 0, 5) . ']');
107  }
getId()
get session id
setId($a_id)
Set id.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setAuthenticated()

ilAuthSession::setAuthenticated (   $a_status,
  $a_user_id 
)

Set authenticated.

Parameters
authenticationstatus $a_status
Returns
type

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

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

Referenced by logout().

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, (int) $a_user_id);
141  $this->setExpired(false);
142  if ($a_status) {
143  $this->regenerateId();
144  }
145  }
regenerateId()
Regenerate id.
static set($a_var, $a_val)
Set a value.
setExpired($a_status)
Set session expired.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setExpired()

ilAuthSession::setExpired (   $a_status)

Set session expired.

Parameters
type$a_status

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

References ilSession\set().

Referenced by setAuthenticated(), and validateExpiration().

161  {
162  $this->expired = $a_status;
163  ilSession::set(self::SESSION_AUTH_EXPIRED, (int) $a_status);
164  }
static set($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 (   $a_id)
protected

Set id.

Parameters
string$a_id

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

Referenced by init(), and regenerateId().

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

◆ setUserId()

ilAuthSession::setUserId (   $a_id)

Set authenticated user id.

Parameters
int$a_id

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

Referenced by init().

171  {
172  $this->user_id = $a_id;
173  }
+ Here is the caller graph for this function:

◆ validateExpiration()

ilAuthSession::validateExpiration ( )
protected

Check expired value of session.

Returns
bool

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

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

Referenced by init().

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

Field Documentation

◆ $authenticated

ilAuthSession::$authenticated = false
private

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

Referenced by isAuthenticated().

◆ $expired

ilAuthSession::$expired = false
private

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

Referenced by isExpired().

◆ $id

ilAuthSession::$id = ''
private

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

Referenced by getId().

◆ $instance

ilAuthSession::$instance = null
staticprivate

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

◆ $logger

ilAuthSession::$logger = null
private

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

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

◆ $user_id

ilAuthSession::$user_id = 0
private

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

Referenced by getUserId(), and init().

◆ SESSION_AUTH_AUTHENTICATED

const ilAuthSession::SESSION_AUTH_AUTHENTICATED = '_authsession_authenticated'

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

◆ SESSION_AUTH_EXPIRED

const ilAuthSession::SESSION_AUTH_EXPIRED = '_authsession_expired'

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

◆ SESSION_AUTH_USER_ID

const ilAuthSession::SESSION_AUTH_USER_ID = '_authsession_user_id'

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


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