private static boolean getBoolean(XMLCryptoContext xc, String name) { Boolean value = (Boolean)xc.getProperty(name); return value != null && value.booleanValue(); } }
/** * Returns the prefix associated with the specified namespace URI * * @param context contains the namespace map * @param nsURI the namespace URI * @return the prefix associated with the specified namespace URI, or * null if not set */ public static String getNSPrefix(XMLCryptoContext context, String nsURI) { if (context != null) { return context.getNamespacePrefix (nsURI, context.getDefaultNamespacePrefix()); } else { return null; } }
private Data dereference(XMLCryptoContext context) throws XMLSignatureException { Data data = null; // use user-specified URIDereferencer if specified; otherwise use deflt URIDereferencer deref = context.getURIDereferencer(); if (deref == null) { deref = DOMURIDereferencer.INSTANCE; } try { data = deref.dereference(this, context); LOG.debug("URIDereferencer class name: {}", deref.getClass().getName()); LOG.debug("Data class name: {}", data.getClass().getName()); } catch (URIReferenceException ure) { throw new XMLSignatureException(ure); } return data; }
URIDereferencer resolver = context.getURIDereferencer(); URIReference uriRef = new URIReference(){ FilterProcessingContext wssContext = (FilterProcessingContext)context.get(MessageConstants.WSS_PROCESSING_CONTEXT);
private Marshaller getMarshaller() throws JAXBException{ JAXBFilterProcessingContext wssContext = (JAXBFilterProcessingContext)context.get(MessageConstants.WSS_PROCESSING_CONTEXT); Marshaller marshaller = _jaxbContext.createMarshaller(); marshaller.setProperty("com.sun.xml.bind.xmlDeclaration", false); if(wssContext != null) marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper", new WSSNamespacePrefixMapper(wssContext.isSOAP12())); else marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper", new WSSNamespacePrefixMapper()); marshaller.setProperty(Marshaller.JAXB_FRAGMENT,true); return marshaller; }
String uri = uriRef.getURI(); DOMCryptoContext dcc = (DOMCryptoContext) context; String baseURI = context.getBaseURI();
@Override public Data transform(Data data, XMLCryptoContext context, OutputStream os) throws TransformException { String attachmentUri = ((ApacheOctetStreamData) data).getURI(); String attachmentId = attachmentUri.substring(4); Attachment attachment; if (attachmentTransformParameterSpec != null) { attachment = attachmentTransformParameterSpec.getAttachment(); context.setProperty(ATTACHMENT_CALLBACKHANDLER, attachmentTransformParameterSpec.getAttachmentCallbackHandler()); } else { attachment = attachmentRequestCallback(context, attachmentId); } return processAttachment(context, os, attachmentUri, attachment); }
protected static SecurityHeaderElement resolveToken(final String uri, XMLCryptoContext context) throws URIReferenceException, XWSSecurityException{ URIDereferencer resolver = context.getURIDereferencer(); JAXBFilterProcessingContext wssContext = (JAXBFilterProcessingContext)context.get(MessageConstants.WSS_PROCESSING_CONTEXT);
/** Creates a new instance of StAXEnvelopedTransformWriter */ public StAXSTRTransformWriter(XMLStreamWriter writer,Data data,XMLCryptoContext xMLCryptoContext) { this.nextWriter = writer; this.data = data; if(data instanceof JAXBData){ ns = ((JAXBData)data).getNamespaceContext(); }else if(data instanceof StreamWriterData){ ns = ((StreamWriterData)data).getNamespaceContext(); } this.xMLCryptoContext = xMLCryptoContext; filterContext = (JAXBFilterProcessingContext) xMLCryptoContext.get(MessageConstants.WSS_PROCESSING_CONTEXT); }
apacheTransform = new Transform(ownerDoc, getAlgorithm(), transformElem.getChildNodes()); apacheTransform.setElement(transformElem, xc.getBaseURI()); boolean secVal = Utils.secureValidation(xc); apacheTransform.setSecureValidation(secVal);
if (attachmentTransformParameterSpec != null) { attachment = attachmentTransformParameterSpec.getAttachment(); context.setProperty(ATTACHMENT_CALLBACKHANDLER, attachmentTransformParameterSpec.getAttachmentCallbackHandler()); } else {
protected Attachment attachmentRequestCallback(XMLCryptoContext context, String attachmentId) throws TransformException { CallbackHandler attachmentCallbackHandler = (CallbackHandler) context.getProperty(ATTACHMENT_CALLBACKHANDLER); if (attachmentCallbackHandler == null) { throw new TransformException("No attachment callbackhandler supplied"); } AttachmentRequestCallback attachmentRequestCallback = new AttachmentRequestCallback(); attachmentRequestCallback.setAttachmentId(attachmentId); try { attachmentCallbackHandler.handle(new Callback[]{attachmentRequestCallback}); } catch (Exception e) { throw new TransformException(e); } List<Attachment> attachments = attachmentRequestCallback.getAttachments(); if (attachments == null || attachments.isEmpty() || !attachmentId.equals(attachments.get(0).getId())) { throw new TransformException("Attachment not found"); } return attachments.get(0); }
String dsPrefix = null; if (context != null) { prefix = context.getNamespacePrefix (WSSE, "wsse"); dsPrefix = context.getNamespacePrefix (XMLSignature.XMLNS, context.getDefaultNamespacePrefix());
private Data dereference(XMLCryptoContext context) throws XMLSignatureException { Data data = null; // use user-specified URIDereferencer if specified; otherwise use deflt URIDereferencer deref = context.getURIDereferencer(); try { data = deref.dereference(this, context); } catch (URIReferenceException ure) { throw new XMLSignatureException(ure); } return data; }
public StAXSTRTransformWriter(Data data,XMLCryptoContext xMLCryptoContext,String refId) { this.data = data; if(data instanceof JAXBData){ ns = ((JAXBData)data).getNamespaceContext(); }else if(data instanceof StreamWriterData){ ns = ((StreamWriterData)data).getNamespaceContext(); } this.xMLCryptoContext = xMLCryptoContext; this.strId = refId; filterContext = (JAXBFilterProcessingContext) xMLCryptoContext.get(MessageConstants.WSS_PROCESSING_CONTEXT); }
apacheTransform = new Transform(ownerDoc, getAlgorithm(), transformElem.getChildNodes()); apacheTransform.setElement(transformElem, xc.getBaseURI()); boolean secVal = Utils.secureValidation(xc); apacheTransform.setSecureValidation(secVal);
protected void attachmentResultCallback(XMLCryptoContext context, Attachment attachment) throws TransformException { CallbackHandler attachmentCallbackHandler = (CallbackHandler) context.getProperty(ATTACHMENT_CALLBACKHANDLER); if (attachmentCallbackHandler == null) { throw new TransformException("No attachment callbackhandler supplied"); } AttachmentResultCallback attachmentResultCallback = new AttachmentResultCallback(); attachmentResultCallback.setAttachmentId(attachment.getId()); attachmentResultCallback.setAttachment(attachment); try { attachmentCallbackHandler.handle(new Callback[]{attachmentResultCallback}); } catch (Exception e) { throw new TransformException(e); } }
protected static Node deReference(final Node node,XMLCryptoContext context)throws URIReferenceException { /*NodeList nodeList = ((Document)node).getElementsByTagNameNS(WSSE_EXT,"SecurityTokenReference"); final Node domNode = nodeList.item(0);*/ URIDereferencer dereferencer = context.getURIDereferencer(); //Dereference SecurityTokenReference; DOMURIReference domReference = new DOMURIReference(){ public Node getHere(){ return node; } public String getURI(){ return null; } public String getType(){ return null; } }; Data data = dereferencer.dereference(domReference, context); //Node parentNode = node.getParentNode(); Iterator nodeIterator = ((NodeSetData)data).iterator(); if(nodeIterator.hasNext()){ return (Node)nodeIterator.next(); }else{ throw new URIReferenceException("URI "+((Element)node).getAttribute("URI") + "not found"); } }
Data dereferenceAttachments(final String uri, final XMLCryptoContext context) throws URIReferenceException{ JAXBFilterProcessingContext filterContext = (JAXBFilterProcessingContext) context.get(MessageConstants.WSS_PROCESSING_CONTEXT); SecuredMessage secureMsg = filterContext.getSecuredMessage(); Attachment attachment = secureMsg.getAttachment(uri); if(attachment == null){ throw new URIReferenceException ("Attachment Resource with Identifier "+uri+" was not found"); } AttachmentData attachData = new AttachmentData(attachment); return attachData; }
Object wsDocInfoObject = xc.getProperty(TRANSFORM_WS_DOC_INFO); WSDocInfo wsDocInfo = null; if (wsDocInfoObject instanceof WSDocInfo) {