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);
/** * 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; }
/** * 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); } }
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); } }
@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 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); }