19declare(strict_types=1);
34 private string $id =
'';
46 return self::$instance ??=
new self(
$logger);
59 if (session_status() === PHP_SESSION_ACTIVE) {
60 $this->
getLogger()->error(__METHOD__ .
' called with active session.');
67 $this->
setId(session_id());
72 $this->
getLogger()->debug(
'Resuming old session for user: ' . $user_id);
74 $this->expired = (bool)
ilSession::get(self::SESSION_AUTH_EXPIRED);
75 $this->authenticated = (bool)
ilSession::get(self::SESSION_AUTH_AUTHENTICATED);
79 $this->
getLogger()->debug(
'Started new session.');
81 $this->expired =
false;
82 $this->authenticated =
false;
124 'Ensure anonymous context for: ' . $this->
getUserId()
157 $this->authenticated =
true;
158 $this->user_id = $a_user_id;
187 $this->expired = $a_status;
196 $this->user_id = $a_id;
228 protected function setId(
string $a_id): void
266 if (defined(
'IL_PHPUNIT_TEST')) {
270 $submitted_id = $submitted_session_id->
get();
271 if ($submitted_id ===
'' || $submitted_id !== session_id()) {
282 $old_session_id = session_id();
284 session_regenerate_id(
285 $policy === SessionRotationPolicy::Rotate
288 $this->
setId(session_id());
291 ?
'Session reject foreign id'
292 :
'Session regenerate id';
294 $label .
': [' . substr($old_session_id, 0, 5) .
'] -> [' . substr($this->
getId(), 0, 5) .
']'
init(SubmittedSessionId $submitted_session_id)
Start auth session.
static getInstance(ilLogger $logger)
rejectForeignSessionIdIfUnknown(SubmittedSessionId $submitted_session_id)
setAuthenticated(int $a_user_id)
establishAnonymousAuthState()
Anonymous auth flags.
const string SESSION_AUTH_AUTHENTICATED
validateExpiration()
Check expired value of session.
onSessionExpired()
Transition an expired privileged session to anonymous.
const string SESSION_AUTH_EXPIRED
applySessionRotation(SessionRotationPolicy $policy)
ensureAnonymousContext()
Prepare the login screen: anonymous auth state in the current session (no destroy,...
__construct(ilLogger $logger)
isValid()
Check if current session is valid (authenticated and not expired)
isExpired()
Check if current is or was expired in last request.
isAnonymouslyAuthenticated()
getUserId()
Get authenticated user id.
setUserId(int $a_id)
Set authenticated user id.
setId(string $a_id)
Set id.
setExpired(bool $a_status)
Set session expired.
const string SESSION_AUTH_USER_ID
isAuthenticated()
Check if session is authenticated.
logout()
End the current auth context and establish an anonymous session.
static ilAuthSession $instance
onLoginSuccess(int $user_id)
Establish an authenticated session after successful login.
Component logger with individual log levels by component id.
static get(string $a_var)
static exists(string $a_session_id)
static set(string $a_var, $a_val)
Set a value.
static lookupExpireTime(string $a_session_id)
Lookup expire time for a specific session.
The session id a client sent with the current request.
SessionRotationPolicy
When and how the PHP session id is changed at a security boundary.
@ RejectForeign
Issue a new session id after login, logout, or expiry.