com.sun.xml.ws.security.opt.impl.dsig.JAXBSignatureHeaderElement Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of webservices-osgi Show documentation
Show all versions of webservices-osgi Show documentation
Metro Web Services Runtime OSGi Bundle
/*
* Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0, which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
/*
* JAXBSignatureHeaderElement.java
*
* Created on August 18, 2006, 2:29 PM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package com.sun.xml.ws.security.opt.impl.dsig;
import com.sun.xml.security.core.dsig.CustomStreamWriterImpl;
import com.sun.xml.ws.api.SOAPVersion;
import com.sun.xml.ws.security.opt.api.SecurityElementWriter;
import com.sun.xml.ws.security.opt.api.SecurityHeaderElement;
import com.sun.xml.ws.security.opt.crypto.dsig.keyinfo.KeyInfo;
import com.sun.xml.wss.impl.MessageConstants;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.io.OutputStream;
import jakarta.xml.bind.JAXBElement;
import jakarta.xml.bind.Marshaller;
import jakarta.xml.bind.JAXBException;
import javax.xml.crypto.MarshalException;
import javax.xml.crypto.dsig.XMLSignContext;
import javax.xml.crypto.dsig.XMLSignatureException;
import com.sun.xml.ws.security.opt.crypto.dsig.Signature;
import com.sun.xml.ws.security.opt.impl.util.JAXBUtil;
import com.sun.xml.stream.buffer.XMLStreamBufferResult;
import javax.xml.stream.XMLStreamException;
import org.jvnet.staxex.XMLStreamWriterEx;
/**
*
* @author [email protected]
*/
public class JAXBSignatureHeaderElement implements SecurityHeaderElement, SecurityElementWriter {
/* true if this signature header element is canonicalized before*/
private boolean isCanonicalized = false;
/*canonicalized signature value - for future use*/
private byte [] cs = null;
private Signature signature = null;
private SOAPVersion soapVersion = SOAPVersion.SOAP_11;
private Marshaller marshaller = null;
private XMLSignContext signContext = null;
/** Creates a new instance of JAXBSignatureHeaderElement */
public JAXBSignatureHeaderElement(Signature signature,SOAPVersion soapVersion) {
this.signature = signature;
this.soapVersion = soapVersion;
}
public JAXBSignatureHeaderElement(Signature signature,SOAPVersion soapVersion,XMLSignContext signctx) {
this.signature = signature;
this.soapVersion = soapVersion;
this.signContext = signctx;
}
public String getId() {
return signature.getId();
}
public void setId(String id) {
throw new UnsupportedOperationException();
}
public String getNamespaceURI() {
return MessageConstants.DSIG_NS;
}
public String getLocalPart() {
return MessageConstants.SIGNATURE_LNAME;
}
public javax.xml.stream.XMLStreamReader readHeader() throws XMLStreamException {
XMLStreamBufferResult xbr = new XMLStreamBufferResult();
try{
getMarshaller().marshal(signature, xbr);
} catch(JAXBException je){
//log
throw new XMLStreamException(je);
}
return xbr.getXMLStreamBuffer().readAsXMLStreamReader();
}
/**
* writes the jaxb signature header element to an XMLStreamWriter
* @param streamWriter javax.xml.stream.XMLStreamWriter
* @throws XMLStreamException
*/
public void writeTo(javax.xml.stream.XMLStreamWriter streamWriter) throws XMLStreamException {
try {
// If writing to Zephyr, get output stream and use JAXB UTF-8 writer
if (streamWriter instanceof Map) {
OutputStream os = (OutputStream) ((Map) streamWriter).get("sjsxp-outputstream");
if (os != null) {
streamWriter.writeCharacters(""); // Force completion of open elems
getMarshaller().marshal(signature, os);
return;
}
}else if (streamWriter instanceof XMLStreamWriterEx) {
CustomStreamWriterImpl swi = new CustomStreamWriterImpl(streamWriter);
getMarshaller().marshal(signature, swi);
} else {
getMarshaller().marshal(signature, streamWriter);
}
} catch (JAXBException e) {
throw new XMLStreamException(e);
}
}
/**
* writes the jaxb signature header element to an XMLStreamWriter
* @param streamWriter javax.xml.stream.XMLStreamWriter
* @param props HashMap
* @throws XMLStreamException
*/
@SuppressWarnings("unchecked")
public void writeTo(javax.xml.stream.XMLStreamWriter streamWriter,HashMap props) throws XMLStreamException {
try{
Marshaller marshaller = getMarshaller();
Iterator> itr = props.entrySet().iterator();
while(itr.hasNext()){
Map.Entry