mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-05-31 09:12:14 +00:00
Make Optional Pretty-Printed Metadata
Closes gh-13715
This commit is contained in:
parent
cc6010876f
commit
823bc971f5
@ -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.
|
||||
@ -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()
|
||||
@ -123,6 +125,15 @@ public final class OpenSamlMetadataResolver implements Saml2MetadataResolver {
|
||||
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);
|
||||
@ -204,7 +215,10 @@ public final class OpenSamlMetadataResolver implements Saml2MetadataResolver {
|
||||
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);
|
||||
@ -214,7 +228,10 @@ public final class OpenSamlMetadataResolver implements Saml2MetadataResolver {
|
||||
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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user