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")); }
String getAssertionXml(Assertion assertion) { try { AssertionMarshaller marshaller = new AssertionMarshaller(); Element plaintextElement = marshaller.marshall(assertion); String serializedElement = XMLHelper.nodeToString(plaintextElement); return serializedElement; } catch(Exception e) { } return null; }
/** * {@inheritDoc} */ @Override public String xmlDocumentToUnformattedString(Document document) { Element element = null; String unformatted = null; if(document !=null){ if(document.getDocumentElement() !=null){ element = document.getDocumentElement(); if(element !=null){ unformatted = XMLHelper.nodeToString(element); unformatted = unformatted.replace(StringConstants.XML_OMIT_STRING, ""); } } } return unformatted; }
/** * {@inheritDoc} */ @Override public String saml2ResponseToUnFormattedString(Response response) { Element saml2ResponseElement = null; String saml2ResponseString = null; try { if(response !=null){ saml2ResponseElement = responseMarshaller.marshall(response); } if(saml2ResponseElement !=null) { saml2ResponseString = XMLHelper.nodeToString(saml2ResponseElement); } }catch(MarshallingException e){ String message ="saml2ResponseToString(Response), Marshalling failed"; logger.error(message,e); } return saml2ResponseString; }
/** * Loads the configuration docuement. * * @param configuration the configurationd document * @throws ConfigurationException thrown if the configuration file(s) can not be be read or invalid */ public void load(Document configuration) throws ConfigurationException { log.debug("Loading configuration from XML Document"); log.trace("{}", XMLHelper.nodeToString(configuration.getDocumentElement())); // Schema validation log.debug("Schema validating configuration Document"); validateConfiguration(configuration); log.debug("Configuration document validated"); load(configuration.getDocumentElement()); }
/** * Loads the configuration docuement. * * @param configuration the configurationd document * @throws ConfigurationException thrown if the configuration file(s) can not be be read or invalid */ public void load(Document configuration) throws ConfigurationException { log.debug("Loading configuration from XML Document"); log.trace("{}", XMLHelper.nodeToString(configuration.getDocumentElement())); // Schema validation log.debug("Schema validating configuration Document"); validateConfiguration(configuration); log.debug("Configuration document validated"); load(configuration.getDocumentElement()); }
/** * {@inheritDoc} */ @Override public String saml2AssertionToUnFormattedString(Assertion assertion) { Element saml2AssertionElement = null; String saml2AssertionString = null; try { if(assertion != null) { saml2AssertionElement = assertionMarshaller.marshall(assertion); if(saml2AssertionElement != null) { saml2AssertionString = XMLHelper.nodeToString(saml2AssertionElement); }else{ saml2AssertionString ="AssertionElement is null! "; logger.error(saml2AssertionString); } }else{ saml2AssertionString ="Assertion is null! "; logger.error(saml2AssertionString); } }catch(MarshallingException e){ saml2AssertionString ="saml2AssertionToUnFormattedString(Assertion), Marshalling failed"; logger.error(saml2AssertionString,e); } return saml2AssertionString; }
/** * Custom serialization logic which transform XMLObject into String. * * @param out output stream * @throws java.io.IOException error performing XMLObject serialization */ private void writeObject(ObjectOutputStream out) throws IOException { try { if (serializedObject == null) { serializedObject = XMLHelper.nodeToString(SAMLUtil.marshallMessage(getObject())); } out.writeObject(serializedObject); } catch (MessageEncodingException e) { log.error("Error serializing SAML object", e); throw new IOException("Error serializing SAML object: " + e.getMessage()); } }
/** * Custom serialization logic which transform List of XMLObject into List of Strings. * * @param out output stream * @throws java.io.IOException error performing XMLObject serialization */ private void writeObject(ObjectOutputStream out) throws IOException { try { if (serializedObject == null) { ArrayList<String> serializedItems = new ArrayList<String>(); for (T item : getObject()) { serializedItems.add(XMLHelper.nodeToString(SAMLUtil.marshallMessage(item))); } serializedObject = serializedItems; } out.writeObject(serializedObject); } catch (MessageEncodingException e) { log.error("Error serializing SAML object", e); throw new IOException("Error serializing SAML object: " + e.getMessage()); } }
/** * DEFLATE (RFC1951) compresses the given SAML message. * * @param message SAML message * * @return DEFLATE compressed message * * @throws MessageEncodingException thrown if there is a problem compressing the message */ protected String deflateAndBase64Encode(SAMLObject message) throws MessageEncodingException { log.debug("Deflating and Base64 encoding SAML message"); try { String messageStr = XMLHelper.nodeToString(marshallMessage(message)); ByteArrayOutputStream bytesOut = new ByteArrayOutputStream(); Deflater deflater = new Deflater(Deflater.DEFLATED, true); DeflaterOutputStream deflaterStream = new DeflaterOutputStream(bytesOut, deflater); deflaterStream.write(messageStr.getBytes("UTF-8")); deflaterStream.finish(); return Base64.encodeBytes(bytesOut.toByteArray(), Base64.DONT_BREAK_LINES); } catch (IOException e) { throw new MessageEncodingException("Unable to DEFLATE and Base64 encode SAML message", e); } }
/** * {@inheritDoc} */ @Override public String soapMessageToUnFormattedString(SOAPMessage soapMessage) { Element soapElement = null; String unformatted = null; try { if(soapMessage != null){ soapElement = soapMessage.getSOAPPart().getEnvelope().getOwnerDocument().getDocumentElement(); if(soapElement != null){ unformatted = XMLHelper.nodeToString(soapElement); unformatted = unformatted.replace(StringConstants.SOAP_REPLACE_FROM,StringConstants.SOAP_REPLACE_TO); }else{ unformatted = "SOAP Element is null!"; logger.error(unformatted); } }else{ unformatted = "SOAPMessage is null!"; logger.error(unformatted); } }catch(SOAPException e){ unformatted = "Formatting failed: "; logger.error(unformatted,e); } return unformatted; }
private String writeEntityDescriptor(EntityDescriptor entityDescriptor) throws ParserConfigurationException, MarshallingException, TransformerException { Marshaller marshaller = Configuration.getMarshallerFactory().getMarshaller(entityDescriptor); Element element = marshaller.marshall(entityDescriptor); return XMLHelper.nodeToString(element); }
log.trace(XMLHelper.nodeToString(messageElem));
log.trace(XMLHelper.nodeToString(messageElem));
log.trace(XMLHelper.nodeToString(messageElem));
StringBuilder res = new StringBuilder(); for (XMLObject obj : ep.getUnknownXMLObjects()) { res.append(XMLHelper.nodeToString(marshallObject(obj)));
log.trace(XMLHelper.nodeToString(messageElem));
public SAMLAuthenticationInfo(Authentication authentication) throws MessageEncodingException{ SAMLCredential credential = (SAMLCredential) authentication.getCredentials(); //General general = new General(authentication); //Principal's SAML Attributes attributes = new ArrayList<>(); for(Attribute attr : credential.getAttributes()){ Map<String, String> attrMap = new HashMap<>(); attrMap.put("name", attr.getName()); attrMap.put("friendlyName", attr.getFriendlyName()); attrMap.put("value", credential.getAttributeAsString(attr.getName())); attributes.add(attrMap); } //Subject confirmation subjectConfirmation = new SubjectConfirmation(authentication); //Authentication statement authenticationStatement = new AuthenticationStatement(authentication); //Conditions conditions = new Conditions(authentication); //Assertion XML assertion = XMLHelper.nodeToString(SAMLUtil.marshallMessage(credential.getAuthenticationAssertion())); }
/** * Helper method that marshals the given message. * * @param message message the marshall and serialize * @return marshaled message * @throws org.opensaml.ws.message.encoder.MessageEncodingException * thrown if the give message can not be marshaled into its DOM representation */ public static Element marshallMessage(XMLObject message) throws MessageEncodingException { try { if (message.getDOM() != null) { log.debug("XMLObject already had cached DOM, returning that element"); return message.getDOM(); } Marshaller marshaller = Configuration.getMarshallerFactory().getMarshaller(message); if (marshaller == null) { throw new MessageEncodingException("Unable to marshall message, no marshaller registered for message object: " + message.getElementQName()); } Element messageElem = marshaller.marshall(message); if (log.isTraceEnabled()) { log.trace("Marshalled message into DOM:\n{}", XMLHelper.nodeToString(messageElem)); } return messageElem; } catch (MarshallingException e) { log.error("Encountered error marshalling message to its DOM representation", e); throw new MessageEncodingException("Encountered error marshalling message into its DOM representation", e); } }
throw new MessageEncodingException("No KeyInfo marshaller was configured"); String kiXML = XMLHelper.nodeToString(marshaller.marshall(keyInfo)); String kiBase64 = Base64.encodeBytes(kiXML.getBytes(), Base64.DONT_BREAK_LINES); return kiBase64;