Package org.apache.ws.security

Examples of org.apache.ws.security.SOAPConstants


    public void testX509SignatureDirectSTR() throws Exception {
        SOAPEnvelope envelope = null;
        WSSecSignature builder = new WSSecSignature();
        builder.setUserInfo("wss4jcert", "security");
        // builder.setUserInfo("john", "keypass");
        SOAPConstants soapConstants = WSSecurityUtil.getSOAPConstants(unsignedEnvelope.getAsDOM());
        Vector parts = new Vector();
       
        /*
         * Set up to sign body and use STRTransorm to sign
         * the signature token (e.g. X.509 certificate)
         */
        WSEncryptionPart encP =
            new WSEncryptionPart(
                soapConstants.getBodyQName().getLocalPart(),
                soapConstants.getEnvelopeURI(),
                "Content");
        parts.add(encP);
        encP =
            new WSEncryptionPart(
                "STRTransform",
                soapConstants.getEnvelopeURI(),
                "Content");
        parts.add(encP);

        builder.setParts(parts);
        builder.setKeyIdentifierType(WSConstants.BST_DIRECT_REFERENCE);
View Full Code Here


    public void testX509SignatureISSTR() throws Exception {
        SOAPEnvelope envelope = null;
        WSSecSignature builder = new WSSecSignature();
        builder.setUserInfo("wss4jcert", "security");
        // builder.setUserInfo("john", "keypass");
        SOAPConstants soapConstants = WSSecurityUtil.getSOAPConstants(unsignedEnvelope.getAsDOM());
        Vector parts = new Vector();
       
        /*
         * Set up to sign body and use STRTransorm to sign
         * the signature token (e.g. X.509 certificate)
         */
        WSEncryptionPart encP =
            new WSEncryptionPart(
                soapConstants.getBodyQName().getLocalPart(),    // define the body
                soapConstants.getEnvelopeURI(),
                "Content");
        parts.add(encP);
        encP =
            new WSEncryptionPart(
                "STRTransform",                // reserved word to use STRTransform
                soapConstants.getEnvelopeURI(),
                "Content");
        parts.add(encP);

        builder.setParts(parts);
        builder.setKeyIdentifierType(WSConstants.ISSUER_SERIAL);
View Full Code Here

    public void testX509SignatureSKISTR() throws Exception {
        SOAPEnvelope envelope = null;
        WSSecSignature builder = new WSSecSignature();
        builder.setUserInfo("wss4jcert", "security");
        // builder.setUserInfo("john", "keypass");
        SOAPConstants soapConstants = WSSecurityUtil.getSOAPConstants(unsignedEnvelope.getAsDOM());
        Vector parts = new Vector();
       
        /*
         * Set up to sign body and use STRTransorm to sign
         * the signature token (e.g. X.509 certificate)
         */
        WSEncryptionPart encP =
            new WSEncryptionPart(
                soapConstants.getBodyQName().getLocalPart(),    // define the body
                soapConstants.getEnvelopeURI(),
                "Content");
        parts.add(encP);
        encP =
            new WSEncryptionPart(
                "STRTransform",                // reserved word to use STRTransform
                soapConstants.getEnvelopeURI(),
                "Content");
        parts.add(encP);

        builder.setParts(parts);
        builder.setKeyIdentifierType(WSConstants.SKI_KEY_IDENTIFIER);
View Full Code Here

    /*
     * First get the SOAP envelope as document, then create a security
     * header and insert into the document (Envelope)
     */
    Document doc = unsignedEnvelope.getAsDocument();
    SOAPConstants soapConstants = WSSecurityUtil.getSOAPConstants(doc
        .getDocumentElement());

    WSSecHeader secHeader = new WSSecHeader();
    secHeader.insertSecurityHeader(doc);

    Vector sigParts = new Vector();
    Vector encPartsInternal = new Vector();
    Vector encPartsExternal = new Vector();

    /*
     * Check is a timestamp is required. If yes create one and add its Id to
     * signed parts. According to WSP a timestamp must be signed
     */
    WSSecTimestamp timestamp = null;
    if (wpd.isIncludeTimestamp()) {
      timestamp = new WSSecTimestamp();
      timestamp.prepare(doc);
      sigParts.add(new WSEncryptionPart(timestamp.getId()));
    }

    /*
     * Check for a recipient token. If one is avaliable use it as token to
     * encrypt data to the recipient. This is according to WSP
     * specification. Most of the data is extracted from the
     * WSS4JPolicyData, only the user info (name/alias of the certificate in
     * the keystore) must be provided by some other means.
     */
    WSSecEncrypt recEncrypt = null;
    WSS4JPolicyToken recToken = null;
    if ((recToken = wpd.getRecipientToken()) != null) {
      recEncrypt = new WSSecEncrypt();
      recEncrypt.setUserInfo("wss4jcert");
      recEncrypt.setKeyIdentifierType(recToken.getKeyIdentifier());
      recEncrypt.setSymmetricEncAlgorithm(recToken.getEncAlgorithm());
      recEncrypt.setKeyEnc(recToken.getEncTransportAlgorithm());
      recEncrypt.prepare(doc, cryptoSKI);
    }

    /*
     * Check for an initiator token. If one is avaliable use it as token to
     * sign data. This is according to WSP specification. Most of the data
     * is extracted from the WSS4JPolicyData, only the user info (name/alias
     * of the certificate in the keystore) must be provided by some other
     * means.
     *
     * If SignatureProtection is enabled add the signature to the encrypted
     * parts vector. In any case the signature must be in the internal
     * ReferenceList (this list is a child of the EncryptedKey element).
     *
     * If TokenProtection is enabled add an appropriate signature reference.
     *
     * TODO Check / enable for STRTransform
     */
    WSSecSignature iniSignature = null;
    WSS4JPolicyToken iniToken = null;
    if ((iniToken = wpd.getInitiatorToken()) != null) {
      iniSignature = new WSSecSignature();
      iniSignature.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e",
          "security");
      iniSignature.setKeyIdentifierType(iniToken.getKeyIdentifier());
      iniSignature.setSignatureAlgorithm(iniToken.getSigAlgorithm());
      iniSignature.prepare(doc, crypto, secHeader);
      if (wpd.isSignatureProtection()) {
        encPartsInternal.add(new WSEncryptionPart(iniSignature.getId(),
            "Element"));
      }
      if (wpd.isTokenProtection()) {
        sigParts.add(new WSEncryptionPart("Token", null, null));
      }
    }

    Element body = WSSecurityUtil.findBodyElement(doc, soapConstants);
    if (body == null) {
      System.out
          .println("No SOAP Body found - illegal message structure. Processing terminated");
      return;
    }
    WSEncryptionPart bodyPart = new WSEncryptionPart("Body", soapConstants
        .getEnvelopeURI(), "Content");

    /*
     * Check the protection order. If Encrypt before signing then first take
     * all parts and elements to encrypt and encrypt them. Take their ids
View Full Code Here

    /**
     * Test signing a custom SOAP header and the SOAP body
     */
    public void testSOAPHeaderAndBody() throws Exception {
        SOAPEnvelope unsignedEnvelope = message.getSOAPEnvelope();
        SOAPConstants soapConstants =
            WSSecurityUtil.getSOAPConstants(unsignedEnvelope.getAsDOM());
        WSSecSignature sign = new WSSecSignature();
        sign.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e", "security");
        sign.setKeyIdentifierType(WSConstants.ISSUER_SERIAL);

        Document doc = unsignedEnvelope.getAsDocument();

        WSSecHeader secHeader = new WSSecHeader();
        secHeader.insertSecurityHeader(doc);
       
        Vector parts = new Vector();
        WSEncryptionPart encP =
            new WSEncryptionPart(
                soapConstants.getBodyQName().getLocalPart(),    // define the body
                soapConstants.getEnvelopeURI(),
                "");
        parts.add(encP);
        WSEncryptionPart encP2 =
            new WSEncryptionPart(
                "foobar",
View Full Code Here

     */
    public void testX509SignatureDirectSTR() throws Exception {
        WSSecSignature builder = new WSSecSignature();
        builder.setUserInfo("wss4jcert", "security");
        // builder.setUserInfo("john", "keypass");
        SOAPConstants soapConstants = WSSecurityUtil.getSOAPConstants(unsignedEnvelope.getAsDOM());
        Vector parts = new Vector();
       
        /*
         * Set up to sign body and use STRTransorm to sign
         * the signature token (e.g. X.509 certificate)
         */
        WSEncryptionPart encP =
            new WSEncryptionPart(
                soapConstants.getBodyQName().getLocalPart(),
                soapConstants.getEnvelopeURI(),
                "Content");
        parts.add(encP);
        encP =
            new WSEncryptionPart(
                "STRTransform",
                soapConstants.getEnvelopeURI(),
                "Content");
        parts.add(encP);

        builder.setParts(parts);
        builder.setKeyIdentifierType(WSConstants.BST_DIRECT_REFERENCE);
View Full Code Here

     * A timestamp is added to the document and signed.
     */
    public void testWSS96() throws Exception {
        WSSecSignature builder = new WSSecSignature();
        builder.setUserInfo("wss4jcert", "security");
        SOAPConstants soapConstants = WSSecurityUtil.getSOAPConstants(unsignedEnvelope.getAsDOM());
        Vector parts = new Vector();
       
        Document doc = unsignedEnvelope.getAsDocument();
        WSSecHeader secHeader = new WSSecHeader();
        secHeader.insertSecurityHeader(doc);
       
        /*
         * Set up to sign body and use STRTransorm to sign
         * the signature token (e.g. X.509 certificate)
         */
        WSEncryptionPart encP =
            new WSEncryptionPart(
                soapConstants.getBodyQName().getLocalPart(),
                soapConstants.getEnvelopeURI(),
                "Content");
        parts.add(encP);
        encP =
            new WSEncryptionPart(
                "STRTransform",
                soapConstants.getEnvelopeURI(),
                "Content");
        parts.add(encP);
       
        WSSecTimestamp timestamp = new WSSecTimestamp();
        timestamp.setTimeToLive(600);
View Full Code Here

     */
    public void testX509SignatureISSTR() throws Exception {
        WSSecSignature builder = new WSSecSignature();
        builder.setUserInfo("wss4jcert", "security");
        // builder.setUserInfo("john", "keypass");
        SOAPConstants soapConstants = WSSecurityUtil.getSOAPConstants(unsignedEnvelope.getAsDOM());
        Vector parts = new Vector();
       
        /*
         * Set up to sign body and use STRTransorm to sign
         * the signature token (e.g. X.509 certificate)
         */
        WSEncryptionPart encP =
            new WSEncryptionPart(
                soapConstants.getBodyQName().getLocalPart(),    // define the body
                soapConstants.getEnvelopeURI(),
                "Content");
        parts.add(encP);
        encP =
            new WSEncryptionPart(
                "STRTransform",                // reserved word to use STRTransform
                soapConstants.getEnvelopeURI(),
                "Content");
        parts.add(encP);

        builder.setParts(parts);
        builder.setKeyIdentifierType(WSConstants.ISSUER_SERIAL);
View Full Code Here

     */
    public void testX509SignatureSKISTR() throws Exception {
        WSSecSignature builder = new WSSecSignature();
        builder.setUserInfo("wss4jcert", "security");
        // builder.setUserInfo("john", "keypass");
        SOAPConstants soapConstants = WSSecurityUtil.getSOAPConstants(unsignedEnvelope.getAsDOM());
        Vector parts = new Vector();
       
        /*
         * Set up to sign body and use STRTransorm to sign
         * the signature token (e.g. X.509 certificate)
         */
        WSEncryptionPart encP =
            new WSEncryptionPart(
                soapConstants.getBodyQName().getLocalPart(),    // define the body
                soapConstants.getEnvelopeURI(),
                "Content");
        parts.add(encP);
        encP =
            new WSEncryptionPart(
                "STRTransform",                // reserved word to use STRTransform
                soapConstants.getEnvelopeURI(),
                "Content");
        parts.add(encP);

        builder.setParts(parts);
        builder.setKeyIdentifierType(WSConstants.SKI_KEY_IDENTIFIER);
View Full Code Here

        builder.prepare(doc, crypto);

        /*
         * Set up the parts structure to encrypt the body
         */
        SOAPConstants soapConstants = WSSecurityUtil.getSOAPConstants(doc
                .getDocumentElement());
        Vector parts = new Vector();
        WSEncryptionPart encP = new WSEncryptionPart(soapConstants
                .getBodyQName().getLocalPart(), soapConstants.getEnvelopeURI(),
                "Content");
        parts.add(encP);

        /*
         * Encrypt the parts (Body), create EncrypedData elements that reference
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.