Package org.apache.ws.security.message.token

Examples of org.apache.ws.security.message.token.SecurityTokenReference


       
        QName secTokRef = new QName(WSConstants.WSSE_NS, SecurityTokenReference.SECURITY_TOKEN_REFERENCE);

        if(el.equals(secTokRef)) {
          try {
          this.securityTokenReference = new SecurityTokenReference(WSSConfig.getDefaultWSConfig(), elem);
          } catch (WSSecurityException ex) {
            throw new WSTrustException(WSTrustException.INVALID_REQUEST, ex.getMessage());
          }
        } else {
          this.tokenToBeRenewed = elem;
View Full Code Here


     * @throws WSSecurityException
     */
    public SecurityTokenReference getSecuityTokenReference() throws
            WSSecurityException {
        if (this.elementSecurityTokenReference != null) {
            return new SecurityTokenReference(WSSConfig.getDefaultWSConfig(), this.elementSecurityTokenReference);
        }
        return null;
    }
View Full Code Here

        QName el = new QName(element.getNamespaceURI(), element.getLocalName());
        WSSConfig wssConfig = WSSConfig.getDefaultWSConfig();
        try {
            if (el.equals(SecurityTokenReference.SECURITY_TOKEN_REFERENCE))
                this.reference = new SecurityTokenReference(wssConfig, element);
            if (el.equals(UsernameToken.TOKEN))
                this.usernameToken = new UsernameToken(wssConfig, element);
            if (el.equals(BinarySecurity.TOKEN))
                this.binarySecurityToken = new BinarySecurity(wssConfig, element);
            doc = element.getOwnerDocument();
View Full Code Here

*/
    public static void replaceSecurityTokenReferences(Document doc)throws WSSecurityException{
    //WSSecurityUtil.findElement(doc,SecurityTokenReference.TOKEN.getLocalPart(),SecurityTokenReference.TOKEN.getNamespaceURI());
    NodeList nList=doc.getElementsByTagName(SecurityTokenReference.SECURITY_TOKEN_REFERENCE);
    for(int i=0; i<nList.getLength();i++){
      SecurityTokenReference secTokRef=(SecurityTokenReference)nList.item(i);//SecTokRef
      Reference ref=secTokRef.getReference();
      String uri=ref.getURI();   
      //System.out.println("uri"+uri);
      Element elemFound=WSSecurityUtil.getElementByWsuId(WSSConfig.getDefaultWSConfig(),doc,uri);
      doc.replaceChild(secTokRef.getElement(),elemFound);     
    }     
         
    }
View Full Code Here

        
        // step 1 : Creating wsse:Reference to DerivedKeyToken
        Reference ref = new Reference(WSSConfig.getDefaultWSConfig(), doc);
        ref.setURI("#" + genID);
        ref.setValueType(ConversationConstants.TOKEN_TYPE_DERIVED_KEY_TOKEN);
        SecurityTokenReference stRef = new SecurityTokenReference(WSSConfig.getDefaultWSConfig(), doc);
        stRef.setReference(ref);

        WSSecurityUtil.setNamespace(stRef.getElement(),
                WSConstants.WSSE_NS,
                WSConstants.WSSE_PREFIX);

        // step 2 :Create the DerriveToken
        DerivedKeyToken dtoken = new DerivedKeyToken(doc);
View Full Code Here

        KeyInfo info = sig.getKeyInfo();
        String keyInfoUri = "KeyId-" + info.hashCode();
        info.setId(keyInfoUri);

        SecurityTokenReference secRef = new SecurityTokenReference(WSSConfig.getDefaultWSConfig(), doc);
        String strUri = "STRId-" + secRef.hashCode();
        secRef.setID(strUri);

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

        /*
         * The below "for" loop (which perform transforms) is
         * copied from
         *        build(Document doc, Crypto crypto) method in
         *            org.apache.ws.security.message.WSEncryptBody.java                 
         */

        Transforms transforms = null;

        for (int part = 0; part < parts.size(); part++) {
            WSEncryptionPart encPart = (WSEncryptionPart) parts.get(part);
            String elemName = encPart.getName();
            String nmSpace = encPart.getNamespace();

            /*
             * Set up the elements to sign. There are two resevered element
             * names: "Token" and "STRTransform" "Token": Setup the Signature
             * to either sign the information that points to the security token
             * or the token itself. If its a direct reference sign the token,
             * otherwise sign the KeyInfo Element. "STRTransform": Setup the
             * ds:Reference to use STR Transform
             *
             */
            try {
                if (elemName.equals("Token")) {
                    transforms = new Transforms(doc);
                    transforms.addTransform(Transforms.TRANSFORM_C14N_EXCL_OMIT_COMMENTS);
                    sig.addDocument("#" + keyInfoUri, transforms);
                } else if (elemName.equals("STRTransform")) { // STRTransform
                    Element ctx = createSTRParameter(doc);
                    transforms = new Transforms(doc);
                    transforms.addTransform(STRTransform.implementedTransformURI,
                            ctx);
                    sig.addDocument("#" + strUri, transforms);
                } else {
                    Element body =
                            (Element) WSSecurityUtil.findElement(envelope,
                                    elemName,
                                    nmSpace);
                    if (body == null) {
                        throw new WSSecurityException(WSSecurityException.FAILURE,
                                "noEncElement",
                                new Object[]{nmSpace + ", " + elemName});
                    }
                    transforms = new Transforms(doc);
                    transforms.addTransform(Transforms.TRANSFORM_C14N_EXCL_OMIT_COMMENTS);
                    sig.addDocument("#" + setWsuId(body), transforms);
                }
            } catch (TransformationException e1) {
                throw new WSSecurityException(WSSecurityException.FAILED_SIGNATURE,
                        "noXMLSig",
                        null,
                        e1);
            } catch (XMLSignatureException e1) {
                throw new WSSecurityException(WSSecurityException.FAILED_SIGNATURE,
                        "noXMLSig",
                        null,
                        e1);
            }
        }

        sig.addResourceResolver(EnvelopeIdResolver.getInstance(WSSConfig.getDefaultWSConfig()));

        /*
         * Prepending order
         * -Append the signature element.
         * -Apped the KeyInfo element
         */
        WSSecurityUtil.appendChildElement(doc,
                securityHeader,
                sig.getElement());

        /*
         * Put the "Reference object" into secRef in KeyInfo
         */
        secRef.setReference(ref);

        info.addUnknownElement(secRef.getElement());

        try {
            sig.sign(sharedKey);
        } catch (XMLSignatureException e1) {
            throw new WSSecurityException(WSSecurityException.FAILED_SIGNATURE,
View Full Code Here

                } else if (!rmd.isInitiator() && policyToken.isDerivedKeys()) {
                 
                  // If the Encrypted key used to create the derived key is not
                  // attached use key identifier as defined in WSS1.1 section
                  // 7.7 Encrypted Key reference
                  SecurityTokenReference tokenRef = new SecurityTokenReference(doc);
                  if(tok instanceof EncryptedKeyToken) {
                      tokenRef.setKeyIdentifierEncKeySHA1(((EncryptedKeyToken)tok).getSHA1());;
                  }
                  dkSign.setExternalKey(tok.getSecret(), tokenRef.getElement());
               
                } else {
                    dkSign.setExternalKey(tok.getSecret(), tok.getId());
                }
View Full Code Here

                    } else if (!rmd.isInitiator() && encrToken.isDerivedKeys()) {
                     
                      // If the Encrypted key used to create the derived key is not
                      // attached use key identifier as defined in WSS1.1 section
                      // 7.7 Encrypted Key reference
                      SecurityTokenReference tokenRef = new SecurityTokenReference(doc);
                      if(encrTok instanceof EncryptedKeyToken) {
                          tokenRef.setKeyIdentifierEncKeySHA1(((EncryptedKeyToken)encrTok).getSHA1());
                      }
                      dkEncr.setExternalKey(encrTok.getSecret(), tokenRef.getElement());
                     
                    } else {
                        dkEncr.setExternalKey(encrTok.getSecret(), encrTok.getId());
                    }
                   
View Full Code Here

        Reference ref = new Reference(doc);
        ref.setURI(refUri);
        if (refValueType != null) {
            ref.setValueType(refValueType);
        }
        SecurityTokenReference str = new SecurityTokenReference(doc);
        str.setReference(ref);

        return str.getElement();
    }
View Full Code Here

     * Create a KeyInfo object
     * @throws ConversationException
     */
    private KeyInfo createKeyInfo() throws WSSecurityException, ConversationException {
        KeyInfo keyInfo = new KeyInfo(document);
        SecurityTokenReference secToken = new SecurityTokenReference(document);
        secToken.addWSSENamespace();
        Reference ref = new Reference(document);
        ref.setURI("#" + dktId);
        String ns =
            ConversationConstants.getWSCNs(getWscVersion())
                + ConversationConstants.TOKEN_TYPE_DERIVED_KEY_TOKEN;
        ref.setValueType(ns);
        secToken.setReference(ref);

        keyInfo.addUnknownElement(secToken.getElement());
        Element keyInfoElement = keyInfo.getElement();
        keyInfoElement.setAttributeNS(
            WSConstants.XMLNS_NS, "xmlns:" + WSConstants.SIG_PREFIX, WSConstants.SIG_NS
        );
       
View Full Code Here

TOP

Related Classes of org.apache.ws.security.message.token.SecurityTokenReference

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.