ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
class.ilSoapAdministration.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
29
31{
32 public const NUSOAP = 1;
33 public const PHP5 = 2;
34
35 protected bool $soap_check = true;
36 protected string $message = '';
37 protected string $message_code = '';
38
42 public int $error_method;
43
44 public function __construct(bool $use_nusoap = true)
45 {
46 if (
47 defined('IL_SOAPMODE') &&
48 defined('IL_SOAPMODE_NUSOAP') &&
50 ) {
51 $this->error_method = self::NUSOAP;
52 } else {
53 $this->error_method = self::PHP5;
54 }
55
57 }
58
59 protected function checkSession(string $sid): bool
60 {
61 global $DIC;
62
63 $ilUser = $DIC->user();
64
65 [$sid, $client] = $this->explodeSid($sid);
66
67 if ($sid === '') {
68 $this->setMessage('No session id given');
69 $this->setMessageCode('Client');
70 return false;
71 }
72 if (!$client) {
73 $this->setMessage('No client given');
74 $this->setMessageCode('Client');
75 return false;
76 }
77
78 if (!$GLOBALS['DIC']['ilAuthSession']->isAuthenticated()) {
79 $this->setMessage('Session invalid');
80 $this->setMessageCode('Client');
81 return false;
82 }
83
84 $can = $DIC['legalDocuments']->canUseSoapApi()->applyTo(new Ok($ilUser))->except(
85 fn($error) => new Error(is_string($error) ? $error : $error->getMessage())
86 );
87 if (!$can->isOk()) {
88 $this->setMessage($can->error());
89 $this->setMessageCode('Server');
90 return false;
91 }
92
93 if ($this->soap_check) {
94 $set = new ilSetting();
95 $this->setMessage('SOAP is not enabled in ILIAS administration for this client');
96 $this->setMessageCode('Server');
97 return ((int) $set->get('soap_user_administration', '0')) === 1;
98 }
99
100 return true;
101 }
102
103 protected function explodeSid(string $sid): array
104 {
105 $exploded = explode('::', $sid);
106
107 return is_array($exploded) ? $exploded : array('sid' => '', 'client' => '');
108 }
109
110 protected function setMessage(string $a_str): void
111 {
112 $this->message = $a_str;
113 }
114
115 public function getMessage(): string
116 {
117 return $this->message;
118 }
119
120 public function appendMessage(string $a_str): void
121 {
122 $this->message .= isset($this->message) ? ' ' : '';
123 $this->message .= $a_str;
124 }
125
126 public function setMessageCode(string $a_code): void
127 {
128 $this->message_code = $a_code;
129 }
130
131 public function getMessageCode(): string
132 {
133 return $this->message_code;
134 }
135
136 protected function initAuth(string $sid): void
137 {
138 [$sid, $client] = $this->explodeSid($sid);
139
140 if (session_status() === PHP_SESSION_ACTIVE && $sid === session_id()) {
141 return;
142 }
143
144 if (session_status() === PHP_SESSION_ACTIVE) {
145 session_destroy();
146 }
147
148 session_id($sid);
149
151
153 ilUtil::setCookie(session_name(), $sid);
154 }
155 }
156
157 protected function initIlias(): void
158 {
160 try {
162 } catch (Exception $e) {
163 }
164 }
165 }
166
167 public function reInitUser(): void
168 {
170 try {
172 } catch (Exception $e) {
173 }
174 }
175 }
176
177 protected function initAuthenticationObject(): void
178 {
180 }
181
187 protected function raiseError(string $a_message, $a_code)
188 {
189 switch ($this->error_method) {
190 case self::NUSOAP:
191 require_once __DIR__ . '/../lib/nusoap.php';
192 return new soap_fault($a_code, '', $a_message);
193 case self::PHP5:
194 return new SoapFault($a_code, $a_message);
195 }
196 return null;
197 }
198
199 public function isFault($object): bool
200 {
201 switch ($this->error_method) {
202 case self::NUSOAP:
203 require_once __DIR__ . '/../lib/nusoap.php';
204 return $object instanceof soap_fault;
205 case self::PHP5:
206 return $object instanceof SoapFault;
207 }
208 return true;
209 }
210
214 protected function checkObjectAccess(
215 int $ref_id,
216 array $expected_type,
217 string $permission,
218 bool $returnObject = false
219 ) {
220 global $DIC;
221
222 $rbacsystem = $DIC->rbac()->system();
223
224 if (!ilObject::_exists($ref_id, true)) {
225 return $this->raiseError(
226 'No object for id.',
227 'CLIENT_OBJECT_NOT_FOUND'
228 );
229 }
230
231 if (ilObject::_isInTrash($ref_id)) {
232 return $this->raiseError(
233 'Object is already trashed.',
234 'CLIENT_OBJECT_DELETED'
235 );
236 }
237
239 if (!in_array($type, $expected_type, true)) {
240 return $this->raiseError(
241 "Wrong type $type for id. Expected: " . implode(',', $expected_type),
242 'CLIENT_OBJECT_WRONG_TYPE'
243 );
244 }
245 if (!$rbacsystem->checkAccess($permission, $ref_id, $type)) {
246 return $this->raiseError(
247 'Missing permission $permission for type $type.',
248 'CLIENT_OBJECT_WRONG_PERMISSION'
249 );
250 }
251 if ($returnObject) {
252 try {
254 } catch (ilObjectNotFoundException $e) {
255 return $this->raiseError('No valid ref_id given', 'Client');
256 }
257 }
258 return $type;
259 }
260
261 public function getInstallationInfoXML(): string
262 {
264
266
267 $clientdirs = glob(ILIAS_WEB_DIR . '/*', GLOB_ONLYDIR);
268 $writer = new ilSoapInstallationInfoXMLWriter();
269 $writer->start();
270 if (is_array($clientdirs)) {
271 foreach ($clientdirs as $clientdir) {
272 $writer->addClient($clientdir);
273 }
274 }
275 $writer->end();
276 return $writer->getXML();
277 }
278
282 public function getClientInfoXML(string $clientid)
283 {
285
287
288 $clientdir = ILIAS_WEB_DIR . '/' . $clientid;
289 $writer = new ilSoapInstallationInfoXMLWriter();
290 $writer->start();
291 if (!$writer->addClient($clientdir)) {
292 return $this->raiseError(
293 'Client ID ' . $clientid . 'does not exist!',
294 'Client'
295 );
296 }
297 $writer->end();
298 return $writer->getXML();
299 }
300}
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Ok.php:31
const int CONTEXT_SOAP
SOAP based authentication.
static setContext(int $a_context)
const CONTEXT_SOAP_WITHOUT_CLIENT
Definition: ilContext.php:39
static getType()
Get context type.
Definition: ilContext.php:165
static init(string $a_type)
Init context by type.
Definition: ilContext.php:52
const CONTEXT_SOAP
Definition: ilContext.php:34
static initILIAS()
ilias initialisation
static getInstanceByRefId(int $ref_id, bool $stop_on_error=true)
get an instance of an Ilias object by reference id
static _lookupType(int $id, bool $reference=false)
static _isInTrash(int $ref_id)
static _exists(int $id, bool $reference=false, ?string $type=null)
checks if an object exists in object_data
static _lookupObjId(int $ref_id)
ILIAS Setting Class.
raiseError(string $a_message, $a_code)
__construct(bool $use_nusoap=true)
int $error_method
Defines type of error handling (PHP5 || NUSOAP)
checkObjectAccess(int $ref_id, array $expected_type, string $permission, bool $returnObject=false)
check access for ref id: expected type, permission, return object instance if returnobject is true
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static setCookie(string $a_cookie_name, string $a_cookie_value='', bool $a_also_set_super_global=true, bool $a_set_cookie_invalid=false)
Backward compatibility.
Definition: nusoap.php:1069
const ILIAS_WEB_DIR
Definition: constants.php:45
$client
$ref_id
Definition: ltiauth.php:66
global $DIC
Definition: shib_login.php:26
const IL_SOAPMODE
Definition: server.php:23
const IL_SOAPMODE_NUSOAP
Definition: server.php:21
$GLOBALS["DIC"]
Definition: wac.php:54