|
9 | 9 | use SimpleSAML\Error as SspError; |
10 | 10 | use SimpleSAML\Module\adfs\IdP\ADFS as ADFS_IDP; |
11 | 11 | use SimpleSAML\Module\adfs\IdP\MetadataBuilder; |
| 12 | +use SimpleSAML\Module\adfs\IdP\PassiveIdP; |
| 13 | +use SimpleSAML\Module\adfs\MetadataExchange; |
| 14 | +use SimpleSAML\SOAP\XML\env_200305\Envelope; |
| 15 | +use SimpleSAML\XML\DOMDocumentFactory; |
12 | 16 | use Symfony\Component\HttpFoundation\{Request, Response, StreamedResponse}; |
13 | 17 |
|
14 | 18 | /** |
@@ -77,7 +81,6 @@ public function metadata(Request $request): Response |
77 | 81 | // Some products like DirX are known to break on pretty-printed XML |
78 | 82 | $document->ownerDocument->formatOutput = false; |
79 | 83 | $document->ownerDocument->encoding = 'UTF-8'; |
80 | | - |
81 | 84 | $metaxml = $document->ownerDocument->saveXML(); |
82 | 85 |
|
83 | 86 | $response = new Response(); |
@@ -137,4 +140,96 @@ function () use ($idp, /** @scrutinizer ignore-type */ $assocId, $relayState, $l |
137 | 140 | } |
138 | 141 | throw new SspError\BadRequest("Missing parameter 'wa' or 'assocId' in request."); |
139 | 142 | } |
| 143 | + |
| 144 | + |
| 145 | + /** |
| 146 | + * @param \Symfony\Component\HttpFoundation\Request $request |
| 147 | + * @return \Symfony\Component\HttpFoundation\Response |
| 148 | + */ |
| 149 | + public function mex(Request $request): Response |
| 150 | + { |
| 151 | + if (!$this->config->getOptionalBoolean('enable.adfs-idp', false)) { |
| 152 | + throw new SspError\Error('NOACCESS'); |
| 153 | + } |
| 154 | + |
| 155 | + // check if valid local session exists |
| 156 | + $authUtils = new Utils\Auth(); |
| 157 | + if ($this->config->getOptionalBoolean('admin.protectmetadata', false) && !$authUtils->isAdmin()) { |
| 158 | + return new StreamedResponse([$authUtils, 'requireAdmin']); |
| 159 | + } |
| 160 | + |
| 161 | + $mexBuilder = new MetadataExchange(); |
| 162 | + $document = $mexBuilder->buildDocument()->toXML(); |
| 163 | + // Some products like DirX are known to break on pretty-printed XML |
| 164 | + $document->ownerDocument->formatOutput = false; |
| 165 | + $document->ownerDocument->encoding = 'UTF-8'; |
| 166 | + |
| 167 | + $document->setAttributeNS( |
| 168 | + 'http://www.w3.org/2000/xmlns/', |
| 169 | + 'xmlns:tns', |
| 170 | + 'http://schemas.microsoft.com/ws/2008/06/identity/securitytokenservice', |
| 171 | + ); |
| 172 | + |
| 173 | + $document->setAttributeNS( |
| 174 | + 'http://www.w3.org/2000/xmlns/', |
| 175 | + 'xmlns:soapenc', |
| 176 | + 'http://schemas.xmlsoap.org/soap/encoding/', |
| 177 | + ); |
| 178 | + |
| 179 | + $document->setAttributeNS( |
| 180 | + 'http://www.w3.org/2000/xmlns/', |
| 181 | + 'xmlns:msc', |
| 182 | + 'http://schemas.microsoft.com/ws/2005/12/wsdl/contract', |
| 183 | + ); |
| 184 | + |
| 185 | + $document->setAttributeNS( |
| 186 | + 'http://www.w3.org/2000/xmlns/', |
| 187 | + 'xmlns:wsam', |
| 188 | + 'http://www.w3.org/2007/05/addressing/metadata', |
| 189 | + ); |
| 190 | + |
| 191 | + $document->setAttributeNS( |
| 192 | + 'http://www.w3.org/2000/xmlns/', |
| 193 | + 'xmlns:wsap', |
| 194 | + 'http://schemas.xmlsoap.org/ws/2004/08/addressing/policy', |
| 195 | + ); |
| 196 | + |
| 197 | + $metaxml = $document->ownerDocument->saveXML(); |
| 198 | + |
| 199 | + $response = new Response(); |
| 200 | + $response->setEtag(hash('sha256', $metaxml)); |
| 201 | + $response->setPublic(); |
| 202 | + if ($response->isNotModified($request)) { |
| 203 | + return $response; |
| 204 | + } |
| 205 | + $response->headers->set('Content-Type', 'text/xml'); |
| 206 | + $response->setContent($metaxml); |
| 207 | + |
| 208 | + return $response; |
| 209 | + } |
| 210 | + |
| 211 | + |
| 212 | + /** |
| 213 | + * @param \Symfony\Component\HttpFoundation\Request $request |
| 214 | + * @return \Symfony\Component\HttpFoundation\Response |
| 215 | + */ |
| 216 | + public function usernamemixed(Request $request): Response |
| 217 | + { |
| 218 | + if (!$this->config->getOptionalBoolean('enable.adfs-idp', false)) { |
| 219 | + throw new SspError\Error('NOACCESS'); |
| 220 | + } |
| 221 | + |
| 222 | + $soapMessage = $request->getContent(); |
| 223 | + if ($soapMessage === false) { |
| 224 | + throw new SspError\BadRequest('Missing SOAP-content.'); |
| 225 | + } |
| 226 | + |
| 227 | + $domDocument = DOMDocumentFactory::fromString($soapMessage); |
| 228 | + $soapEnvelope = Envelope::fromXML($domDocument->documentElement); |
| 229 | + |
| 230 | + $idpEntityId = $this->metadata->getMetaDataCurrentEntityID('adfs-idp-hosted'); |
| 231 | + $idp = PassiveIdP::getById($this->config, 'adfs:' . $idpEntityId); |
| 232 | + |
| 233 | + return ADFS_IDP::receivePassiveAuthnRequest($request, $soapEnvelope, $idp); |
| 234 | + } |
140 | 235 | } |
0 commit comments