Package org.apache.ws.security

Examples of org.apache.ws.security.SOAPConstants


     * @param doc The SOAP enevlope as W3C document
     * @return Document with RequestSecurityToken added
     * @throws DOMException NoRequestType NoSoapBody
     */
    public Document build(Document doc) throws DOMException, TrustException {
        SOAPConstants soapConsts = WSSecurityUtil.getSOAPConstants(doc.getDocumentElement());

        if (action != null) {
            Element envelope = doc.getDocumentElement();
            Element soapHeader = (Element) WSSecurityUtil.getDirectChild(doc.getFirstChild(), soapConsts.getHeaderQName().getLocalPart(),
                    soapConsts.getEnvelopeURI());

            if (soapHeader == null) {
                soapHeader = createElementInSameNamespace(envelope, soapConsts.getHeaderQName().getLocalPart());
                soapHeader = WSSecurityUtil.prependChildElement(doc, envelope, soapHeader, true);
            }

            Element actionElement = doc.createElementNS(TrustConstants.WSA_NS, TrustConstants.WST_PREFIX + TrustConstants.ACTION_TAG);
            Node actionContent = doc.createTextNode(action.toString());
View Full Code Here


        if (doDebug) {
            log.debug("Beginning signing...");
        }

        prepare(doc, cr, secHeader);
        SOAPConstants soapConstants = WSSecurityUtil.getSOAPConstants(doc.getDocumentElement());

        if (parts == null) {
            parts = new Vector();
            WSEncryptionPart encP =
                new WSEncryptionPart(
                    soapConstants.getBodyQName().getLocalPart(),
                    soapConstants.getEnvelopeURI(),
                    "Content"
                );
            parts.add(encP);
        }
View Full Code Here

        }
        /*
        * Check if it's a fault. Don't process faults.
        *
        */
        SOAPConstants soapConstants =
                WSSecurityUtil.getSOAPConstants(doc.getDocumentElement());
        if (WSSecurityUtil
                .findElement(doc.getDocumentElement(),
                        "Fault",
                        soapConstants.getEnvelopeURI())
                != null) {
            return false;
        }

        /*
 
View Full Code Here

            * Check if it's a response and if its a fault. Don't process
            * faults.
            */
            String msgType = sm.getMessageType();
            if (msgType != null && msgType.equals(Message.RESPONSE)) {
                SOAPConstants soapConstants = WSSecurityUtil
                        .getSOAPConstants(doc.getDocumentElement());
                if (WSSecurityUtil.findElement(doc.getDocumentElement(),
                        "Fault", soapConstants.getEnvelopeURI()) != null) {
                    return;
                }
            }

            /*
 
View Full Code Here

        Vector parts = null;
        if (reqData.getSignatureParts().size() > 0) {
            parts = reqData.getSignatureParts();
        }
        else {
            SOAPConstants soapConstants = WSSecurityUtil.getSOAPConstants(doc
                    .getDocumentElement());
           
            parts = new Vector();
            WSEncryptionPart encP = new WSEncryptionPart(soapConstants
                    .getBodyQName().getLocalPart(), soapConstants
                    .getEnvelopeURI(), "Content");
            parts.add(encP);
        }
        sign.addReferencesToSign(parts, reqData.getSecHeader());
View Full Code Here

        //
        // prepend elements in the right order to the security header
        //
        prependDKElementToHeader(secHeader);
               
        SOAPConstants soapConstants = WSSecurityUtil.getSOAPConstants(envelope);
        if (parts == null) {
            parts = new Vector();
            WSEncryptionPart encP =
                new WSEncryptionPart(
                    soapConstants.getBodyQName().getLocalPart(),
                    soapConstants.getEnvelopeURI(),
                    "Content"
                );
            parts.add(encP);
        }
        Element externRefList = encryptForExternalRef(null, parts);
View Full Code Here

     * @return The value of the <code>wsu:Id</code> attribute of the SOAP body
     * @throws Exception
     * @deprecated replaced by {@link WSSecBase#setBodyID(Document)}
     */
    protected String setBodyID(Document doc) throws Exception {
        SOAPConstants soapConstants = WSSecurityUtil.getSOAPConstants(doc
                .getDocumentElement());
        Element bodyElement = (Element) WSSecurityUtil.getDirectChild(doc
                .getFirstChild(), soapConstants.getBodyQName().getLocalPart(),
                soapConstants.getEnvelopeURI());
        if (bodyElement == null) {
            throw new Exception("SOAP Body Element node not found");
        }
        return setWsuId(bodyElement);
    }
View Full Code Here

     * @return A <code>wsse:Security</code> element
     * @deprecated replaced by
     *             {@link WSSecHeader#insertSecurityHeader(Document)}
     */
    protected Element insertSecurityHeader(Document doc) {
        SOAPConstants soapConstants = WSSecurityUtil.getSOAPConstants(doc
                .getDocumentElement());
        // lookup a security header block that matches actor
        Element securityHeader = WSSecurityUtil.getSecurityHeader(doc, actor,
                soapConstants);
        if (securityHeader == null) { // create if nothing found
            securityHeader = WSSecurityUtil.findWsseSecurityHeaderBlock(doc,
                    doc.getDocumentElement(), actor, true);

            String soapPrefix = WSSecurityUtil.getPrefixNS(soapConstants
                    .getEnvelopeURI(), securityHeader);
            if (actor != null && actor.length() > 0) {
                // Check for SOAP 1.2 here and use "role" instead of "actor"
                securityHeader.setAttributeNS(soapConstants.getEnvelopeURI(),
                        soapPrefix
                                + ":"
                                + soapConstants.getRoleAttributeQName()
                                        .getLocalPart(), actor);
            }
            if (mustunderstand) {
                securityHeader.setAttributeNS(soapConstants.getEnvelopeURI(),
                        soapPrefix + ":" + WSConstants.ATTR_MUST_UNDERSTAND,
                        soapConstants.getMustUnderstand());
            }
        }
        return securityHeader;
    }
View Full Code Here

        // If there is already a security header in this instance just return it
        //
        if (securityHeader != null) {
            return securityHeader;
        }
        SOAPConstants soapConstants =
            WSSecurityUtil.getSOAPConstants(doc.getDocumentElement());

        securityHeader =
            WSSecurityUtil.findWsseSecurityHeaderBlock(
                doc, doc.getDocumentElement(), actor, true
            );

        String soapPrefix =
            WSSecurityUtil.setNamespace(
                securityHeader, soapConstants.getEnvelopeURI(), WSConstants.DEFAULT_SOAP_PREFIX
            );
       
        if (actor != null && actor.length() > 0) {
            securityHeader.setAttributeNS(
                soapConstants.getEnvelopeURI(),
                soapPrefix + ":" + soapConstants.getRoleAttributeQName().getLocalPart(),
                actor
            );
        }
        if (mustunderstand) {
            securityHeader.setAttributeNS(
                soapConstants.getEnvelopeURI(),
                soapPrefix + ":" + WSConstants.ATTR_MUST_UNDERSTAND,
                soapConstants.getMustUnderstand()
            );
        }
        return securityHeader;
    }
View Full Code Here

         */
        WSDocInfo wsDocInfo = new WSDocInfo(doc);
        wsDocInfo.setCrypto(crypto);

        Element envelope = doc.getDocumentElement();
        SOAPConstants soapConstants = WSSecurityUtil.getSOAPConstants(envelope);

        Element securityHeader = insertSecurityHeader(doc);

        // Set the id of the elements to be used as digest source
        // String id = setBodyID(doc);
        String certUri = null;
        X509Certificate[] certs = null;
        if (keyIdentifierType != WSConstants.UT_SIGNING) {
            certs = crypto.getCertificates(user);
            if (certs == null || certs.length <= 0) {
                throw new WSSecurityException(
                    WSSecurityException.FAILURE,
                    "noUserCertsFound",
                    new Object[] { user, "signature" }
                );
            }
            certUri = wssConfig.getIdAllocator().createSecureId("CertId-", certs[0])
            if (sigAlgo == null) {
                String pubKeyAlgo = certs[0].getPublicKey().getAlgorithm();
                log.debug("automatic sig algo detection: " + pubKeyAlgo);
                if (pubKeyAlgo.equalsIgnoreCase("DSA")) {
                    sigAlgo = XMLSignature.ALGO_ID_SIGNATURE_DSA;
                } else if (pubKeyAlgo.equalsIgnoreCase("RSA")) {
                    sigAlgo = XMLSignature.ALGO_ID_SIGNATURE_RSA;
                } else {
                    throw new WSSecurityException(
                        WSSecurityException.FAILURE,
                        "unknownSignatureAlgorithm",
                        new Object[] {
                            pubKeyAlgo
                        }
                    );
                }
            }
        }
        XMLSignature sig = null;

        if (canonAlgo.equals(WSConstants.C14N_EXCL_OMIT_COMMENTS)) {
            Element canonElem = XMLUtils.createElementInSignatureSpace(doc,
                    Constants._TAG_CANONICALIZATIONMETHOD);

            canonElem.setAttributeNS(null, Constants._ATT_ALGORITHM, canonAlgo);

            if (wssConfig.isWsiBSPCompliant()) {
                Set prefixes = getInclusivePrefixes(securityHeader, false);

                InclusiveNamespaces inclusiveNamespaces = new InclusiveNamespaces(
                        doc, prefixes);

                canonElem.appendChild(inclusiveNamespaces.getElement());
            }

            try {
                SignatureAlgorithm signatureAlgorithm = new SignatureAlgorithm(
                        doc, sigAlgo);
                sig = new XMLSignature(doc, null, signatureAlgorithm
                        .getElement(), canonElem);
            } catch (XMLSecurityException e) {
                log.error("", e);
                throw new WSSecurityException(
                    WSSecurityException.FAILED_SIGNATURE, "noXMLSig", null, e
                );
            }
        } else {
            try {
                sig = new XMLSignature(doc, null, sigAlgo, canonAlgo);
            } catch (XMLSecurityException e) {
                log.error("", e);
                throw new WSSecurityException(
                    WSSecurityException.FAILED_SIGNATURE, "noXMLSig", null, e
                );
            }
        }
        /*
         * If we don't generate a new Transforms for each addDocument here, then
         * only the last Transforms is put into the according ds:Reference
         * element, i.e. the first ds:Reference does not contain a Transforms
         * element. Thus the verification fails (somehow)
         */

        KeyInfo info = sig.getKeyInfo();
        String keyInfoUri = wssConfig.getIdAllocator().createSecureId("KeyId-", info);
        info.setId(keyInfoUri);

        SecurityTokenReference secRef = new SecurityTokenReference(doc);
        String secRefId = wssConfig.getIdAllocator().createSecureId("STRId-", info);
        secRef.setID(secRefId);

        if (tlog.isDebugEnabled()) {
            t1 = System.currentTimeMillis();
        }

        if (parts == null) {
            parts = new Vector();
            WSEncryptionPart encP = new WSEncryptionPart(soapConstants
                    .getBodyQName().getLocalPart(), soapConstants
                    .getEnvelopeURI(), "Content");
            parts.add(encP);
        }

        Transforms transforms = null;
View Full Code Here

TOP

Related Classes of org.apache.ws.security.SOAPConstants

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.