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); }
/** * Adds an object provider to this configuration. * * @param providerName the name of the object provider, corresponding to the element name or type name that the * builder, marshaller, and unmarshaller operate on * @param builder the builder for that given provider * @param marshaller the marshaller for the provider * @param unmarshaller the unmarshaller for the provider */ public static void registerObjectProvider(QName providerName, XMLObjectBuilder builder, Marshaller marshaller, Unmarshaller unmarshaller) { Logger log = getLogger(); log.debug("Registering new builder, marshaller, and unmarshaller for {}", providerName); builderFactory.registerBuilder(providerName, builder); marshallerFactory.registerMarshaller(providerName, marshaller); unmarshallerFactory.registerUnmarshaller(providerName, unmarshaller); }
/** * Removes the builder, marshaller, and unmarshaller registered to the given key. * * @param key the key of the builder, marshaller, and unmarshaller to be removed */ public static void deregisterObjectProvider(QName key) { Logger log = getLogger(); log.debug("Unregistering builder, marshaller, and unmarshaller for {}", key); configuredObjectProviders.remove(key); builderFactory.deregisterBuilder(key); marshallerFactory.deregisterMarshaller(key); unmarshallerFactory.deregisterUnmarshaller(key); }
/** * Adds an object provider to this configuration. * * @param providerName the name of the object provider, corresponding to the element name or type name that the * builder, marshaller, and unmarshaller operate on * @param builder the builder for that given provider * @param marshaller the marshaller for the provider * @param unmarshaller the unmarshaller for the provider */ public static void registerObjectProvider(QName providerName, XMLObjectBuilder builder, Marshaller marshaller, Unmarshaller unmarshaller) { Logger log = getLogger(); log.debug("Registering new builder, marshaller, and unmarshaller for {}", providerName); builderFactory.registerBuilder(providerName, builder); marshallerFactory.registerMarshaller(providerName, marshaller); unmarshallerFactory.registerUnmarshaller(providerName, unmarshaller); }
/** * Removes the builder, marshaller, and unmarshaller registered to the given key. * * @param key the key of the builder, marshaller, and unmarshaller to be removed */ public static void deregisterObjectProvider(QName key) { Logger log = getLogger(); log.debug("Unregistering builder, marshaller, and unmarshaller for {}", key); configuredObjectProviders.remove(key); builderFactory.deregisterBuilder(key); marshallerFactory.deregisterMarshaller(key); unmarshallerFactory.deregisterUnmarshaller(key); }
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; }
/** * Adds an object provider to this configuration. * * @param providerName the name of the object provider, corresponding to the element name or type name that the * builder, marshaller, and unmarshaller operate on * @param builder the builder for that given provider * @param marshaller the marshaller for the provider * @param unmarshaller the unmarshaller for the provider * @param configuration optional XML configuration snippet * * @deprecated this method is deprecated with no replacement */ public static void registerObjectProvider(QName providerName, XMLObjectBuilder builder, Marshaller marshaller, Unmarshaller unmarshaller, Element configuration) { Logger log = getLogger(); log.debug("Registering new builder, marshaller, and unmarshaller for {}", providerName); if (configuration != null) { configuredObjectProviders.put(providerName, configuration); } builderFactory.registerBuilder(providerName, builder); marshallerFactory.registerMarshaller(providerName, marshaller); unmarshallerFactory.registerUnmarshaller(providerName, unmarshaller); }
SecurityHelper.prepareSignatureParams(signature, defaultCredential, null, null); assertion.setSignature(signature); Marshaller marshaller = Configuration.getMarshallerFactory().getMarshaller(assertion); marshaller.marshall(assertion); Signer.signObject(signature);
/** * Adds an object provider to this configuration. * * @param providerName the name of the object provider, corresponding to the element name or type name that the * builder, marshaller, and unmarshaller operate on * @param builder the builder for that given provider * @param marshaller the marshaller for the provider * @param unmarshaller the unmarshaller for the provider * @param configuration optional XML configuration snippet * * @deprecated this method is deprecated with no replacement */ public static void registerObjectProvider(QName providerName, XMLObjectBuilder builder, Marshaller marshaller, Unmarshaller unmarshaller, Element configuration) { Logger log = getLogger(); log.debug("Registering new builder, marshaller, and unmarshaller for {}", providerName); if (configuration != null) { configuredObjectProviders.put(providerName, configuration); } builderFactory.registerBuilder(providerName, builder); marshallerFactory.registerMarshaller(providerName, marshaller); unmarshallerFactory.registerUnmarshaller(providerName, unmarshaller); }
DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.newDocument(); Marshaller out = Configuration.getMarshallerFactory().getMarshaller(spEntityDescriptor); out.marshall(spEntityDescriptor, document);
/** * Retrieves the marshaller for the given XMLObject. The schema type, if present, is tried first as the key with the * element QName used if no schema type is present or does not have a marshaller registered under it. * * @param xmlObject the XMLObject to retrieve the marshaller for * * @return the marshaller that can be used for the given XMLObject */ public Marshaller getMarshaller(XMLObject xmlObject) { Marshaller marshaller; marshaller = getMarshaller(xmlObject.getSchemaType()); if (marshaller == null) { marshaller = getMarshaller(xmlObject.getElementQName()); } return marshaller; }
/** * Retrieves the marshaller for the given XMLObject. The schema type, if present, is tried first as the key with the * element QName used if no schema type is present or does not have a marshaller registered under it. * * @param xmlObject the XMLObject to retrieve the marshaller for * * @return the marshaller that can be used for the given XMLObject */ public Marshaller getMarshaller(XMLObject xmlObject) { Marshaller marshaller; marshaller = getMarshaller(xmlObject.getSchemaType()); if (marshaller == null) { marshaller = getMarshaller(xmlObject.getElementQName()); } return marshaller; }
static String xmlToString(XMLObject aObject) throws IOException { Document doc; try { doc = Configuration.getMarshallerFactory().getMarshaller(aObject).marshall(aObject) .getOwnerDocument(); } catch (MarshallingException e) { throw new IOException(e); } try { Source source = new DOMSource(doc); StringWriter stringWriter = new StringWriter(); Result result = new StreamResult(stringWriter); TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer(); transformer.transform(source, result); return stringWriter.getBuffer().toString(); } catch (TransformerException e) { throw new IOException(e); } }
/** * 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); } }
/** * Get a KeyInfo marshaller. * * @return a KeyInfo marshaller * @throws SecurityException thrown if there is an error obtaining the marshaller from the configuration */ private Marshaller getMarshaller() throws SecurityException { if (keyInfoMarshaller != null) { return keyInfoMarshaller; } keyInfoMarshaller = Configuration.getMarshallerFactory().getMarshaller(KeyInfo.DEFAULT_ELEMENT_NAME); if (keyInfoMarshaller == null) { throw new SecurityException("Could not obtain KeyInfo marshaller from the configuration"); } return keyInfoMarshaller; }
/** * Get a KeyInfo marshaller. * * @return a KeyInfo marshaller * @throws SecurityException thrown if there is an error obtaining the marshaller from the configuration */ private Marshaller getMarshaller() throws SecurityException { if (keyInfoMarshaller != null) { return keyInfoMarshaller; } keyInfoMarshaller = Configuration.getMarshallerFactory().getMarshaller(KeyInfo.DEFAULT_ELEMENT_NAME); if (keyInfoMarshaller == null) { throw new SecurityException("Could not obtain KeyInfo marshaller from the configuration"); } return keyInfoMarshaller; }
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); } }
Marshaller out = org.opensaml.xml.Configuration.getMarshallerFactory().getMarshaller(entityDescriptor);
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); } }