org.opensaml.xml.io.Marshaller.marshall()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(13.5k)|赞(0)|评价(0)|浏览(95)

本文整理了Java中org.opensaml.xml.io.Marshaller.marshall()方法的一些代码示例,展示了Marshaller.marshall()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Marshaller.marshall()方法的具体详情如下:
包路径:org.opensaml.xml.io.Marshaller
类名称:Marshaller
方法名:marshall

Marshaller.marshall介绍

[英]Marshall this element, and its children, and root them in a newly created Document. The Document is created by a javax.xml.parsers.DocumentBuilder obtained from a javax.xml.parsers.DocumentBuilderFactorycreated without any additional parameters or properties set; that is the system defaults properties are used.
[中]对该元素及其子元素进行Marshall处理,并将其根放到新创建的文档中。该文档是由javax创建的。xml。解析器。DocumentBuilder从javax获得。xml。解析器。DocumentBuilderFactory创建时未设置任何附加参数或属性;即使用系统默认属性。

代码示例

代码示例来源:origin: cloudfoundry/uaa

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);
}

代码示例来源:origin: cloudfoundry/uaa

assertion.setSignature(signature);
Marshaller marshaller = Configuration.getMarshallerFactory().getMarshaller(assertion);
marshaller.marshall(assertion);
Signer.signObject(signature);
return assertion;

代码示例来源:origin: apache/cloudstack

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;
}

代码示例来源:origin: apache/cloudstack

Document document = builder.newDocument();
Marshaller out = Configuration.getMarshallerFactory().getMarshaller(spEntityDescriptor);
out.marshall(spEntityDescriptor, document);

代码示例来源:origin: org.apache.rampart/rampart-trust

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);
  }
}

代码示例来源:origin: org.opensaml/openws

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

代码示例来源:origin: OpenConext/Mujina

private String writeEntityDescriptor(EntityDescriptor entityDescriptor) throws ParserConfigurationException, MarshallingException, TransformerException {
 Marshaller marshaller = Configuration.getMarshallerFactory().getMarshaller(entityDescriptor);
 Element element = marshaller.marshall(entityDescriptor);
 return XMLHelper.nodeToString(element);
}

代码示例来源:origin: be.fedict.eid-idp/eid-idp-common-saml2

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

代码示例来源:origin: usnistgov/iheos-toolkit2

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();
    }
  }
}

代码示例来源:origin: edu.internet2.middleware/shibboleth-common

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

代码示例来源:origin: org.wso2.carbon.identity/org.wso2.carbon.identity.provider

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

代码示例来源:origin: org.wso2.carbon.identity.inbound.auth.openid/org.wso2.carbon.identity.provider

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

代码示例来源:origin: org.wso2.carbon.identity.inbound.auth.openid/org.wso2.carbon.identity.provider

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

代码示例来源:origin: org.wso2.carbon.identity/org.wso2.carbon.identity.provider

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

代码示例来源:origin: org.opensaml/xmltooling

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

代码示例来源:origin: io.apigee.opensaml/xmltooling

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

代码示例来源:origin: org.wso2.carbon.identity.inbound.auth.saml2/org.wso2.carbon.identity.sso.saml.ui

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);
  }
}

代码示例来源:origin: org.wso2.carbon.identity/org.wso2.carbon.identity.sso.saml.ui

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);
  }
}

代码示例来源:origin: org.adeptnet.auth/auth-saml

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);
  }
}

代码示例来源:origin: OpenConext/Mujina

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);
}

相关文章

微信公众号

最新文章

更多

Marshaller类方法