ILIAS  trunk Revision v12.0_alpha-1613-gae4c99ebb18
SoapDummyAuthHandler.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\AuthSOAP;
22
31{
35 public function isValidSession(string $ext_uid, string $soap_pw, bool $new_user): array
36 {
37 return $this->buildValidationResult($ext_uid, $soap_pw, $new_user);
38 }
39
44 public function __soapCall(string $function_name, array $arguments): array
45 {
46 if ($this->localOperationName($function_name) !== 'isValidSession') {
47 throw new \SoapFault('SOAP-ENV:Server', "Procedure '$function_name' not present");
48 }
49
50 return $this->invokeIsValidSession($arguments);
51 }
52
53 private function localOperationName(string $name): string
54 {
55 if (str_contains($name, ':')) {
56 return substr($name, strrpos($name, ':') + 1);
57 }
58
59 return $name;
60 }
61
66 private function invokeIsValidSession(array $arguments): array
67 {
68 if (\count($arguments) === 1) {
69 $first = $arguments[0];
70 if (\is_object($first)) {
72 $arguments = (array) $first;
73 } elseif (\is_array($first)) {
75 $arguments = $first;
76 }
77 }
78
79 $parameters = $this->normalizeParameterKeys($arguments);
80
81 return $this->buildValidationResult(
82 $parameters['ext_uid'],
83 $parameters['soap_pw'],
84 $parameters['new_user']
85 );
86 }
87
92 private function normalizeParameterKeys(array $arguments): array
93 {
94 $normalized = [];
95 foreach ($arguments as $key => $value) {
96 if (!\is_string($key)) {
97 continue;
98 }
99 $normalized[$this->localOperationName($key)] = $value;
100 }
101
102 if ($normalized !== []) {
103 return [
104 'ext_uid' => (string) ($normalized['ext_uid'] ?? ''),
105 'soap_pw' => (string) ($normalized['soap_pw'] ?? ''),
106 'new_user' => (bool) ($normalized['new_user'] ?? false),
107 ];
108 }
109
110 return [
111 'ext_uid' => (string) ($arguments[0] ?? ''),
112 'soap_pw' => (string) ($arguments[1] ?? ''),
113 'new_user' => (bool) ($arguments[2] ?? false),
114 ];
115 }
116
120 private function buildValidationResult(string $ext_uid, string $soap_pw, bool $new_user): array
121 {
122 $result = [
123 'firstname' => '',
124 'lastname' => '',
125 'email' => '',
126 'valid' => $ext_uid === $soap_pw,
127 ];
128
129 if ($new_user) {
130 $result['firstname'] = 'first ' . $ext_uid;
131 $result['lastname'] = 'last ' . $ext_uid;
132 $result['email'] = $ext_uid . '@de.de';
133 }
134
135 return $result;
136 }
137}
@phpstan-type ValidationResult array{firstname: string, lastname: string, email: string,...
isValidSession(string $ext_uid, string $soap_pw, bool $new_user)
buildValidationResult(string $ext_uid, string $soap_pw, bool $new_user)
__soapCall(string $function_name, array $arguments)
$soap_pw
$ext_uid
$new_user