ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
StartUp.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\Cron\CLI;
22
24
26{
27 private readonly \ilAuthSession $auth_session;
28 private bool $is_authenticated = false;
29
30 public function __construct(
31 private readonly string $client,
32 private readonly string $username,
33 ?\ilAuthSession $authSession = null
34 ) {
37
38 // TODO @see mantis 20371: To get rid of this, the authentication service has to provide a mechanism to pass the client_id
39 $_GET['client_id'] = $this->client;
40
41 require_once __DIR__ . '/../../../../../artifacts/bootstrap_default.php';
42 entry_point('ILIAS Legacy Initialisation Adapter');
43
44 if ($authSession === null) {
45 global $DIC;
46 $authSession = $DIC['ilAuthSession'];
47 }
48 $this->auth_session = $authSession;
49 }
50
51 public function authenticate(): bool
52 {
53 $credentials = new \ilAuthFrontendCredentials();
54 $credentials->setUsername($this->username);
55
57
58 $frontend_factory = new \ilAuthFrontendFactory();
59 $frontend_factory->setContext(\ilAuthFrontendFactory::CONTEXT_CLI);
60
61 $provider_factory = new \ilAuthProviderCliFactory();
62
63 $frontend = $frontend_factory->getFrontend(
64 $this->auth_session,
65 $status,
66 $credentials,
67 $provider_factory->getProviders($credentials)
68 );
69
70 $frontend->authenticate();
71
72 switch ($status->getStatus()) {
73 case \ilAuthStatus::STATUS_AUTHENTICATED:
74 $this->is_authenticated = true;
75 \ilLoggerFactory::getLogger('auth')->debug('Authentication successful; Redirecting to starting page.');
76
77 // https://mantis.ilias.de/view.php?id=47354
78 \ilInitialisation::initLanguage(true);
79
80 return true;
81
82 case \ilAuthStatus::STATUS_AUTHENTICATION_FAILED:
83 default:
84 throw new CronException($status->getTranslatedReason());
85 }
86 }
87
88 public function logout(): void
89 {
90 if ($this->is_authenticated) {
92 $this->auth_session->logout();
93 }
94 }
95}
readonly ilAuthSession $auth_session
Definition: StartUp.php:27
__construct(private readonly string $client, private readonly string $username, ?\ilAuthSession $authSession=null)
Definition: StartUp.php:30
static getInstance()
Get status instance.
const CONTEXT_CRON
Definition: ilContext.php:31
static init(string $a_type)
Init context by type.
Definition: ilContext.php:52
static getLogger(string $a_component_id)
Get component logger.
static setClosingContext(int $a_context)
set closing context (for statistics)
const int SESSION_CLOSE_USER
$client
$_GET['cmd']
Definition: lti.php:26
entry_point(string $name)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: result1.php:21
global $DIC
Definition: shib_login.php:26