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); }
SecurityHelper.prepareSignatureParams(signature, defaultCredential, null, null); assertion.setSignature(signature); Marshaller marshaller = Configuration.getMarshallerFactory().getMarshaller(assertion); marshaller.marshall(assertion); Signer.signObject(signature);
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; }
DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.newDocument(); Marshaller out = Configuration.getMarshallerFactory().getMarshaller(spEntityDescriptor); out.marshall(spEntityDescriptor, document);
/** * Convert specified opensaml {@link XMLObject} to specified JAXB type. * * @param openSAMLObject * the opensaml XML object. * @param wsType * the JAXB class * @param <T> * the JAXB type * @return JAXB representation of the opensaml xml object. */ @SuppressWarnings("unchecked") public static <T> T toJAXB(final XMLObject openSAMLObject, Class<T> wsType) { try { Element element = Configuration.getMarshallerFactory() .getMarshaller(openSAMLObject).marshall(openSAMLObject); return ((JAXBElement<T>) JAXBContext.newInstance(wsType) .createUnmarshaller().unmarshal(element)).getValue(); } catch (MarshallingException e) { throw new RuntimeException( "Marshaling from OpenSAML object failed.", e); } catch (JAXBException e) { throw new RuntimeException("Unmarshaling to JAXB object failed.", e); } }
/** * 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); } }
private String writeEntityDescriptor(EntityDescriptor entityDescriptor) throws ParserConfigurationException, MarshallingException, TransformerException { Marshaller marshaller = Configuration.getMarshallerFactory().getMarshaller(entityDescriptor); Element element = marshaller.marshall(entityDescriptor); return XMLHelper.nodeToString(element); }
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); } }
protected String encodeRequestMessage(SignableSAMLObject requestMessage, String binding) throws SSOAgentException { Marshaller marshaller = Configuration.getMarshallerFactory().getMarshaller(requestMessage); Element authDOM = null; try {
protected String encodeRequestMessage(RequestAbstractType requestMessage, String binding) throws SSOAgentException { Marshaller marshaller = Configuration.getMarshallerFactory().getMarshaller(requestMessage); Element authDOM = null; try {
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); } }
Configuration.getMarshallerFactory().getMarshaller(assertion).marshall(assertion, document); } catch (MarshallingException e) { log.debug("Error while marshalling assertion ", 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); }
Element elem = Configuration.getMarshallerFactory() .getMarshaller(request) .marshall(request);
Marshaller marshaller = Configuration.getMarshallerFactory().getMarshaller(signableMessage); marshaller.marshall(signableMessage); Signer.signObject(signature);
Marshaller marshaller = Configuration.getMarshallerFactory().getMarshaller(signableMessage); if (marshaller == null) { throw new MessageEncodingException("No marshaller registered for "
Configuration.getMarshallerFactory().getMarshaller(entityDescriptor).marshall(entityDescriptor); Signer.signObject(signature);
this.securityDecorator.getPhoto()); Element element = Configuration.getMarshallerFactory() .getMarshaller(assertion).marshall(assertion); return element;