static void initXMLSec() { org.apache.xml.security.Init.init(); try { ElementProxy.setDefaultPrefix(Constants.SignatureSpecNS, "ds"); ElementProxy.setDefaultPrefix(QualifyingProperty.XADES_XMLNS, "xades"); ElementProxy.setDefaultPrefix(QualifyingProperty.XADESV141_XMLNS, "xades141"); } catch (XMLSecurityException ex) { } } }
Element toElement() { Element result = ElementProxy.createElementForFamily( contextDocument, EncryptionConstants.EncryptionSpecNS, EncryptionConstants._TAG_REFERENCELIST ); Iterator<Reference> eachReference = references.iterator(); while (eachReference.hasNext()) { Reference reference = eachReference.next(); result.appendChild(((ReferenceImpl) reference).toElement()); } return result; }
/** * Method addTextElement * * @param text * @param localname */ public void addTextElement(String text, String localname) { Element e = XMLUtils.createElementInSignatureSpace(getDocument(), localname); Text t = createText(text); appendOther(e, t); appendSelf(e); addReturnToSelf(); }
/** * Method addText * * @param text */ public void addText(String text) { if (text != null) { Text t = createText(text); appendSelf(t); } }
/** * Constructor ElementProxy * * @param doc */ public ElementProxy(Document doc) { if (doc == null) { throw new RuntimeException("Document is null"); } this.wrappedDoc = doc; this.wrappedElement = createElementForFamilyLocal(this.getBaseNamespace(), this.getBaseLocalName()); }
/** * Method addBase64Element * * @param bytes * @param localname */ public void addBase64Element(byte[] bytes, String localname) { if (bytes != null) { Element el = XMLUtils.createElementInSignatureSpace(getDocument(), localname); Text text = getDocument().createTextNode(XMLUtils.encodeToString(bytes)); el.appendChild(text); appendSelf(el); if (!XMLUtils.ignoreLineBreaks()) { appendSelf(createText("\n")); } } }
/** * Method addBigIntegerElement * * @param bi * @param localname */ public void addBigIntegerElement(BigInteger bi, String localname) { if (bi != null) { Element e = XMLUtils.createElementInSignatureSpace(getDocument(), localname); byte[] bytes = XMLUtils.getBytes(bi, bi.bitLength()); String encodedInt = XMLUtils.encodeToString(bytes); Document doc = e.getOwnerDocument(); Text text = doc.createTextNode(encodedInt); e.appendChild(text); appendSelf(e); addReturnToSelf(); } }
/** * Method addBase64Text * * @param bytes */ public void addBase64Text(byte[] bytes) { if (bytes != null) { Text t = XMLUtils.ignoreLineBreaks() ? createText(XMLUtils.encodeToString(bytes)) : createText("\n" + XMLUtils.encodeToString(bytes) + "\n"); appendSelf(t); } }
public void signMetadata(EntityDescriptor baseDescriptor) throws MetadataException { // Add key descriptors for each element in base descriptor. List<RoleDescriptor> roleDescriptors = baseDescriptor.getRoleDescriptors(); if (roleDescriptors.size() > 0) { for (RoleDescriptor roleDesc : roleDescriptors) { roleDesc.getKeyDescriptors().add(createKeyDescriptor()); } } if (log.isDebugEnabled()) { log.debug("Key Descriptors set for all the role descriptor types"); } // Remove namespace of Signature element try { org.apache.xml.security.utils.ElementProxy.setDefaultPrefix(ConfigElements.XMLSIGNATURE_NS, ""); } catch (XMLSecurityException e) { throw new MetadataException("Unable to set default prefix for signature element", e); } org.apache.xml.security.Init.init(); } /**
/** * @return the XML Element form of that Reference */ public Element toElement() { String tagName = getType(); Element result = ElementProxy.createElementForFamily( contextDocument, EncryptionConstants.EncryptionSpecNS, tagName ); result.setAttributeNS(null, EncryptionConstants._ATT_URI, uri); // TODO: Need to martial referenceInformation // Figure out how to make this work.. // <any namespace="##other" minOccurs="0" maxOccurs="unbounded"/> return result; } }
public static Document signAssertion(SAMLAssertion assertion) throws XMLSecurityException, KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException, UnrecoverableKeyException, ParserConfigurationException, DOMException, SAMLException { ElementProxy.setDefaultPrefix(Constants.SignatureSpecNS, "ds");
ElementProxy.createElementForFamily( doc, this.getBaseNamespace(), XPathFilterCHGPContainer._TAG_INCLUDE_BUT_SEARCH ); ElementProxy.createElementForFamily( doc, this.getBaseNamespace(), XPathFilterCHGPContainer._TAG_EXCLUDE_BUT_SEARCH ); ElementProxy.createElementForFamily( doc, this.getBaseNamespace(), XPathFilterCHGPContainer._TAG_EXCLUDE);
String prefix = element.getAttributeNS(null, "prefix"); LOG.debug("Now I try to bind {} to {}", prefix, namespace); ElementProxy.setDefaultPrefix(namespace, prefix);
Element toElement() { Element result = ElementProxy.createElementForFamily( contextDocument, EncryptionConstants.EncryptionSpecNS, EncryptionConstants._TAG_ENCRYPTEDKEY ElementProxy.createElementForFamily( contextDocument, EncryptionConstants.EncryptionSpecNS,
ElementProxy.setDefaultPrefix(Constants.SignatureSpecNS, "ds"); final KeyStore keyStore = loadKeyStore(privateKeyFile); final XMLSignature sig = new XMLSignature(doc, null,
Element toElement() { Element result = ElementProxy.createElementForFamily( contextDocument, EncryptionConstants.EncryptionSpecNS, EncryptionConstants._TAG_ENCRYPTEDDATA
Element qualifyingPropsElem = ElementProxy.createElementForFamily( signature.getDocument(), QualifyingProperty.XADES_XMLNS, QualifyingProperty.QUALIFYING_PROPS_TAG);