1111use SimpleSAML \Configuration ;
1212use SimpleSAML \Logger ;
1313use SimpleSAML \Module ;
14+ use SimpleSAML \SAML2 \Constants as C_SAML2 ;
1415use SimpleSAML \SAML2 \Exception \ArrayValidationException ;
16+ use SimpleSAML \SAML2 \Type \EntityIDValue ;
17+ use SimpleSAML \SAML2 \Type \KeyTypesValue ;
18+ use SimpleSAML \SAML2 \Type \SAMLAnyURIListValue ;
19+ use SimpleSAML \SAML2 \Type \SAMLAnyURIValue ;
20+ use SimpleSAML \SAML2 \Type \SAMLStringValue ;
1521use SimpleSAML \SAML2 \XML \md \AbstractMetadataDocument ;
1622use SimpleSAML \SAML2 \XML \md \ContactPerson ;
1723use SimpleSAML \SAML2 \XML \md \EntityDescriptor ;
2632use SimpleSAML \SAML2 \XML \saml \AttributeValue ;
2733use SimpleSAML \SAML2 \XML \shibmd \Scope ;
2834use SimpleSAML \Utils ;
29- use SimpleSAML \WSSecurity \Constants as C ;
30- use SimpleSAML \WSSecurity \XML \fed \PassiveRequestorEndpoint ;
31- use SimpleSAML \WSSecurity \XML \fed \SecurityTokenServiceEndpoint ;
32- use SimpleSAML \WSSecurity \XML \fed \SecurityTokenServiceType ;
33- use SimpleSAML \WSSecurity \XML \fed \TokenType ;
34- use SimpleSAML \WSSecurity \XML \fed \TokenTypesOffered ;
35- use SimpleSAML \WSSecurity \XML \wsa_200508 \Address ;
36- use SimpleSAML \WSSecurity \XML \wsa_200508 \EndpointReference ;
35+ use SimpleSAML \WebServices \Addressing \XML \wsa_200508 \Address ;
36+ use SimpleSAML \WebServices \Addressing \XML \wsa_200508 \EndpointReference ;
37+ use SimpleSAML \WebServices \Federation \Constants as C_FED ;
38+ use SimpleSAML \WebServices \Federation \XML \fed \PassiveRequestorEndpoint ;
39+ use SimpleSAML \WebServices \Federation \XML \fed \SecurityTokenServiceEndpoint ;
40+ use SimpleSAML \WebServices \Federation \XML \fed \SecurityTokenServiceType ;
41+ use SimpleSAML \WebServices \Federation \XML \fed \TokenType ;
42+ use SimpleSAML \WebServices \Federation \XML \fed \TokenTypesOffered ;
43+ use SimpleSAML \WebServices \Trust \Constants as C_TRUST ;
3744use SimpleSAML \XML \Chunk ;
45+ use SimpleSAML \XMLSchema \Type \AnyURIValue ;
46+ use SimpleSAML \XMLSchema \Type \BooleanValue ;
47+ use SimpleSAML \XMLSchema \Type \IDValue ;
48+ use SimpleSAML \XMLSchema \Type \NCNameValue ;
49+ use SimpleSAML \XMLSchema \Type \QNameValue ;
3850use SimpleSAML \XMLSecurity \Alg \Signature \SignatureAlgorithmFactory ;
51+ use SimpleSAML \XMLSecurity \Constants as C_XMLSEC ;
3952use SimpleSAML \XMLSecurity \Key \PrivateKey ;
4053use SimpleSAML \XMLSecurity \XML \ds \KeyInfo ;
4154use SimpleSAML \XMLSecurity \XML \ds \KeyName ;
@@ -81,11 +94,13 @@ public function buildDocument(): EntityDescriptor
8194 $ contactPerson = $ this ->getContactPerson ();
8295 $ organization = $ this ->getOrganization ();
8396 $ roleDescriptor = $ this ->getRoleDescriptor ();
97+ $ extensions = $ this ->getExtensions ();
8498
8599 $ randomUtils = new Utils \Random ();
86100 $ entityDescriptor = new EntityDescriptor (
87- id: $ randomUtils ->generateID (),
88- entityId: $ entityId ,
101+ id: IDValue::fromString ($ randomUtils ->generateID ()),
102+ extensions: $ extensions ,
103+ entityId: EntityIDValue::fromString ($ entityId ),
89104 contactPerson: $ contactPerson ,
90105 organization: $ organization ,
91106 roleDescriptor: $ roleDescriptor ,
@@ -110,7 +125,7 @@ protected function signDocument(AbstractMetadataDocument $document): AbstractMet
110125 /** @var array<mixed> $keyArray */
111126 $ keyArray = $ cryptoUtils ->loadPrivateKey ($ this ->config , true , 'metadata.sign. ' );
112127 $ certArray = $ cryptoUtils ->loadPublicKey ($ this ->config , false , 'metadata.sign. ' );
113- $ algo = $ this ->config ->getOptionalString ('metadata.sign.algorithm ' , C ::SIG_RSA_SHA256 );
128+ $ algo = $ this ->config ->getOptionalString ('metadata.sign.algorithm ' , C_XMLSEC ::SIG_RSA_SHA256 );
114129
115130 $ key = PrivateKey::fromFile ($ keyArray ['PEM ' ], $ keyArray ['password ' ] ?? '' );
116131 $ signer = (new SignatureAlgorithmFactory ())->getAlgorithm ($ algo , $ key );
@@ -124,7 +139,7 @@ protected function signDocument(AbstractMetadataDocument $document): AbstractMet
124139 ]);
125140 }
126141
127- $ document ->sign ($ signer , C ::C14N_EXCLUSIVE_WITHOUT_COMMENTS , $ keyInfo );
142+ $ document ->sign ($ signer , C_XMLSEC ::C14N_EXCLUSIVE_WITHOUT_COMMENTS , $ keyInfo );
128143 return $ document ;
129144 }
130145
@@ -190,24 +205,35 @@ private function getRoleDescriptor(): array
190205 /**
191206 * This method builds the SecurityTokenService element
192207 *
193- * @return \SimpleSAML\WSSecurity \XML\fed\SecurityTokenServiceType
208+ * @return \SimpleSAML\WebServices\Federation \XML\fed\SecurityTokenServiceType
194209 */
195210 public function getSecurityTokenService (): SecurityTokenServiceType
196211 {
197212 $ defaultEndpoint = Module::getModuleURL ('adfs ' ) . '/idp/prp.php ' ;
198213
199214 return new SecurityTokenServiceType (
200- protocolSupportEnumeration: [C::NS_TRUST_200512 , C::NS_TRUST_200502 , C::NS_FED ],
215+ QNameValue::fromParts (
216+ NCNameValue::fromString (SecurityTokenServiceType::getLocalName ()),
217+ AnyURIValue::fromString (SecurityTokenServiceType::NS ),
218+ NCNameValue::fromString (SecurityTokenServiceType::NS_PREFIX ),
219+ ),
220+ protocolSupportEnumeration: SAMLAnyURIListValue::fromArray (
221+ [C_TRUST ::NS_TRUST_200512 , C_TRUST ::NS_TRUST_200502 , C_FED ::NS_FED ],
222+ ),
201223 keyDescriptors: $ this ->getKeyDescriptor (),
202- tokenTypesOffered: new TokenTypesOffered ([new TokenType ('urn:oasis:names:tc:SAML:1.0:assertion ' )]),
224+ tokenTypesOffered: new TokenTypesOffered (
225+ [
226+ new TokenType (AnyURIValue::fromString ('urn:oasis:names:tc:SAML:1.0:assertion ' )),
227+ ],
228+ ),
203229 securityTokenServiceEndpoint: [
204230 new SecurityTokenServiceEndpoint ([
205- new EndpointReference (new Address ($ defaultEndpoint )),
231+ new EndpointReference (new Address (AnyURIValue:: fromString ( $ defaultEndpoint) )),
206232 ]),
207233 ],
208234 passiveRequestorEndpoint: [
209235 new PassiveRequestorEndpoint ([
210- new EndpointReference (new Address ($ defaultEndpoint )),
236+ new EndpointReference (new Address (AnyURIValue:: fromString ( $ defaultEndpoint) )),
211237 ]),
212238 ],
213239 );
@@ -282,8 +308,11 @@ private function getExtensions(): ?Extensions
282308
283309 if ($ this ->metadata ->hasValue ('scope ' )) {
284310 foreach ($ this ->metadata ->getArray ('scope ' ) as $ scopetext ) {
285- $ isRegexpScope = (1 === preg_match ('/[\$\^\)\(\*\| \\\\]/ ' , $ scopetext ));
286- $ extensions [] = new Scope ($ scopetext , $ isRegexpScope );
311+ $ isRegexpScope = 1 === preg_match ('/[\$\^\)\(\*\| \\\\]/ ' , $ scopetext );
312+ $ extensions [] = new Scope (
313+ SAMLStringValue::fromString ($ scopetext ),
314+ BooleanValue::fromBoolean ($ isRegexpScope ),
315+ );
287316 }
288317 }
289318
@@ -298,14 +327,16 @@ private function getExtensions(): ?Extensions
298327 // Attribute names that is not URI is prefixed as this: '{nameformat}name'
299328 if (preg_match ('/^\{(.*?)\}(.*)$/ ' , $ attributeName , $ matches )) {
300329 $ attr [] = new Attribute (
301- name: $ matches [2 ],
302- nameFormat: $ matches [1 ] === C::NAMEFORMAT_UNSPECIFIED ? null : $ matches [1 ],
330+ name: SAMLStringValue::fromString ($ matches [2 ]),
331+ nameFormat: SAMLAnyURIValue::fromString (
332+ $ matches [1 ] === C_SAML2 ::NAMEFORMAT_UNSPECIFIED ? null : $ matches [1 ],
333+ ),
303334 attributeValue: $ attrValues ,
304335 );
305336 } else {
306337 $ attr [] = new Attribute (
307- name: $ attributeName ,
308- nameFormat: C:: NAMEFORMAT_UNSPECIFIED ,
338+ name: SAMLStringValue:: fromString ( $ attributeName) ,
339+ nameFormat: SAMLAnyURIValue:: fromString ( C_SAML2 :: NAMEFORMAT_UNSPECIFIED ) ,
309340 attributeValue: $ attrValues ,
310341 );
311342 }
@@ -364,17 +395,17 @@ private static function buildKeyDescriptor(string $use, string $x509Cert, ?strin
364395 Assert::oneOf ($ use , ['encryption ' , 'signing ' ]);
365396 $ info = [
366397 new X509Data ([
367- new X509Certificate ($ x509Cert ),
398+ X509Certificate:: fromString ($ x509Cert ),
368399 ]),
369400 ];
370401
371402 if ($ keyName !== null ) {
372- $ info [] = new KeyName ($ keyName );
403+ $ info [] = KeyName:: fromString ($ keyName );
373404 }
374405
375406 return new KeyDescriptor (
376407 new KeyInfo ($ info ),
377- $ use ,
408+ KeyTypesValue:: fromString ( $ use) ,
378409 );
379410 }
380411}
0 commit comments