From b4127bb7d7a54c80e67681f78b84b4fc001b5efb Mon Sep 17 00:00:00 2001 From: Luca Leonardo Scorcia Date: Fri, 3 Apr 2020 20:00:25 -0400 Subject: [PATCH] KEYCLOAK-13713 Define a write method for XMLGregorianCalendar attributes --- .../core/saml/v2/writers/BaseWriter.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/saml-core/src/main/java/org/keycloak/saml/processing/core/saml/v2/writers/BaseWriter.java b/saml-core/src/main/java/org/keycloak/saml/processing/core/saml/v2/writers/BaseWriter.java index 14c130ab1b..878697cf0b 100755 --- a/saml-core/src/main/java/org/keycloak/saml/processing/core/saml/v2/writers/BaseWriter.java +++ b/saml-core/src/main/java/org/keycloak/saml/processing/core/saml/v2/writers/BaseWriter.java @@ -172,6 +172,8 @@ public class BaseWriter { writeStringAttributeValue((String) attributeValue); } else if (attributeValue instanceof NameIDType) { writeNameIDTypeAttributeValue((NameIDType) attributeValue); + } else if (attributeValue instanceof XMLGregorianCalendar) { + writeDateAttributeValue((XMLGregorianCalendar) attributeValue); } else throw logger.writerUnsupportedAttributeValueError(attributeValue.getClass().getName()); } else { @@ -203,6 +205,22 @@ public class BaseWriter { StaxUtil.writeEndElement(writer); } + public void writeDateAttributeValue(XMLGregorianCalendar attributeValue) throws ProcessingException { + StaxUtil.writeStartElement(writer, ASSERTION_PREFIX, JBossSAMLConstants.ATTRIBUTE_VALUE.get(), ASSERTION_NSURI.get()); + + StaxUtil.writeNameSpace(writer, JBossSAMLURIConstants.XSI_PREFIX.get(), JBossSAMLURIConstants.XSI_NSURI.get()); + StaxUtil.writeNameSpace(writer, "xs", JBossSAMLURIConstants.XMLSCHEMA_NSURI.get()); + StaxUtil.writeAttribute(writer, "xsi", JBossSAMLURIConstants.XSI_NSURI.get(), "type", "xs:" + attributeValue.getXMLSchemaType().getLocalPart()); + + if (attributeValue == null) { + StaxUtil.writeAttribute(writer, "xsi", JBossSAMLURIConstants.XSI_NSURI.get(), "nil", "true"); + } else { + StaxUtil.writeCharacters(writer, attributeValue.toString()); + } + + StaxUtil.writeEndElement(writer); + } + public void writeLocalizedNameType(LocalizedNameType localizedNameType, QName startElement) throws ProcessingException { StaxUtil.writeStartElement(writer, startElement.getPrefix(), startElement.getLocalPart(), startElement.getNamespaceURI());