ILIAS  trunk Revision v12.0_alpha-1613-gae4c99ebb18
SessionValidationClient.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\AuthSOAP;
22
24{
25 public function __construct(
26 private string $location,
27 private string $namespace,
28 private bool $use_dotnet = false,
29 ) {
30 }
31
32 public function validateSession(
33 string $ext_uid,
34 string $soap_pw,
35 bool $new_user,
37 $service_namespace = $this->namespace !== '' ? $this->namespace : $this->location;
38
39 $soap_client = new \SoapClient(null, [
40 'location' => $this->location,
41 'uri' => $service_namespace,
42 'trace' => true,
43 'exceptions' => true,
44 'style' => SOAP_RPC,
45 'use' => SOAP_ENCODED,
46 ]);
47
48 $call_options = ['uri' => $service_namespace];
49 if ($this->use_dotnet) {
50 $call_options['soapaction'] = $service_namespace . '/isValidSession';
51 }
52
53 $valid = $soap_client->__soapCall(
54 'isValidSession',
55 $this->buildCallParameters($ext_uid, $soap_pw, $new_user),
56 $call_options
57 );
58
59 return new SessionValidationResult(
60 $this->normalizeValidationResult($valid),
61 (string) $soap_client->__getLastRequest(),
62 (string) $soap_client->__getLastResponse(),
63 );
64 }
65
70 private function buildCallParameters(string $ext_uid, string $soap_pw, bool $new_user): array
71 {
72 if ($this->use_dotnet) {
73 return [
74 new \SoapParam($ext_uid, 'ns1:ext_uid'),
75 new \SoapParam($soap_pw, 'ns1:soap_pw'),
76 new \SoapParam($new_user, 'ns1:new_user'),
77 ];
78 }
79
80 return [
81 new \SoapParam($ext_uid, 'ext_uid'),
82 new \SoapParam($soap_pw, 'soap_pw'),
83 new \SoapParam($new_user, 'new_user'),
84 ];
85 }
86
90 private function normalizeValidationResult(mixed $valid): array
91 {
92 if (\is_object($valid)) {
93 $valid = (array) $valid;
94 }
95
96 if (!\is_array($valid)) {
97 return ['valid' => false];
98 }
99
100 return $valid;
101 }
102}
$location
Definition: buildRTE.php:22
__construct(private string $location, private string $namespace, private bool $use_dotnet=false,)
validateSession(string $ext_uid, string $soap_pw, bool $new_user,)
buildCallParameters(string $ext_uid, string $soap_pw, bool $new_user)
Mirrors legacy nusoap_client::call() parameter naming (ns1: prefix in .NET mode).
@phpstan-type ValidationArray array{valid: bool, firstname?: string, lastname?: string,...
$soap_pw
$ext_uid
$new_user