本文整理了Java中org.opensaml.xml.io.Marshaller
类的一些代码示例,展示了Marshaller
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Marshaller
类的具体详情如下:
包路径:org.opensaml.xml.io.Marshaller
类名称:Marshaller
[英]Marshallers are used to marshall a org.opensaml.xml.XMLObject into a W3C DOM element.
[中]封送员用来封送一个组织。opensaml。xml。将XMLObject转换为W3C DOM元素。
代码示例来源: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: de.tudarmstadt.ukp.shibhttpclient/shib-http-client
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);
}
}
代码示例来源:origin: be.fedict.eid-idp/eid-idp-common-saml2
/**
* 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);
}
}
代码示例来源: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.metadata.saml2/org.wso2.carbon.identity.outbound.metadata.saml2
/**
* Marshall the provided descriptor element contents to DOM.
*
* @param desc
* @return Document after marshalling the SAML object to XML
* @throws MetadataException
*/
private Document marshallDescriptor(EntityDescriptor desc) throws MetadataException {
DocumentBuilderFactory factory = IdentityUtil.getSecuredDocumentBuilderFactory();
DocumentBuilder builder;
try {
builder = factory.newDocumentBuilder();
} catch (ParserConfigurationException e) {
throw new MetadataException("Error while creating the document.", e);
}
if (log.isDebugEnabled()) {
log.debug("Marshalling the metadata element contents");
}
Document document = builder.newDocument();
Marshaller out = org.opensaml.xml.Configuration.getMarshallerFactory().getMarshaller(desc);
try {
out.marshall(desc, document);
} catch (MarshallingException e) {
throw new MetadataException("Error while marshalling the descriptor.", e);
}
if (log.isDebugEnabled()) {
log.debug("Marshalling completed");
}
return document;
}
代码示例来源: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: io.apigee.opensaml/xmltooling
Element messageElem = marshaller.marshall(xmlObject);
内容来源于网络,如有侵权,请联系作者删除!