Skip to content

Commit 8b9d915

Browse files
committed
2 parents 1968474 + eeb7828 commit 8b9d915

File tree

3 files changed

+14
-42
lines changed

3 files changed

+14
-42
lines changed

src/Controller/Adfs.php

Lines changed: 11 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,6 @@ public function metadata(Request $request): Response
184184
$metaArray['RegistrationInfo'] = $idpmeta->getArray('RegistrationInfo');
185185
}
186186

187-
$metaflat = '$metadata[' . var_export($idpentityid, true) . '] = ' . var_export($metaArray, true) . ';';
188-
189187
$metaBuilder = new Metadata\SAMLBuilder($idpentityid);
190188
$metaBuilder->addSecurityTokenServiceType($metaArray);
191189
$metaBuilder->addOrganizationInfo($metaArray);
@@ -197,51 +195,24 @@ public function metadata(Request $request): Response
197195
'contactType' => 'technical',
198196
]));
199197
}
200-
$output_xhtml = $request->query->get('output') === 'xhtml';
201-
$metaxml = $metaBuilder->getEntityDescriptorText($output_xhtml);
202-
if (!$output_xhtml) {
203-
$metaxml = str_replace("\n", '', $metaxml);
204-
}
198+
$metaxml = $metaBuilder->getEntityDescriptorText();
205199

206200
// sign the metadata if enabled
207201
$metaxml = Metadata\Signer::sign($metaxml, $idpmeta->toArray(), 'ADFS IdP');
208202

209-
if ($output_xhtml) {
210-
$t = new Template($this->config, 'metadata.twig');
203+
// make sure to export only the md:EntityDescriptor
204+
$i = strpos($metaxml, '<md:EntityDescriptor');
205+
$metaxml = substr($metaxml, $i ? $i : 0);
211206

212-
$t->data['clipboard.js'] = true;
213-
$t->data['available_certs'] = $availableCerts;
214-
$certdata = [];
215-
foreach (array_keys($availableCerts) as $availableCert) {
216-
$certdata[$availableCert]['name'] = $availableCert;
217-
$certdata[$availableCert]['url'] = Module::getModuleURL('saml/idp/certs.php') .
218-
'/' . $availableCert;
207+
// 22 = strlen('</md:EntityDescriptor>')
208+
$i = strrpos($metaxml, '</md:EntityDescriptor>');
209+
$metaxml = substr($metaxml, 0, $i ? $i + 22 : 0);
219210

220-
$certdata[$availableCert]['comment'] = '';
221-
}
222-
$t->data['certdata'] = $certdata;
223-
$t->data['headerString'] = Translate::noop('metadata_adfs-idp');
224-
$httpUtils = new Utils\HTTP();
225-
$t->data['metaurl'] = $httpUtils->getSelfURLNoQuery();
226-
$t->data['metadata'] = htmlspecialchars($metaxml);
227-
$t->data['metadataflat'] = htmlspecialchars($metaflat);
228-
229-
return $t;
230-
} else {
231-
// make sure to export only the md:EntityDescriptor
232-
$i = strpos($metaxml, '<md:EntityDescriptor');
233-
$metaxml = substr($metaxml, $i ? $i : 0);
211+
$response = new Response();
212+
$response->headers->set('Content-Type', 'application/samlmetadata+xml');
213+
$response->setContent($metaxml);
234214

235-
// 22 = strlen('</md:EntityDescriptor>')
236-
$i = strrpos($metaxml, '</md:EntityDescriptor>');
237-
$metaxml = substr($metaxml, 0, $i ? $i + 22 : 0);
238-
239-
$response = new Response();
240-
$response->headers->set('Content-Type', 'application/samlmetadata+xml');
241-
$response->setContent($metaxml);
242-
243-
return $response;
244-
}
215+
return $response;
245216
} catch (Exception $exception) {
246217
throw new SspError\Error('METADATA', $exception);
247218
}

src/IdP/ADFS.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ private static function generateResponse(
118118
$name,
119119
'http://schemas.xmlsoap.org/claims'
120120
);
121+
$namespace = htmlspecialchars($namespace);
122+
$name = htmlspecialchars($name);
121123
foreach ($values as $value) {
122124
if ((!isset($value)) || ($value === '')) {
123125
continue;

tests/src/Controller/AdfsControllerTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ public function testMissingMetadataForRP(): void
8686
$c = new Controller\Adfs($this->config, $this->session);
8787

8888
$this->expectException(Error\MetadataNotFound::class);
89-
// This line breaks tests in PHP 8.1
90-
//$this->expectExceptionMessage("METADATANOTFOUND('%ENTITYID%' => '\'urn:example-sp\'')");
89+
$this->expectExceptionMessage("METADATANOTFOUND('%ENTITYID%' => 'urn:example-sp')");
9190

9291
$c->prp($request);
9392
}

0 commit comments

Comments
 (0)