ILIAS  trunk Revision v12.0_alpha-1613-gae4c99ebb18
SoapDummyAuthServer.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\AuthSOAP;
22
24{
25 public const SERVICE_NAME = 'ILIAS SOAP Dummy Authentication Server';
26 public const SERVICE_NAMESPACE = 'urn:SoapDummyAuthServer';
27
28 public function __construct(private readonly bool $use_wsdl = true)
29 {
30 }
31
32 public function start(): never
33 {
34 if ($this->isPostRequest()) {
36 } else {
37 $this->handleNusoapRequest();
38 }
39
40 exit();
41 }
42
43 private function isPostRequest(): bool
44 {
45 return strcasecmp($_SERVER['REQUEST_METHOD'] ?? '', 'POST') === 0;
46 }
47
48 private function handleNativeSoapRequest(): void
49 {
50 $uri = $this->buildEndpointUri();
51
52 // Non-WSDL mode: nusoap WSDL describes RPC/encoded ops as "ns1:isValidSession", which
53 // native SoapServer cannot map when loading that WSDL. Dispatch via __soapCall instead.
54 $soap_server = new \SoapServer(null, [
55 'uri' => self::SERVICE_NAMESPACE,
56 'location' => $uri,
57 ]);
58 $soap_server->setObject(new SoapDummyAuthHandler());
59 $soap_server->handle();
60 }
61
62 private function handleNusoapRequest(): void
63 {
64 $server = $this->createNusoapServer();
65
66 $post_data = file_get_contents('php://input');
67
68 $server->service($post_data);
69 }
70
71 private function createNusoapServer(): \soap_server
72 {
73 require_once __DIR__ . '/../../soap/lib/nusoap.php';
74 $server = new \soap_server();
75 $server->class = SoapDummyAuthHandler::class;
76
77 if ($this->use_wsdl) {
78 $this->enableWSDL($server);
79 }
80
82
83 return $server;
84 }
85
86 private function buildEndpointUri(): string
87 {
88 $https = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off');
89 $scheme = $https ? 'https' : 'http';
90 $host = $_SERVER['HTTP_HOST'] ?? 'localhost';
91 $script = $_SERVER['SCRIPT_NAME'] ?? '';
92
93 return $scheme . '://' . $host . $script;
94 }
95
96 public function enableWSDL(\soap_server $server): bool
97 {
98 $server->configureWSDL(self::SERVICE_NAME, self::SERVICE_NAMESPACE);
99
100 return true;
101 }
102
104 {
105 $server->wsdl->addComplexType(
106 'intArray',
107 'complexType',
108 'array',
109 '',
110 'SOAP-ENC:Array',
111 [],
112 [['ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'xsd:int[]']],
113 'xsd:int'
114 );
115
116 $server->wsdl->addComplexType(
117 'stringArray',
118 'complexType',
119 'array',
120 '',
121 'SOAP-ENC:Array',
122 [],
123 [['ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'xsd:string[]']],
124 'xsd:string'
125 );
126
127 $server->register(
128 'isValidSession',
129 [
130 'ext_uid' => 'xsd:string',
131 'soap_pw' => 'xsd:string',
132 'new_user' => 'xsd:boolean'
133 ],
134 [
135 'valid' => 'xsd:boolean',
136 'firstname' => 'xsd:string',
137 'lastname' => 'xsd:string',
138 'email' => 'xsd:string'
139 ],
140 self::SERVICE_NAMESPACE,
141 self::SERVICE_NAMESPACE . '#isValidSession',
142 'rpc',
143 'encoded',
144 'Dummy Session Validation'
145 );
146 }
147}
@phpstan-type ValidationResult array{firstname: string, lastname: string, email: string,...
__construct(private readonly bool $use_wsdl=true)
Backward compatibility.
Definition: nusoap.php:4565
$_SERVER['HTTP_HOST']
Definition: raiseError.php:26
$server
Definition: shib_login.php:28
exit
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...