private void signAssertion(Assertion assertion, Credential credential) throws SecurityException, MarshallingException, SignatureException { SignatureBuilder signatureBuilder = (SignatureBuilder) builderFactory .getBuilder(Signature.DEFAULT_ELEMENT_NAME); Signature signature = signatureBuilder.buildObject(); signature.setSigningCredential(credential); SecurityHelper.prepareSignatureParams(signature, credential, null, null); assertion.setSignature(signature); Marshaller marshaller = Configuration.getMarshallerFactory().getMarshaller(assertion); marshaller.marshall(assertion); Signer.signObject(signature); }
assertion.setSignature(signature); Marshaller marshaller = Configuration.getMarshallerFactory().getMarshaller(assertion); marshaller.marshall(assertion); Signer.signObject(signature); return assertion;
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; }
Document document = builder.newDocument(); Marshaller out = Configuration.getMarshallerFactory().getMarshaller(spEntityDescriptor); out.marshall(spEntityDescriptor, document);
public static Element getElementFromAssertion(XMLObject xmlObj) throws TrustException { try { MarshallerFactory marshallerFactory = org.opensaml.xml.Configuration.getMarshallerFactory(); Marshaller marshaller = marshallerFactory.getMarshaller(xmlObj); Element assertionElement = marshaller.marshall(xmlObj, ((DOMMetaFactory)OMAbstractFactory.getMetaFactory(OMAbstractFactory.FEATURE_DOM)).newDocumentBuilderFactory().newDocumentBuilder().newDocument()); log.debug("DOM element is created successfully from the OpenSAML2 XMLObject"); return assertionElement; } catch (Exception e) { throw new TrustException("Error creating DOM object from the assertion", e); } }
/** * Creates the request entity that makes up the POST message body. * * @param message message to be sent * @param charset character set used for the message * * @return request entity that makes up the POST message body * * @throws SOAPClientException thrown if the message could not be marshalled */ protected RequestEntity createRequestEntity(Envelope message, Charset charset) throws SOAPClientException { try { Marshaller marshaller = Configuration.getMarshallerFactory().getMarshaller(message); ByteArrayOutputStream arrayOut = new ByteArrayOutputStream(); OutputStreamWriter writer = new OutputStreamWriter(arrayOut, charset); if (log.isDebugEnabled()) { log.debug("Outbound SOAP message is:\n" + XMLHelper.prettyPrintXML(marshaller.marshall(message))); } XMLHelper.writeNode(marshaller.marshall(message), writer); return new ByteArrayRequestEntity(arrayOut.toByteArray(), "text/xml"); } catch (MarshallingException e) { throw new SOAPClientException("Unable to marshall SOAP envelope", e); } }
private String writeEntityDescriptor(EntityDescriptor entityDescriptor) throws ParserConfigurationException, MarshallingException, TransformerException { Marshaller marshaller = Configuration.getMarshallerFactory().getMarshaller(entityDescriptor); Element element = marshaller.marshall(entityDescriptor); return XMLHelper.nodeToString(element); }
/** * Marhsall the opensaml {@link XMLObject} to a DOM {@link Element} * * @param xmlObject * the XML object * @return marshalled DOM element */ public static Element marshall(XMLObject xmlObject) { MarshallerFactory marshallerFactory = Configuration .getMarshallerFactory(); Marshaller marshaller = marshallerFactory.getMarshaller(xmlObject); try { return marshaller.marshall(xmlObject); } catch (MarshallingException e) { throw new RuntimeException("opensaml2 marshalling error: " + e.getMessage(), e); } }
public static Element marshallObject(XMLObject object) throws Exception { if (object.getDOM() == null) { Marshaller m = (Marshaller) Configuration.getMarshallerFactory().getMarshaller(object); if (m == null) { throw new IllegalArgumentException("No unmarshaller for " + object); } try { return m.marshall(object); } catch (MarshallingException e) { throw new Exception(e); } } else { return object.getDOM(); } } }
/** * Prints the given attribute statement to system output. * * @param attributeStatement attribute statement to print */ private static void printAttributeStatement(SAMLObject attributeStatement) { if (attributeStatement == null) { System.out.println("No attribute statement."); return; } Marshaller statementMarshaller = Configuration.getMarshallerFactory().getMarshaller(attributeStatement); try { Element statement = statementMarshaller.marshall(attributeStatement); System.out.println(XMLHelper.prettyPrintXML(statement)); } catch (MarshallingException e) { errorAndExit("Unable to marshall attribute statement", e); } }
@Override public void marshellAndSign() throws IdentityProviderException { try { MarshallerFactory marshallerFactory = Configuration.getMarshallerFactory(); Marshaller marshaller = marshallerFactory.getMarshaller(assertion); signedAssertion = marshaller.marshall(assertion); Signer.signObjects(signatureList); } catch (MarshallingException e) { log.debug(e); throw new IdentityProviderException("errorMarshellingOrSigning", e); } catch (Exception e) { log.debug(e); throw new IdentityProviderException("errorMarshellingOrSigning", e); } }
@Override public void marshellAndSign() throws IdentityProviderException { try { MarshallerFactory marshallerFactory = Configuration.getMarshallerFactory(); Marshaller marshaller = marshallerFactory.getMarshaller(assertion); signedAssertion = marshaller.marshall(assertion); Signer.signObjects(signatureList); } catch (MarshallingException e) { log.debug(e); throw new IdentityProviderException("errorMarshellingOrSigning", e); } catch (Exception e) { log.debug(e); throw new IdentityProviderException("errorMarshellingOrSigning", e); } }
@Override public void marshellAndSign() throws IdentityProviderException { try { MarshallerFactory marshallerFactory = Configuration.getMarshallerFactory(); Marshaller marshaller = marshallerFactory.getMarshaller(assertion); signedAssertion = marshaller.marshall(assertion); Signer.signObjects(signatureList); } catch (MarshallingException e) { log.debug(e); throw new IdentityProviderException("errorMarshellingOrSigning", e); } catch (Exception e) { log.debug(e); throw new IdentityProviderException("errorMarshellingOrSigning", e); } }
@Override public void marshellAndSign() throws IdentityProviderException { try { MarshallerFactory marshallerFactory = Configuration.getMarshallerFactory(); Marshaller marshaller = marshallerFactory.getMarshaller(assertion); signedAssertion = marshaller.marshall(assertion); Signer.signObjects(signatureList); } catch (MarshallingException e) { log.debug(e); throw new IdentityProviderException("errorMarshellingOrSigning", e); } catch (Exception e) { log.debug(e); throw new IdentityProviderException("errorMarshellingOrSigning", e); } }
/** * Ensure that the XMLObject is marshalled. * * @param xmlObject the object to check and marshall * @throws EncryptionException thrown if there is an error when marshalling the XMLObject */ protected void checkAndMarshall(XMLObject xmlObject) throws EncryptionException { Element targetElement = xmlObject.getDOM(); if (targetElement == null) { Marshaller marshaller = Configuration.getMarshallerFactory().getMarshaller(xmlObject); try { targetElement = marshaller.marshall(xmlObject); } catch (MarshallingException e) { log.error("Error marshalling target XMLObject", e); throw new EncryptionException("Error marshalling target XMLObject", e); } } }
/** * Ensure that the XMLObject is marshalled. * * @param xmlObject the object to check and marshall * @throws EncryptionException thrown if there is an error when marshalling the XMLObject */ protected void checkAndMarshall(XMLObject xmlObject) throws EncryptionException { Element targetElement = xmlObject.getDOM(); if (targetElement == null) { Marshaller marshaller = Configuration.getMarshallerFactory().getMarshaller(xmlObject); try { targetElement = marshaller.marshall(xmlObject); } catch (MarshallingException e) { log.error("Error marshalling target XMLObject", e); throw new EncryptionException("Error marshalling target XMLObject", e); } } }
private static String marshall(XMLObject xmlObject) throws org.wso2.carbon.identity.base.IdentityException { try { System.setProperty("javax.xml.parsers.DocumentBuilderFactory", "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl"); MarshallerFactory marshallerFactory = org.opensaml.xml.Configuration.getMarshallerFactory(); Marshaller marshaller = marshallerFactory.getMarshaller(xmlObject); Element element = marshaller.marshall(xmlObject); ByteArrayOutputStream byteArrayOutputStrm = new ByteArrayOutputStream(); DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS"); LSSerializer writer = impl.createLSSerializer(); LSOutput output = impl.createLSOutput(); output.setByteStream(byteArrayOutputStrm); writer.write(element, output); return byteArrayOutputStrm.toString("UTF-8"); } catch (Exception e) { log.error("Error Serializing the SAML Response"); throw IdentityException.error("Error Serializing the SAML Response", e); } }
private static String marshall(XMLObject xmlObject) throws org.wso2.carbon.identity.base.IdentityException { try { System.setProperty("javax.xml.parsers.DocumentBuilderFactory", "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl"); MarshallerFactory marshallerFactory = org.opensaml.xml.Configuration.getMarshallerFactory(); Marshaller marshaller = marshallerFactory.getMarshaller(xmlObject); Element element = marshaller.marshall(xmlObject); ByteArrayOutputStream byteArrayOutputStrm = new ByteArrayOutputStream(); DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS"); LSSerializer writer = impl.createLSSerializer(); LSOutput output = impl.createLSOutput(); output.setByteStream(byteArrayOutputStrm); writer.write(element, output); return byteArrayOutputStrm.toString("UTF-8"); } catch (Exception e) { log.error("Error Serializing the SAML Response"); throw IdentityException.error("Error Serializing the SAML Response", e); } }
private String _createAuthnRequest(final String requestId) throws SAMLException { final AuthnRequest request = createAuthnRequest(requestId); try { // samlobject to xml dom object final Element elem = Configuration.getMarshallerFactory() .getMarshaller(request) .marshall(request); // and to a string... final Document document = elem.getOwnerDocument(); final DOMImplementationLS domImplLS = (DOMImplementationLS) document .getImplementation(); final LSSerializer serializer = domImplLS.createLSSerializer(); serializer.getDomConfig().setParameter("xml-declaration", false); return serializer.writeToString(elem); } catch (MarshallingException e) { throw new SAMLException(e); } }
public static void signAssertion(SignableXMLObject signableXMLObject, Credential signingCredential) throws MarshallingException, SignatureException { Signature signature = buildSAMLObject(Signature.class, Signature.DEFAULT_ELEMENT_NAME); signature.setSigningCredential(signingCredential); signature.setSignatureAlgorithm(Configuration.getGlobalSecurityConfiguration().getSignatureAlgorithmURI(signingCredential)); signature.setCanonicalizationAlgorithm(SignatureConstants.ALGO_ID_C14N_EXCL_OMIT_COMMENTS); signableXMLObject.setSignature(signature); Configuration.getMarshallerFactory().getMarshaller(signableXMLObject).marshall(signableXMLObject); Signer.signObject(signature); }