Package org.apache.wss4j.common.ext

Examples of org.apache.wss4j.common.ext.Attachment


                    throw new WSSecurityException(
                            WSSecurityException.ErrorCode.INVALID_SECURITY,
                            "empty", "Attachment not found"
                    );
                }
                Attachment attachment = attachments.get(0);

                final String encAlgo = X509Util.getEncAlgo(encData);
                final String jceAlgorithm =
                        JCEMapper.translateURItoJCEID(encAlgo);
                final Cipher cipher = Cipher.getInstance(jceAlgorithm);

                InputStream attachmentInputStream =
                        AttachmentUtils.setupAttachmentDecryptionStream(
                                encAlgo, cipher, symmetricKey, attachment.getSourceStream());

                Attachment resultAttachment = new Attachment();
                resultAttachment.setId(attachment.getId());
                resultAttachment.setMimeType(encData.getAttributeNS(null, "MimeType"));
                resultAttachment.setSourceStream(attachmentInputStream);
                resultAttachment.addHeaders(attachment.getHeaders());

                if (WSConstants.SWA_ATTACHMENT_ENCRYPTED_DATA_TYPE_COMPLETE.equals(typeStr)) {
                    AttachmentUtils.readAndReplaceEncryptedAttachmentHeaders(
                            resultAttachment.getHeaders(), attachmentInputStream);
                }

                AttachmentResultCallback attachmentResultCallback = new AttachmentResultCallback();
                attachmentResultCallback.setAttachment(resultAttachment);
                attachmentResultCallback.setAttachmentId(resultAttachment.getId());
                attachmentCallbackHandler.handle(new Callback[]{attachmentResultCallback});

            } catch (UnsupportedCallbackException e) {
                throw new WSSecurityException(
                        WSSecurityException.ErrorCode.FAILED_CHECK, e);
View Full Code Here


        String attachmentUri = ((ApacheOctetStreamData) data).getURI();
        String attachmentId = attachmentUri.substring(4);

        AttachmentTransformParameterSpec attachmentTransformParameterSpec = getAttachmentTransformParameterSpec();

        Attachment attachment;
        if (attachmentTransformParameterSpec != null) {
            attachment = attachmentTransformParameterSpec.getAttachment();
            context.setProperty(ATTACHMENT_CALLBACKHANDLER, attachmentTransformParameterSpec.getAttachmentCallbackHandler());
        } else {
            attachment = attachmentRequestCallback(context, attachmentId);
        }       

        try {
            OutputStream outputStream = os;
            if (outputStream == null) {
                outputStream = new ByteArrayOutputStream();
            }
            AttachmentUtils.canonizeMimeHeaders(os, attachment.getHeaders());
            processAttachment(context, os, attachmentUri, attachment);

            if (os == null) {
                String mimeType = attachment.getMimeType();
                return new OctetStreamData(
                        new ByteArrayInputStream(
                                ((ByteArrayOutputStream)outputStream).toByteArray()
                        ),
                        attachmentUri, mimeType);
View Full Code Here

                            WSSecurityException.ErrorCode.FAILURE, e
                    );
                }
                List<Attachment> attachments = attachmentRequestCallback.getAttachments();
                for (int i = 0; i < attachments.size(); i++) {
                    Attachment attachment = attachments.get(i);

                    try {
                        List<Transform> transforms = new ArrayList<Transform>();

                        AttachmentTransformParameterSpec attachmentTransformParameterSpec =
                                new AttachmentTransformParameterSpec(
                                        attachmentCallbackHandler,
                                        attachment
                                        );

                        String attachmentSignatureTransform;
                        if ("Element".equals(encPart.getEncModifier())) {
                            attachmentSignatureTransform = WSConstants.SWA_ATTACHMENT_COMPLETE_SIG_TRANS;
                        } else {
                            attachmentSignatureTransform = WSConstants.SWA_ATTACHMENT_CONTENT_SIG_TRANS;
                        }

                        transforms.add(
                                signatureFactory.newTransform(
                                        attachmentSignatureTransform,
                                        attachmentTransformParameterSpec)
                        );

                        javax.xml.crypto.dsig.Reference reference =
                                signatureFactory.newReference("cid:" + attachment.getId(),
                                        digestMethod,
                                        transforms,
                                        null,
                                        null
                                );
View Full Code Here

                    attachmentEncryptedDataType = WSConstants.SWA_ATTACHMENT_ENCRYPTED_DATA_TYPE_CONTENT_ONLY;
                }

                List<Attachment> attachments = attachmentRequestCallback.getAttachments();
                for (int i = 0; i < attachments.size(); i++) {
                    Attachment attachment = attachments.get(i);

                    final String attachmentId = attachment.getId();
                    String encEncryptedDataId = config.getIdAllocator().createId("ED-", attachmentId);
                    encDataRef.add("#" + encEncryptedDataId);

                    Element encryptedData =
                            doc.createElementNS(WSConstants.ENC_NS, WSConstants.ENC_PREFIX + ":EncryptedData");
                    encryptedData.setAttributeNS(null, "Id", encEncryptedDataId);
                    encryptedData.setAttributeNS(null, "MimeType", attachment.getMimeType());
                    encryptedData.setAttributeNS(null, "Type", attachmentEncryptedDataType);

                    Element encryptionMethod =
                            doc.createElementNS(WSConstants.ENC_NS, WSConstants.ENC_PREFIX + ":EncryptionMethod");
                    encryptionMethod.setAttributeNS(null, "Algorithm", encryptionAlgorithm);

                    encryptedData.appendChild(encryptionMethod);
                    encryptedData.appendChild(keyInfo.getElement());

                    Element cipherData =
                            doc.createElementNS(WSConstants.ENC_NS, WSConstants.ENC_PREFIX + ":CipherData");
                    Element cipherReference =
                            doc.createElementNS(WSConstants.ENC_NS, WSConstants.ENC_PREFIX + ":CipherReference");
                    cipherReference.setAttributeNS(null, "URI", "cid:" + attachmentId);

                    Element transforms = doc.createElementNS(WSConstants.ENC_NS, WSConstants.ENC_PREFIX + ":Transforms");
                    Element transform = doc.createElementNS(WSConstants.SIG_NS, WSConstants.SIG_PREFIX + ":Transform");
                    transform.setAttributeNS(null, "Algorithm", WSConstants.SWA_ATTACHMENT_CIPHERTEXT_TRANS);
                    transforms.appendChild(transform);

                    cipherReference.appendChild(transforms);
                    cipherData.appendChild(cipherReference);
                    encryptedData.appendChild(cipherData);

                    attachmentEncryptedDataElements.add(encryptedData);

                    Attachment resultAttachment = new Attachment();
                    resultAttachment.setId(attachmentId);
                    resultAttachment.setMimeType("application/octet-stream");

                    String jceAlgorithm = JCEMapper.translateURItoJCEID(encryptionAlgorithm);
                    Cipher cipher = null;
                    try {
                        cipher = Cipher.getInstance(jceAlgorithm);

                        // The Spec mandates a 96-bit IV for GCM algorithms
                        if (XMLCipher.AES_128_GCM.equals(encryptionAlgorithm)
                                || XMLCipher.AES_192_GCM.equals(encryptionAlgorithm)
                                || XMLCipher.AES_256_GCM.equals(encryptionAlgorithm)) {
                            byte[] temp = WSSecurityUtil.generateNonce(12);
                            IvParameterSpec paramSpec = new IvParameterSpec(temp);
                            cipher.init(Cipher.ENCRYPT_MODE, secretKey, paramSpec);
                        } else {
                            cipher.init(Cipher.ENCRYPT_MODE, secretKey);
                        }
                    } catch (Exception e) {
                        throw new WSSecurityException(WSSecurityException.ErrorCode.FAILED_ENCRYPTION, e);
                    }

                    Map<String, String> headers = new HashMap<String, String>();
                    headers.putAll(attachment.getHeaders());
                    resultAttachment.setSourceStream(
                            AttachmentUtils.setupAttachmentEncryptionStream(
                                    cipher,
                                    "Element".equals(encPart.getEncModifier()),
                                    attachment,
                                    headers
                            )
                    );
                    resultAttachment.addHeaders(headers);

                    AttachmentResultCallback attachmentResultCallback = new AttachmentResultCallback();
                    attachmentResultCallback.setAttachmentId(attachmentId);
                    attachmentResultCallback.setAttachment(resultAttachment);
                    try {
View Full Code Here

                    throw new WSSecurityException(
                            WSSecurityException.ErrorCode.INVALID_SECURITY,
                            "empty", "Attachment not found"
                    );
                }
                Attachment attachment = attachments.get(0);

                final String encAlgo = X509Util.getEncAlgo(encData);
                final String jceAlgorithm =
                        JCEMapper.translateURItoJCEID(encAlgo);
                final Cipher cipher = Cipher.getInstance(jceAlgorithm);

                InputStream attachmentInputStream =
                        AttachmentUtils.setupAttachmentDecryptionStream(
                                encAlgo, cipher, symmetricKey, attachment.getSourceStream());

                Attachment resultAttachment = new Attachment();
                resultAttachment.setId(attachment.getId());
                resultAttachment.setMimeType(encData.getAttributeNS(null, "MimeType"));
                resultAttachment.setSourceStream(attachmentInputStream);
                resultAttachment.addHeaders(attachment.getHeaders());

                if (WSConstants.SWA_ATTACHMENT_ENCRYPTED_DATA_TYPE_COMPLETE.equals(typeStr)) {
                    AttachmentUtils.readAndReplaceEncryptedAttachmentHeaders(
                            resultAttachment.getHeaders(), attachmentInputStream);
                }

                AttachmentResultCallback attachmentResultCallback = new AttachmentResultCallback();
                attachmentResultCallback.setAttachment(resultAttachment);
                attachmentResultCallback.setAttachmentId(resultAttachment.getId());
                attachmentCallbackHandler.handle(new Callback[]{attachmentResultCallback});

            } catch (UnsupportedCallbackException e) {
                throw new WSSecurityException(
                        WSSecurityException.ErrorCode.FAILED_CHECK, e);
View Full Code Here

TOP

Related Classes of org.apache.wss4j.common.ext.Attachment

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.