Package com.sun.xml.ws.security.opt.api

Examples of com.sun.xml.ws.security.opt.api.SecurityHeaderElement


            }
        }
       
        ArrayList pshList =  securityContext.getProcessedSecurityHeaders();
        for(int j=0; j< pshList.size() ; j++){
            SecurityHeaderElement  header = (SecurityHeaderElement) pshList.get(j);
            if(id.equals(header.getId())){
                if(header instanceof NamespaceContextInfo){
                    return new StreamWriterData(header,((NamespaceContextInfo)header).getInscopeNSContext());
                }else{
                    throw new URIReferenceException("Cannot derefernce this MessagePart and use if for any crypto operation " +
                              "as the message part is not cached");
                }
            }
        }
       
        // looking into buffered headers for - (Should be used only for getting the key)
        // What will happen when encrypting the content but signing the entire element? Can go wrong
        ArrayList bufList =  securityContext.getBufferedSecurityHeaders();
        for(int j=0; j< bufList.size() ; j++){
            SecurityHeaderElement  header = (SecurityHeaderElement) bufList.get(j);
            if(id.equals(header.getId())){
                if(header instanceof NamespaceContextInfo){
                    return new StreamWriterData(header,((NamespaceContextInfo)header).getInscopeNSContext());
                }else{
                    throw new URIReferenceException("Cannot derefernce this MessagePart and use if for any crypto operation " +
                              "as the message part is not cached");
View Full Code Here


                    XMLStreamReader decryptedData = ed.getDecryptedData(ek.getKey(ed.getEncryptionAlgorithm()));
                    SecurityHeaderProcessor shp = new SecurityHeaderProcessor(context, currentParentNS, staxIF, creator);
                    if (decryptedData.getEventType() != XMLStreamReader.START_ELEMENT) {
                        StreamUtil.moveToNextElement(decryptedData);
                    }
                    SecurityHeaderElement she = shp.createHeader(decryptedData);
                    encIds.put(ed.getId(), she.getId());
                    edAlgos.put(ed.getId(), ed.getEncryptionAlgorithm());
                    ek.getPendingReferenceList().remove(ed.getId());
                    if (ek.getPendingReferenceList().isEmpty()) {
                        pendingElement = null;
                        bufferedHeaders.remove(ek);
                        addSecurityHeader(ek);
                    }
                    checkDecryptedData(she, ek.getPolicy());
                } else {
                    // Handle Encrypted Attachment here
                    byte[] decryptedMimeData = ed.getDecryptedMimeData(ek.getKey(ed.getEncryptionAlgorithm()));
                    Attachment as = new AttachmentImpl(ed.getAttachmentContentId(), decryptedMimeData, ed.getAttachmentMimeType());
                    securityContext.getDecryptedAttachmentSet().add(as);
                    ek.getPendingReferenceList().remove(ed.getId());
                    if (ek.getPendingReferenceList().isEmpty()) {
                        pendingElement = null;
                        bufferedHeaders.remove(ek);
                        addSecurityHeader(ek);
                    }
                }
            } else {
                if (!lookInBufferedHeaders(ed, currentParentNS)) {
                    addSecurityHeader(ed);
                }
            }
        } else if (pendingElement != null && pendingElement instanceof ReferenceListHeader) {
            ReferenceListHeader refList = (ReferenceListHeader) pendingElement;
            if (refList.getPendingReferenceList().contains(ed.getId())) {
                //for policy verification
                refList.getPolicy().setKeyBinding(ed.getInferredKB());
                //

                if (!ed.hasCipherReference()) {
                    XMLStreamReader decryptedData = ed.getDecryptedData();
                    if (decryptedData.getEventType() != XMLStreamReader.START_ELEMENT) {
                        StreamUtil.moveToNextElement(decryptedData);
                    }
                    SecurityHeaderProcessor shp = new SecurityHeaderProcessor(context, currentParentNS, staxIF, creator);
                    SecurityHeaderElement she = shp.createHeader(decryptedData);
                    encIds.put(ed.getId(), she.getId());
                    edAlgos.put(ed.getId(), ed.getEncryptionAlgorithm());
                    refList.getPendingReferenceList().remove(ed.getId());
                    if (refList.getPendingReferenceList().isEmpty()) {
                        pendingElement = null;
                    }
View Full Code Here

    }

    private boolean lookInBufferedHeaders(EncryptedData ed, HashMap<String, String> currentParentNS) throws XWSSecurityException, XMLStreamException {
        if (bufferedHeaders.size() > 0) {
            for (int i = 0; i < bufferedHeaders.size(); i++) {
                SecurityHeaderElement bufShe = (SecurityHeaderElement) bufferedHeaders.get(i);
                if (MessageConstants.ENCRYPTEDKEY_LNAME.equals(bufShe.getLocalPart()) &&
                        MessageConstants.XENC_NS.equals(bufShe.getNamespaceURI())) {
                    EncryptedKey ek = ((EncryptedKey) bufShe);
                    if (ek.getPendingReferenceList() != null && ek.getPendingReferenceList().contains(ed.getId())) {
                        //for policy verification
                        if (ek.getPolicy() != null) {
                            ek.getPolicy().setKeyBinding(ek.getInferredKB());
                        }
                        if (!ed.hasCipherReference()) {
                            XMLStreamReader decryptedData = ed.getDecryptedData(ek.getKey(ed.getEncryptionAlgorithm()));
                            SecurityHeaderProcessor shp = new SecurityHeaderProcessor(context, currentParentNS, staxIF, creator);
                            if (decryptedData.getEventType() != XMLStreamReader.START_ELEMENT) {
                                StreamUtil.moveToNextElement(decryptedData);
                            }
                            SecurityHeaderElement she = shp.createHeader(decryptedData);
                            encIds.put(ed.getId(), she.getId());
                            edAlgos.put(ed.getId(), ed.getEncryptionAlgorithm());
                            //addSecurityHeader(she);
                            ek.getPendingReferenceList().remove(ed.getId());
                            checkDecryptedData(she, ek.getPolicy());
                        } else {
                            // handle encrypted attachment here
                            byte[] decryptedMimeData = ed.getDecryptedMimeData(ek.getKey(ed.getEncryptionAlgorithm()));
                            Attachment as = new AttachmentImpl(ed.getAttachmentContentId(), decryptedMimeData, ed.getAttachmentMimeType());
                            securityContext.getDecryptedAttachmentSet().add(as);
                            ek.getPendingReferenceList().remove(ed.getId());
                        }
                        return true;
                    }

                } else if (MessageConstants.XENC_REFERENCE_LIST_LNAME.equals(bufShe.getLocalPart()) &&
                        MessageConstants.XENC_NS.equals(bufShe.getNamespaceURI())) {
                    ReferenceListHeader refList = (ReferenceListHeader) bufShe;
                    if (refList.getPendingReferenceList().contains(ed.getId())) {
                        //for policy verification
                        refList.getPolicy().setKeyBinding(ed.getInferredKB());
                        //

                        if (!ed.hasCipherReference()) {
                            XMLStreamReader decryptedData = ed.getDecryptedData();
                            if (decryptedData.getEventType() != XMLStreamReader.START_ELEMENT) {
                                StreamUtil.moveToNextElement(decryptedData);
                            }
                            SecurityHeaderProcessor shp = new SecurityHeaderProcessor(context, currentParentNS, staxIF, creator);
                            SecurityHeaderElement she = shp.createHeader(decryptedData);
                            encIds.put(ed.getId(), she.getId());
                            edAlgos.put(ed.getId(), ed.getEncryptionAlgorithm());
                            //addSecurityHeader(she);
                            refList.getPendingReferenceList().remove(ed.getId());
                            checkDecryptedData(she, refList.getPolicy());
                        } else {
View Full Code Here

            XMLStreamReader decryptedData = ed.getDecryptedData();
            if (decryptedData.getEventType() != XMLStreamReader.START_ELEMENT) {
                StreamUtil.moveToNextElement(decryptedData);
            }
            SecurityHeaderProcessor shp = new SecurityHeaderProcessor(context, currentParentNS, staxIF, creator);
            SecurityHeaderElement she = shp.createHeader(decryptedData);
            encIds.put(ed.getId(), she.getId());
            edAlgos.put(ed.getId(), ed.getEncryptionAlgorithm());
            checkDecryptedData(she, policy);
            if (!handleSAMLAssertion(she)) {
                addSecurityHeader(she);
            }
View Full Code Here

        }

        ArrayList clonedBufferedHeaders = (ArrayList) bufferedHeaders.clone();
        if (clonedBufferedHeaders.size() > 0) {
            for (int i = 0; i < clonedBufferedHeaders.size(); i++) {
                SecurityHeaderElement she = (SecurityHeaderElement) clonedBufferedHeaders.get(i);
                processSecurityHeader(she);
            }
        }
        if (processedHeaders.size() > 0) {
            for (int i = 0; i < processedHeaders.size(); i++) {
                SecurityHeaderElement she = (SecurityHeaderElement) processedHeaders.get(i);
                processProcessedHeaders(she);
            }
        }

        try {
View Full Code Here

                }
            }
        }
        // look in processed headers
        for (int j = 0; j < processedHeaders.size(); j++) {
            SecurityHeaderElement header = (SecurityHeaderElement) processedHeaders.get(j);
            if (uri.equals(header.getId())) {
                qname = new QName(header.getNamespaceURI(), header.getLocalPart());
                target.setQName(qname);
                target.setContentOnly(false);
                return;
            }
        }
        // look in buffered headers
        for (int j = 0; j < bufferedHeaders.size(); j++) {
            SecurityHeaderElement header = (SecurityHeaderElement) bufferedHeaders.get(j);
            if (uri.equals(header.getId())) {
                qname = new QName(header.getNamespaceURI(), header.getLocalPart());
                target.setQName(qname);
                target.setContentOnly(false);
                return;
            }
        }
View Full Code Here

        }
    }

    private boolean isPending() throws XWSSecurityException {
        for (int i = 0; i < bufferedHeaders.size(); i++) {
            SecurityHeaderElement she = (SecurityHeaderElement) bufferedHeaders.get(i);
            if (isPrimary(she)) {
                return false;
            }
        }
        return true;
View Full Code Here

                    decryptedData = ed.getDecryptedData();
                    SecurityHeaderProcessor shp = new SecurityHeaderProcessor(context, envshNS, staxIF, creator);
                    if (decryptedData.getEventType() != XMLStreamReader.START_ELEMENT) {
                        StreamUtil.moveToNextElement(decryptedData);
                    }
                    SecurityHeaderElement newHeader = shp.createHeader(decryptedData);
                    encIds.put(ed.getId(), newHeader.getId());
                    edAlgos.put(ed.getId(), ed.getEncryptionAlgorithm());
                    processSecurityHeader(newHeader);
                    processedHeaders.add(newHeader);
                } else {
                    // handle encrypted attachment here
View Full Code Here

            }
            if (found) {
                continue;
            }
            for (int j = 0; j < processedHeaders.size(); j++) {
                SecurityHeaderElement header = (SecurityHeaderElement) processedHeaders.get(j);
                if (id.equals(header.getId())) {
                    if (header instanceof EncryptedData) {
                        found = true;
                        throw new XWSSecurityException("EncryptedKey or ReferenceList must appear before EncryptedData element with ID" + header.getId());
                    }
                }
            }
            if (found) {
                continue;
            }
            for (int j = 0; j < bufferedHeaders.size(); j++) {
                SecurityHeaderElement header = (SecurityHeaderElement) bufferedHeaders.get(j);
                if (id.equals(header.getId())) {
                    if (header instanceof EncryptedData) {
                        EncryptedData ed = (EncryptedData) header;
                        if (!ed.hasCipherReference()) {
                            XMLStreamReader decryptedData = null;
                            try {
                                if (ek != null) {
                                    if (ek.getPolicy() != null) {
                                        //for policy verification
                                        ek.getPolicy().setKeyBinding(ek.getInferredKB());
                                    }
                                    decryptedData = ed.getDecryptedData(ek.getKey(ed.getEncryptionAlgorithm()));
                                } else if (rlh != null) {
                                    rlh.getPolicy().setKeyBinding(ed.getInferredKB());
                                    decryptedData = ed.getDecryptedData();
                                } else {
                                    throw new XWSSecurityException("Internal Error: Both EncryptedKey and ReferenceList are set to null");
                                }


                                SecurityHeaderProcessor shp = new SecurityHeaderProcessor(context, envshNS, staxIF, creator);
                                if (decryptedData.getEventType() != XMLStreamReader.START_ELEMENT) {
                                    StreamUtil.moveToNextElement(decryptedData);
                                }
                                SecurityHeaderElement she = shp.createHeader(decryptedData);
                                edList.remove(ed.getId());
                                encIds.put(ed.getId(), she.getId());
                                edAlgos.put(ed.getId(), ed.getEncryptionAlgorithm());
                                bufferedHeaders.set(i, she);
                            } catch (XMLStreamException ex) {
                                logger.log(Level.SEVERE,LogStringsMessages.WSS_1615_ERROR_DECRYPTING_ENCRYPTED_DATA(), ex);
                                throw new XWSSecurityException("Error occurred while decrypting EncryptedData with ID " + ed.getId(), ex);
View Full Code Here

                return r;
            }
           
            private void fetch() {
                while(idx<secHeaderContent.size()) {
                    SecurityHeaderElement she = secHeaderContent.get(idx++);
                    if((uri == null && localName.equals(she.getLocalPart())) ||
                            (localName.equals(she.getLocalPart() )&& uri.equals(she.getNamespaceURI()))){
                        next = she;
                        break;
                    }
                }
            }
View Full Code Here

TOP

Related Classes of com.sun.xml.ws.security.opt.api.SecurityHeaderElement

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.