public String mockAssertionEncoded(Assertion assertion) throws Exception { AssertionMarshaller marshaller = new AssertionMarshaller(); Element plaintextElement = marshaller.marshall(assertion); String serializedElement = XMLHelper.nodeToString(plaintextElement); return Base64.encodeBase64URLSafeString(serializedElement.getBytes("utf-8")); }
public static String encodeSAMLRequest(XMLObject authnRequest) throws MarshallingException, IOException { Marshaller marshaller = Configuration.getMarshallerFactory() .getMarshaller(authnRequest); Element authDOM = marshaller.marshall(authnRequest); StringWriter requestWriter = new StringWriter(); XMLHelper.writeNode(authDOM, requestWriter); String requestMessage = requestWriter.toString(); Deflater deflater = new Deflater(Deflater.DEFLATED, true); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); DeflaterOutputStream deflaterOutputStream = new DeflaterOutputStream(byteArrayOutputStream, deflater); deflaterOutputStream.write(requestMessage.getBytes(Charset.forName("UTF-8"))); deflaterOutputStream.close(); String encodedRequestMessage = Base64.encodeBytes(byteArrayOutputStream.toByteArray(), Base64.DONT_BREAK_LINES); encodedRequestMessage = URLEncoder.encode(encodedRequestMessage, HttpUtils.UTF_8).trim(); return encodedRequestMessage; }
/** {@inheritDoc} */ protected void processAttribute(XMLObject samlObject, Attr attribute) throws UnmarshallingException { GeneratedKey key = (GeneratedKey) samlObject; QName attrName = XMLHelper.getNodeQName(attribute); if (GeneratedKey.SOAP11_MUST_UNDERSTAND_ATTR_NAME.equals(attrName)) { key.setSOAP11MustUnderstand(XSBooleanValue.valueOf(attribute.getValue())); } else if (GeneratedKey.SOAP11_ACTOR_ATTR_NAME.equals(attrName)) { key.setSOAP11Actor(attribute.getValue()); } else { super.processAttribute(samlObject, attribute); } }
/** {@inheritDoc} */ protected void marshallElementContent(XMLObject samlObject, Element domElement) throws MarshallingException { AssertionURIRef assertionURIRef = (AssertionURIRef) samlObject; XMLHelper.appendTextContent(domElement, assertionURIRef.getAssertionURI()); } }
/** * Constructs an attribute owned by the given document with the given name. * * @param owningDocument the owning document * @param attributeName the name of that attribute * * @return the constructed attribute */ public static Attr constructAttribute(Document owningDocument, QName attributeName) { return constructAttribute(owningDocument, attributeName.getNamespaceURI(), attributeName.getLocalPart(), attributeName.getPrefix()); }
/** {@inheritDoc} */ protected void marshallAttributes(XMLObject xmlObject, Element domElement) throws MarshallingException { SecurityTokenReference str = (SecurityTokenReference) xmlObject; if (!DatatypeHelper.isEmpty(str.getWSUId())) { XMLHelper.marshallAttribute(SecurityTokenReference.WSU_ID_ATTR_NAME, str.getWSUId(), domElement, true); } List<String> usages = str.getWSSEUsages(); if (usages != null && ! usages.isEmpty()) { XMLHelper.marshallAttribute(SecurityTokenReference.WSSE_USAGE_ATTR_NAME, usages, domElement, false); } XMLHelper.marshallAttributeMap(str.getUnknownAttributes(), domElement); }
/** * Pretty prints the XML node. * * @param node xml node to print * * @return pretty-printed xml */ public static String prettyPrintXML(Node node) { StringWriter writer = new StringWriter(); writeNode(node, writer, getPrettyPrintParams()); return writer.toString(); }
/** {@inheritDoc} */ protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { log.info("Parsing configuration for {} trust engine with id: {}", XMLHelper.getXSIType(element).getLocalPart(), element.getAttributeNS(null, "id")); List<Element> childElems = XMLHelper.getChildElementsByTagNameNS(element, SecurityNamespaceHandler.NAMESPACE, "Credential"); builder.addPropertyValue("credentials", SpringConfigurationUtils .parseCustomElements(childElems, parserContext)); }
/** * Constructs a QName from a string (attribute or element content) value. * * @param qname the QName string * @param owningObject XMLObject, with cached DOM, owning the QName * * @return the QName respresented by the string */ public static QName constructQName(String qname, XMLObject owningObject) { return constructQName(qname, owningObject.getDOM()); }
/** {@inheritDoc} */ protected void doParse(Element config, ParserContext parserContext, BeanDefinitionBuilder builder) { super.doParse(config, parserContext, builder); List<Element> metadataContent = XMLHelper.getChildElementsByTagNameNS(config, SAMLConstants.SAML20MD_NS, "EntitiesDescriptor"); if (metadataContent.size() < 1) { metadataContent = XMLHelper.getChildElementsByTagNameNS(config, SAMLConstants.SAML20MD_NS, "EntityDescriptor"); } builder.addConstructorArgValue((Element) metadataContent.get(0)); } }
/** {@inheritDoc} */ protected void marshallAttributes(XMLObject xmlObject, Element domElement) throws MarshallingException { RelayState relayState = (RelayState) xmlObject; if (relayState.isSOAP11MustUnderstandXSBoolean() != null) { XMLHelper.marshallAttribute(RelayState.SOAP11_MUST_UNDERSTAND_ATTR_NAME, relayState.isSOAP11MustUnderstandXSBoolean().toString(), domElement, false); } if (relayState.getSOAP11Actor() != null) { XMLHelper.marshallAttribute(RelayState.SOAP11_ACTOR_ATTR_NAME, relayState.getSOAP11Actor(), domElement, false); } }
/** {@inheritDoc} */ protected void processAttribute(XMLObject xmlObject, Attr attribute) throws UnmarshallingException { UsernameToken token = (UsernameToken) xmlObject; QName attribQName = XMLHelper.constructQName(attribute.getNamespaceURI(), attribute.getLocalName(), attribute.getPrefix()); if (UsernameToken.WSU_ID_ATTR_NAME.equals(attribQName)) { token.setWSUId(attribute.getValue()); attribute.getOwnerElement().setIdAttributeNode(attribute, true); } else { XMLHelper.unmarshallToAttributeMap(token.getUnknownAttributes(), attribute); } }
/** {@inheritDoc} */ protected void unmarshallTextContent(XMLObject xmlObject, Text content) throws UnmarshallingException { String textContent = DatatypeHelper.safeTrimOrNullString(content.getWholeText()); if (textContent != null) { XSQName qname = (XSQName) xmlObject; qname.setValue(XMLHelper.constructQName(textContent, XMLHelper.getElementAncestor(content))); } } }
/** {@inheritDoc} */ protected void processAttribute(XMLObject xmlObject, Attr attribute) throws UnmarshallingException { RequestAuthenticated ra = (RequestAuthenticated) xmlObject; QName attrName = XMLHelper.getNodeQName(attribute); if (RequestAuthenticated.SOAP11_MUST_UNDERSTAND_ATTR_NAME.equals(attrName)) { ra.setSOAP11MustUnderstand(XSBooleanValue.valueOf(attribute.getValue())); } else if (RequestAuthenticated.SOAP11_ACTOR_ATTR_NAME.equals(attrName)) { ra.setSOAP11Actor(attribute.getValue()); } else { super.processAttribute(xmlObject, attribute); } }
/** {@inheritDoc} */ protected void marshallElementContent(XMLObject samlObject, Element domElement) throws MarshallingException { Action action = (Action) samlObject; XMLHelper.appendTextContent(domElement, action.getAction()); } }
/** * Constructs an attribute owned by the given document with the given name. * * @param owningDocument the owning document * @param attributeName the name of that attribute * * @return the constructed attribute */ public static Attr constructAttribute(Document owningDocument, QName attributeName) { return constructAttribute(owningDocument, attributeName.getNamespaceURI(), attributeName.getLocalPart(), attributeName.getPrefix()); }
/** {@inheritDoc} */ protected void marshallAttributes(XMLObject xmlObject, Element domElement) throws MarshallingException { Timestamp timestamp = (Timestamp) xmlObject; if (!DatatypeHelper.isEmpty(timestamp.getWSUId())) { XMLHelper.marshallAttribute(Timestamp.WSU_ID_ATTR_NAME, timestamp.getWSUId(), domElement, true); } XMLHelper.marshallAttributeMap(timestamp.getUnknownAttributes(), domElement); }
/** * Pretty prints the XML node. * * @param node xml node to print * * @return pretty-printed xml */ public static String prettyPrintXML(Node node) { StringWriter writer = new StringWriter(); writeNode(node, writer, getPrettyPrintParams()); return writer.toString(); }
/** {@inheritDoc} */ protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { log.info("Parsing configuration for {} trust engine with id: {}", XMLHelper.getXSIType(element).getLocalPart(), element.getAttributeNS(null, "id")); List<Element> childElems = XMLHelper.getChildElementsByTagNameNS(element, SecurityNamespaceHandler.NAMESPACE, "Credential"); builder.addPropertyValue("credentials", SpringConfigurationUtils .parseCustomElements(childElems, parserContext)); }
/** * Constructs a QName from a string (attribute or element content) value. * * @param qname the QName string * @param owningObject XMLObject, with cached DOM, owning the QName * * @return the QName respresented by the string */ public static QName constructQName(String qname, XMLObject owningObject) { return constructQName(qname, owningObject.getDOM()); }