ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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
152 ilUtil::setCookie(session_name(), $sid);
153 }
154 }
155
156 protected function initIlias(): void
157 {
159 try {
161 } catch (Exception $e) {
162 }
163 }
164 }
165
166 public function reInitUser(): void
167 {
169 try {
171 } catch (Exception $e) {
172 }
173 }
174 }
175
176 protected function initAuthenticationObject(): void
177 {
179 }
180
186 protected function raiseError(string $a_message, $a_code)
187 {
188 switch ($this->error_method) {
189 case self::NUSOAP:
190 require_once __DIR__ . '/../lib/nusoap.php';
191 return new soap_fault($a_code, '', $a_message);
192 case self::PHP5:
193 return new SoapFault($a_code, $a_message);
194 }
195 return null;
196 }
197
198 public function isFault($object): bool
199 {
200 switch ($this->error_method) {
201 case self::NUSOAP:
202 require_once __DIR__ . '/../lib/nusoap.php';
203 return $object instanceof soap_fault;
204 case self::PHP5:
205 return $object instanceof SoapFault;
206 }
207 return true;
208 }
209
213 protected function checkObjectAccess(
214 int $ref_id,
215 array $expected_type,
216 string $permission,
217 bool $returnObject = false
218 ) {
219 global $DIC;
220
221 $rbacsystem = $DIC->rbac()->system();
222
223 if (!ilObject::_exists($ref_id, true)) {
224 return $this->raiseError(
225 'No object for id.',
226 'CLIENT_OBJECT_NOT_FOUND'
227 );
228 }
229
230 if (ilObject::_isInTrash($ref_id)) {
231 return $this->raiseError(
232 'Object is already trashed.',
233 'CLIENT_OBJECT_DELETED'
234 );
235 }
236
238 if (!in_array($type, $expected_type, true)) {
239 return $this->raiseError(
240 "Wrong type $type for id. Expected: " . implode(',', $expected_type),
241 'CLIENT_OBJECT_WRONG_TYPE'
242 );
243 }
244 if (!$rbacsystem->checkAccess($permission, $ref_id, $type)) {
245 return $this->raiseError(
246 'Missing permission $permission for type $type.',
247 'CLIENT_OBJECT_WRONG_PERMISSION'
248 );
249 }
250 if ($returnObject) {
251 try {
253 } catch (ilObjectNotFoundException $e) {
254 return $this->raiseError('No valid ref_id given', 'Client');
255 }
256 }
257 return $type;
258 }
259
260 public function getInstallationInfoXML(): string
261 {
263
265
266 $clientdirs = glob(ILIAS_WEB_DIR . '/*', GLOB_ONLYDIR);
267 $writer = new ilSoapInstallationInfoXMLWriter();
268 $writer->start();
269 if (is_array($clientdirs)) {
270 foreach ($clientdirs as $clientdir) {
271 $writer->addClient($clientdir);
272 }
273 }
274 $writer->end();
275 return $writer->getXML();
276 }
277
281 public function getClientInfoXML(string $clientid)
282 {
284
286
287 $clientdir = ILIAS_WEB_DIR . '/' . $clientid;
288 $writer = new ilSoapInstallationInfoXMLWriter();
289 $writer->start();
290 if (!$writer->addClient($clientdir)) {
291 return $this->raiseError(
292 'Client ID ' . $clientid . 'does not exist!',
293 'Client'
294 );
295 }
296 $writer->end();
297 return $writer->getXML();
298 }
299}
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
static getType()
Get context type.
static init(string $a_type)
Init context by type.
const CONTEXT_SOAP
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