119
119
import io .fusionauth .samlv2 .domain .jaxb .oasis .metadata .KeyTypes ;
120
120
import io .fusionauth .samlv2 .domain .jaxb .oasis .metadata .RoleDescriptorType ;
121
121
import io .fusionauth .samlv2 .domain .jaxb .oasis .metadata .SPSSODescriptorType ;
122
+ import io .fusionauth .samlv2 .domain .jaxb .oasis .metadata .SSODescriptorType ;
122
123
import io .fusionauth .samlv2 .domain .jaxb .oasis .protocol .AuthnRequestType ;
123
124
import io .fusionauth .samlv2 .domain .jaxb .oasis .protocol .NameIDPolicyType ;
124
125
import io .fusionauth .samlv2 .domain .jaxb .oasis .protocol .ObjectFactory ;
@@ -357,23 +358,8 @@ public String buildMetadataResponse(MetaData metaData) throws SAMLException {
357
358
idp .getSingleLogoutService ().add (logOut );
358
359
});
359
360
360
- metaData .idp .certificates .forEach (cert -> {
361
- KeyDescriptorType key = new KeyDescriptorType ();
362
- key .setUse (KeyTypes .SIGNING );
363
- KeyInfoType info = new KeyInfoType ();
364
- key .setKeyInfo (info );
365
- X509DataType data = new X509DataType ();
366
- info .getContent ().add (DSIG_OBJECT_FACTORY .createX509Data (data ));
367
-
368
- try {
369
- JAXBElement <byte []> certElement = DSIG_OBJECT_FACTORY .createX509DataTypeX509Certificate (cert .getEncoded ());
370
- data .getX509IssuerSerialOrX509SKIOrX509SubjectName ().add (certElement );
371
- idp .getKeyDescriptor ().add (key );
372
- } catch (Exception e ) {
373
- // Rethrow
374
- throw new IllegalArgumentException (e );
375
- }
376
- });
361
+ // Add certificates
362
+ addKeyDescriptors (idp , metaData .idp .certificates );
377
363
378
364
root .getRoleDescriptorOrIDPSSODescriptorOrSPSSODescriptor ().add (idp );
379
365
}
@@ -395,6 +381,9 @@ public String buildMetadataResponse(MetaData metaData) throws SAMLException {
395
381
sp .getNameIDFormat ().add (metaData .sp .nameIDFormat .toSAMLFormat ());
396
382
}
397
383
384
+ // Add certificates
385
+ addKeyDescriptors (sp , metaData .sp .certificates );
386
+
398
387
root .getRoleDescriptorOrIDPSSODescriptorOrSPSSODescriptor ().add (sp );
399
388
}
400
389
@@ -637,6 +626,26 @@ public AuthenticationResponse parseResponse(String encodedResponse, boolean veri
637
626
return response ;
638
627
}
639
628
629
+ private void addKeyDescriptors (SSODescriptorType descriptor , List <Certificate > certificates ) {
630
+ certificates .forEach (cert -> {
631
+ KeyDescriptorType key = new KeyDescriptorType ();
632
+ key .setUse (KeyTypes .SIGNING );
633
+ KeyInfoType info = new KeyInfoType ();
634
+ key .setKeyInfo (info );
635
+ X509DataType data = new X509DataType ();
636
+ info .getContent ().add (DSIG_OBJECT_FACTORY .createX509Data (data ));
637
+
638
+ try {
639
+ JAXBElement <byte []> certElement = DSIG_OBJECT_FACTORY .createX509DataTypeX509Certificate (cert .getEncoded ());
640
+ data .getX509IssuerSerialOrX509SKIOrX509SubjectName ().add (certElement );
641
+ descriptor .getKeyDescriptor ().add (key );
642
+ } catch (Exception e ) {
643
+ // Rethrow
644
+ throw new IllegalArgumentException (e );
645
+ }
646
+ });
647
+ }
648
+
640
649
private String attributeToString (Object attribute ) {
641
650
if (attribute == null ) {
642
651
return null ;
0 commit comments