Skip to content

Commit eb75ed9

Browse files
committed
Add option to add Key Descriptors to the SP metadata.
1 parent c63f32d commit eb75ed9

File tree

3 files changed

+29
-18
lines changed

3 files changed

+29
-18
lines changed

build.savant

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
savantVersion = "1.0.0"
1717

18-
project(group: "io.fusionauth", name: "fusionauth-samlv2", version: "0.5.2", licenses: ["ApacheV2_0"]) {
18+
project(group: "io.fusionauth", name: "fusionauth-samlv2", version: "0.5.3", licenses: ["ApacheV2_0"]) {
1919
workflow {
2020
standard()
2121
}

src/main/java/io/fusionauth/samlv2/domain/MetaData.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ public static class SPMetaData {
4545

4646
public boolean authnRequestsSigned;
4747

48+
public List<Certificate> certificates = new ArrayList<>();
49+
4850
public NameIDFormat nameIDFormat;
4951

5052
public boolean wantAssertionsSigned;

src/main/java/io/fusionauth/samlv2/service/DefaultSAMLv2Service.java

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@
119119
import io.fusionauth.samlv2.domain.jaxb.oasis.metadata.KeyTypes;
120120
import io.fusionauth.samlv2.domain.jaxb.oasis.metadata.RoleDescriptorType;
121121
import io.fusionauth.samlv2.domain.jaxb.oasis.metadata.SPSSODescriptorType;
122+
import io.fusionauth.samlv2.domain.jaxb.oasis.metadata.SSODescriptorType;
122123
import io.fusionauth.samlv2.domain.jaxb.oasis.protocol.AuthnRequestType;
123124
import io.fusionauth.samlv2.domain.jaxb.oasis.protocol.NameIDPolicyType;
124125
import io.fusionauth.samlv2.domain.jaxb.oasis.protocol.ObjectFactory;
@@ -357,23 +358,8 @@ public String buildMetadataResponse(MetaData metaData) throws SAMLException {
357358
idp.getSingleLogoutService().add(logOut);
358359
});
359360

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);
377363

378364
root.getRoleDescriptorOrIDPSSODescriptorOrSPSSODescriptor().add(idp);
379365
}
@@ -395,6 +381,9 @@ public String buildMetadataResponse(MetaData metaData) throws SAMLException {
395381
sp.getNameIDFormat().add(metaData.sp.nameIDFormat.toSAMLFormat());
396382
}
397383

384+
// Add certificates
385+
addKeyDescriptors(sp, metaData.sp.certificates);
386+
398387
root.getRoleDescriptorOrIDPSSODescriptorOrSPSSODescriptor().add(sp);
399388
}
400389

@@ -637,6 +626,26 @@ public AuthenticationResponse parseResponse(String encodedResponse, boolean veri
637626
return response;
638627
}
639628

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+
640649
private String attributeToString(Object attribute) {
641650
if (attribute == null) {
642651
return null;

0 commit comments

Comments
 (0)