|
5 | 5 | namespace SimpleSAML\Module\adfs\Controller; |
6 | 6 |
|
7 | 7 | use Exception; |
8 | | -use SimpleSAML\Configuration; |
| 8 | +use SimpleSAML\{Configuration, IdP, Logger, Metadata, Module, Session, Utils}; |
9 | 9 | use SimpleSAML\Error as SspError; |
10 | | -use SimpleSAML\IdP; |
11 | | -use SimpleSAML\Logger; |
12 | | -use SimpleSAML\Metadata; |
13 | | -use SimpleSAML\Module; |
14 | 10 | use SimpleSAML\Module\adfs\IdP\ADFS as ADFS_IDP; |
15 | | -use SimpleSAML\SAML2\Constants as C; |
16 | | -use SimpleSAML\Session; |
17 | | -use SimpleSAML\Utils; |
18 | | -use Symfony\Component\HttpFoundation\Request; |
19 | | -use Symfony\Component\HttpFoundation\Response; |
20 | | -use Symfony\Component\HttpFoundation\StreamedResponse; |
| 11 | +use SimpleSAML\Module\adfs\IdP\MetadataBuilder; |
| 12 | +use Symfony\Component\HttpFoundation\{Request, Response, StreamedResponse}; |
21 | 13 |
|
22 | 14 | /** |
23 | 15 | * Controller class for the adfs module. |
@@ -79,123 +71,14 @@ public function metadata(Request $request): Response |
79 | 71 | } |
80 | 72 | $idpmeta = $this->metadata->getMetaDataConfig($idpentityid, 'adfs-idp-hosted'); |
81 | 73 |
|
82 | | - $availableCerts = []; |
83 | | - $keys = []; |
84 | | - $certInfo = $this->cryptoUtils->loadPublicKey($idpmeta, false, 'new_'); |
| 74 | + $builder = new MetadataBuilder($this->config, $idpmeta); |
85 | 75 |
|
86 | | - if ($certInfo !== null) { |
87 | | - $availableCerts['new_idp.crt'] = $certInfo; |
88 | | - $keys[] = [ |
89 | | - 'type' => 'X509Certificate', |
90 | | - 'signing' => true, |
91 | | - 'encryption' => true, |
92 | | - 'X509Certificate' => $certInfo['certData'], |
93 | | - ]; |
94 | | - $hasNewCert = true; |
95 | | - } else { |
96 | | - $hasNewCert = false; |
97 | | - } |
98 | | - |
99 | | - /** @var array $certInfo */ |
100 | | - $certInfo = $this->cryptoUtils->loadPublicKey($idpmeta, true); |
101 | | - $availableCerts['idp.crt'] = $certInfo; |
102 | | - $keys[] = [ |
103 | | - 'type' => 'X509Certificate', |
104 | | - 'signing' => true, |
105 | | - 'encryption' => ($hasNewCert ? false : true), |
106 | | - 'X509Certificate' => $certInfo['certData'], |
107 | | - ]; |
108 | | - |
109 | | - if ($idpmeta->hasValue('https.certificate')) { |
110 | | - /** @var array $httpsCert */ |
111 | | - $httpsCert = $this->cryptoUtils->loadPublicKey($idpmeta, true, 'https.'); |
112 | | - Assert::keyExists($httpsCert, 'certData'); |
113 | | - $availableCerts['https.crt'] = $httpsCert; |
114 | | - $keys[] = [ |
115 | | - 'type' => 'X509Certificate', |
116 | | - 'signing' => true, |
117 | | - 'encryption' => false, |
118 | | - 'X509Certificate' => $httpsCert['certData'], |
119 | | - ]; |
120 | | - } |
121 | | - |
122 | | - $adfs_service_location = Module::getModuleURL('adfs') . '/idp/prp.php'; |
123 | | - $metaArray = [ |
124 | | - 'metadata-set' => 'adfs-idp-remote', |
125 | | - 'entityid' => $idpentityid, |
126 | | - 'SingleSignOnService' => [ |
127 | | - 0 => [ |
128 | | - 'Binding' => C::BINDING_HTTP_REDIRECT, |
129 | | - 'Location' => $adfs_service_location, |
130 | | - ], |
131 | | - ], |
132 | | - 'SingleLogoutService' => [ |
133 | | - 0 => [ |
134 | | - 'Binding' => C::BINDING_HTTP_REDIRECT, |
135 | | - 'Location' => $adfs_service_location, |
136 | | - ], |
137 | | - ], |
138 | | - ]; |
139 | | - |
140 | | - if (count($keys) === 1) { |
141 | | - $metaArray['certData'] = $keys[0]['X509Certificate']; |
142 | | - } else { |
143 | | - $metaArray['keys'] = $keys; |
144 | | - } |
145 | | - |
146 | | - $metaArray['NameIDFormat'] = $idpmeta->getOptionalString( |
147 | | - 'NameIDFormat', |
148 | | - C::NAMEID_TRANSIENT, |
149 | | - ); |
150 | | - |
151 | | - if ($idpmeta->hasValue('OrganizationName')) { |
152 | | - $metaArray['OrganizationName'] = $idpmeta->getLocalizedString('OrganizationName'); |
153 | | - $metaArray['OrganizationDisplayName'] = $idpmeta->getOptionalLocalizedString( |
154 | | - 'OrganizationDisplayName', |
155 | | - $metaArray['OrganizationName'], |
156 | | - ); |
157 | | - |
158 | | - if (!$idpmeta->hasValue('OrganizationURL')) { |
159 | | - throw new SspError\Exception('If OrganizationName is set, OrganizationURL must also be set.'); |
160 | | - } |
161 | | - $metaArray['OrganizationURL'] = $idpmeta->getLocalizedString('OrganizationURL'); |
162 | | - } |
163 | | - |
164 | | - if ($idpmeta->hasValue('scope')) { |
165 | | - $metaArray['scope'] = $idpmeta->getArray('scope'); |
166 | | - } |
167 | | - |
168 | | - if ($idpmeta->hasValue('EntityAttributes')) { |
169 | | - $metaArray['EntityAttributes'] = $idpmeta->getArray('EntityAttributes'); |
170 | | - } |
171 | | - |
172 | | - if ($idpmeta->hasValue('UIInfo')) { |
173 | | - $metaArray['UIInfo'] = $idpmeta->getArray('UIInfo'); |
174 | | - } |
175 | | - |
176 | | - if ($idpmeta->hasValue('DiscoHints')) { |
177 | | - $metaArray['DiscoHints'] = $idpmeta->getArray('DiscoHints'); |
178 | | - } |
179 | | - |
180 | | - if ($idpmeta->hasValue('RegistrationInfo')) { |
181 | | - $metaArray['RegistrationInfo'] = $idpmeta->getArray('RegistrationInfo'); |
182 | | - } |
183 | | - |
184 | | - $metaBuilder = new Metadata\SAMLBuilder($idpentityid); |
185 | | - $metaBuilder->addSecurityTokenServiceType($metaArray); |
186 | | - $metaBuilder->addOrganizationInfo($metaArray); |
187 | | - $technicalContactEmail = $this->config->getOptionalString('technicalcontact_email', null); |
188 | | - if ( $technicalContactEmail !== null && $technicalContactEmail !== '[email protected]') { |
189 | | - $metaBuilder->addContact(Utils\Config\Metadata::getContact([ |
190 | | - 'emailAddress' => $technicalContactEmail, |
191 | | - 'givenName' => $this->config->getOptionalString('technicalcontact_name', null), |
192 | | - 'contactType' => 'technical', |
193 | | - ])); |
194 | | - } |
195 | | - $metaxml = $metaBuilder->getEntityDescriptorText(); |
| 76 | + $document = $builder->buildDocument()->toXML(); |
| 77 | + // Some products like DirX are known to break on pretty-printed XML |
| 78 | + $document->ownerDocument->formatOutput = false; |
| 79 | + $document->ownerDocument->encoding = 'UTF-8'; |
196 | 80 |
|
197 | | - // sign the metadata if enabled |
198 | | - $metaxml = Metadata\Signer::sign($metaxml, $idpmeta->toArray(), 'ADFS IdP'); |
| 81 | + $metaxml = $document->ownerDocument->saveXML(); |
199 | 82 |
|
200 | 83 | $response = new Response(); |
201 | 84 | $response->setEtag(hash('sha256', $metaxml)); |
|
0 commit comments