Skip to content

Commit

Permalink
Make Optional Pretty-Printed Metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianpoplesanu authored and jzheaux committed Oct 3, 2023
1 parent cef882b commit 1acda91
Showing 1 changed file with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -72,6 +72,8 @@ public final class OpenSamlMetadataResolver implements Saml2MetadataResolver {
private Consumer<EntityDescriptorParameters> entityDescriptorCustomizer = (parameters) -> {
};

private boolean usePrettyPrint = true;

public OpenSamlMetadataResolver() {
this.entityDescriptorMarshaller = (EntityDescriptorMarshaller) XMLObjectProviderRegistrySupport
.getMarshallerFactory()
Expand Down Expand Up @@ -123,6 +125,15 @@ public void setEntityDescriptorCustomizer(Consumer<EntityDescriptorParameters> e
this.entityDescriptorCustomizer = entityDescriptorCustomizer;
}

/**
* Configure whether to pretty-print the metadata XML. This can be helpful when
* signing the metadata payload.
* @since 6.2
**/
public void setUsePrettyPrint(boolean usePrettyPrint) {
this.usePrettyPrint = usePrettyPrint;
}

private SPSSODescriptor buildSpSsoDescriptor(RelyingPartyRegistration registration) {
SPSSODescriptor spSsoDescriptor = build(SPSSODescriptor.DEFAULT_ELEMENT_NAME);
spSsoDescriptor.addSupportedProtocol(SAMLConstants.SAML20P_NS);
Expand Down Expand Up @@ -204,7 +215,10 @@ private <T> T build(QName elementName) {
private String serialize(EntityDescriptor entityDescriptor) {
try {
Element element = this.entityDescriptorMarshaller.marshall(entityDescriptor);
return SerializeSupport.prettyPrintXML(element);
if (this.usePrettyPrint) {
return SerializeSupport.prettyPrintXML(element);
}
return SerializeSupport.nodeToString(element);
}
catch (Exception ex) {
throw new Saml2Exception(ex);
Expand All @@ -214,7 +228,10 @@ private String serialize(EntityDescriptor entityDescriptor) {
private String serialize(EntitiesDescriptor entities) {
try {
Element element = this.entitiesDescriptorMarshaller.marshall(entities);
return SerializeSupport.prettyPrintXML(element);
if (this.usePrettyPrint) {
return SerializeSupport.prettyPrintXML(element);
}
return SerializeSupport.nodeToString(element);
}
catch (Exception ex) {
throw new Saml2Exception(ex);
Expand Down

0 comments on commit 1acda91

Please sign in to comment.