ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ilAuthSession Class Reference
+ Collaboration diagram for ilAuthSession:

Public Member Functions

 getLogger ()
 
 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...
 
 setId ($a_id)
 
 getId ()
 

Static Public Member Functions

static getInstance ()
 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

 validateExpiration ()
 Check expired value of session. More...
 

Private Member Functions

 __construct ()
 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 ( )
private

Consctructor.

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

32 {
33 $this->logger = ilLoggerFactory::getLogger('auth');
34 }
static getLogger($a_component_id)
Get component logger.

References ilLoggerFactory\getLogger().

+ Here is the call graph for this function:

Member Function Documentation

◆ getId()

ilAuthSession::getId ( )

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

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

References $id.

Referenced by regenerateId(), and validateExpiration().

+ Here is the caller graph for this function:

◆ getInstance()

static ilAuthSession::getInstance ( )
static

Get instance.

Returns
ilAuthSession

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

41 {
42 if(self::$instance)
43 {
44 return self::$instance;
45 }
46 return self::$instance = new self();
47 }

References $instance.

Referenced by ilInitialisation\initSession().

+ Here is the caller graph for this function:

◆ getLogger()

ilAuthSession::getLogger ( )
Returns
ilLogger

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

53 {
54 return $this->logger;
55 }

References $logger.

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

+ Here is the caller graph for this function:

◆ getUserId()

ilAuthSession::getUserId ( )

Get authenticated user id.

Returns
int

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

178 {
179 return $this->user_id;
180 }

References $user_id.

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

+ Here is the caller graph for this function:

◆ init()

ilAuthSession::init ( )

Start auth session.

Returns
boolean

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

62 {
63 session_start();
64
65 $this->setId(session_id());
66
67 $user_id = (int) ilSession::get(self::SESSION_AUTH_USER_ID);
68
69 if($user_id)
70 {
71 $this->getLogger()->debug('Resuming old session for user: ' . $user_id);
72 $this->setUserId(ilSession::get(self::SESSION_AUTH_USER_ID));
73 $this->expired = (int) ilSession::get(self::SESSION_AUTH_EXPIRED);
74 $this->authenticated = (int) ilSession::get(self::SESSION_AUTH_AUTHENTICATED);
75
76 $this->validateExpiration();
77 }
78 else
79 {
80 $this->getLogger()->debug('Started new session.');
81 $this->setUserId(0);
82 $this->expired = false;
83 $this->authenticated = false;
84 }
85 return true;
86 }
validateExpiration()
Check expired value of session.
setUserId($a_id)
Set authenticated user id.
static get($a_var)
Get a value.

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

+ Here is the call graph for this function:

◆ isAuthenticated()

ilAuthSession::isAuthenticated ( )

Check if session is authenticated.

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

123 {
125 }

References $authenticated.

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

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

150 {
151 return (bool) $this->expired;
152 }

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)

Returns
bool

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

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

112 {
113 $this->getLogger()->debug('Logout called for: '. $this->getUserId());
114 $this->setAuthenticated(false, 0);
115 session_regenerate_id(true);
116 session_destroy();
117 }
setAuthenticated($a_status, $a_user_id)
Set authenticated.
getUserId()
Get authenticated user id.

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

Referenced by ilSessionControl\checkCurrentSessionIsAllowed().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ regenerateId()

ilAuthSession::regenerateId ( )

Regenerate id.

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

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

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 (   $a_status,
  $a_user_id 
)

Set authenticated.

Parameters
authenticationstatus $a_status
Returns
type

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

133 {
134 $this->authenticated = $a_status;
135 $this->user_id = $a_user_id;
136 ilSession::set(self::SESSION_AUTH_AUTHENTICATED, $a_status);
137 ilSession::set(self::SESSION_AUTH_USER_ID, (int) $a_user_id);
138 $this->setExpired(false);
139 if($a_status)
140 {
141 $this->regenerateId();
142 }
143 }
regenerateId()
Regenerate id.
setExpired($a_status)
Set session expired.
static set($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 (   $a_status)

Set session expired.

Parameters
type$a_status

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

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 (   $a_id)

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

203 {
204 $this->id = $a_id;
205 }

Referenced by init(), and regenerateId().

+ Here is the caller graph for this function:

◆ setUserId()

ilAuthSession::setUserId (   $a_id)

Set authenticated user id.

Parameters
int$a_id

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

169 {
170 $this->user_id = $a_id;
171 }

Referenced by init().

+ Here is the caller graph for this function:

◆ validateExpiration()

ilAuthSession::validateExpiration ( )
protected

Check expired value of session.

Returns
bool

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

187 {
188 if($this->isExpired())
189 {
190 // keep status
191 return false;
192 }
193
194 if(time() > ilSession::lookupExpireTime($this->getId()))
195 {
196 $this->setExpired(true);
197 return false;
198 }
199 return true;
200 }
static lookupExpireTime($a_session_id)
Lookup expire time for a specific session @global ilDB $ilDB.

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

ilAuthSession::$authenticated = false
private

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

Referenced by isAuthenticated().

◆ $expired

ilAuthSession::$expired = false
private

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

Referenced by isExpired().

◆ $id

ilAuthSession::$id = ''
private

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

Referenced by getId().

◆ $instance

ilAuthSession::$instance = null
staticprivate

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

Referenced by getInstance().

◆ $logger

ilAuthSession::$logger = null
private

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

Referenced by getLogger().

◆ $user_id

ilAuthSession::$user_id = 0
private

Definition at line 24 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: