KEYCLOAK-17329 Allow emitting custom elements in SAML metadata extensions

This commit is contained in:
Luca Leonardo Scorcia 2021-03-04 08:47:06 -05:00 committed by Hynek Mlnařík
parent fc29a39e5a
commit dc359e56d4
2 changed files with 30 additions and 8 deletions

View file

@ -90,6 +90,18 @@ public class ExtensionsType {
return Collections.unmodifiableList(this.any);
}
public List<Element> getDomElements() {
List<Element> output = new ArrayList<Element>();
for (Object o : this.any) {
if (o instanceof Element) {
output.add((Element) o);
}
}
return Collections.unmodifiableList(output);
}
public EntityAttributes getEntityAttributes() {
for (Object o : this.any) {
if (o instanceof EntityAttributes) {

View file

@ -90,7 +90,7 @@ public class SAMLMetadataWriter extends BaseWriter {
}
ExtensionsType extensions = entities.getExtensions();
if (extensions != null) {
StaxUtil.writeDOMElement(writer, extensions.getElement());
write(extensions);
}
List<Object> entityDescriptors = entities.getEntityDescriptor();
@ -126,7 +126,7 @@ public class SAMLMetadataWriter extends BaseWriter {
}
ExtensionsType extensions = entityDescriptor.getExtensions();
if (extensions != null) {
StaxUtil.writeDOMElement(writer, extensions.getElement());
write(extensions);
}
List<EntityDescriptorType.EDTChoiceType> choiceTypes = entityDescriptor.getChoiceType();
@ -297,7 +297,7 @@ public class SAMLMetadataWriter extends BaseWriter {
}
ExtensionsType extensions = attributeAuthority.getExtensions();
if (extensions != null) {
StaxUtil.writeDOMElement(writer, extensions.getElement());
write(extensions);
}
List<KeyDescriptorType> keyDescriptorList = attributeAuthority.getKeyDescriptor();
@ -392,7 +392,7 @@ public class SAMLMetadataWriter extends BaseWriter {
ExtensionsType extensions = org.getExtensions();
if (extensions != null) {
StaxUtil.writeDOMElement(writer, extensions.getElement());
write(extensions);
}
// Write the name
@ -434,13 +434,14 @@ public class SAMLMetadataWriter extends BaseWriter {
public void write(ContactType contact) throws ProcessingException {
StaxUtil.writeStartElement(writer, METADATA_PREFIX, JBossSAMLConstants.CONTACT_PERSON.get(), JBossSAMLURIConstants.METADATA_NSURI.get());
ExtensionsType extensions = contact.getExtensions();
if (extensions != null) {
StaxUtil.writeDOMElement(writer, extensions.getElement());
}
ContactTypeType attribs = contact.getContactType();
StaxUtil.writeAttribute(writer, JBossSAMLConstants.CONTACT_TYPE.get(), attribs.value());
ExtensionsType extensions = contact.getExtensions();
if (extensions != null) {
write(extensions);
}
// Write the name
String company = contact.getCompany();
if (company != null) {
@ -480,6 +481,15 @@ public class SAMLMetadataWriter extends BaseWriter {
StaxUtil.flush(writer);
}
public void write(ExtensionsType extensions) throws ProcessingException {
StaxUtil.writeStartElement(writer, METADATA_PREFIX, JBossSAMLConstants.EXTENSIONS__METADATA.get(), JBossSAMLURIConstants.METADATA_NSURI.get());
for (Element extension : extensions.getDomElements())
StaxUtil.writeDOMElement(writer, extension);
StaxUtil.writeEndElement(writer);
}
public void writeKeyDescriptor(KeyDescriptorType keyDescriptor) throws ProcessingException {
StaxUtil.writeStartElement(writer, METADATA_PREFIX, JBossSAMLConstants.KEY_DESCRIPTOR.get(), JBossSAMLURIConstants.METADATA_NSURI.get());