Пример #1
0
        object ReadContent(XmlReader reader)
        {
            reader.MoveToContent();
            if (reader.NodeType != XmlNodeType.Element)
            {
                throw new XmlException(String.Format("Node type {0} is not expected as a WS-Security message header content.", reader.NodeType));
            }
            switch (reader.NamespaceURI)
            {
            case Constants.WsuNamespace:
                switch (reader.LocalName)
                {
                case "Timestamp":
                    return(ReadTimestamp(reader));
                }
                break;

            //case Constants.WstNamespace:
            case Constants.Wss11Namespace:
                if (reader.LocalName == "SignatureConfirmation")
                {
                    return(ReadSignatureConfirmation(reader, doc));
                }
                break;

            case SignedXml.XmlDsigNamespaceUrl:
                switch (reader.LocalName)
                {
                case "Signature":
                    WSSignedXml sxml = new WSSignedXml(doc);
                    sxml.Signature.LoadXml((XmlElement)doc.ReadNode(reader));
                    UpdateSignatureKeyInfo(sxml.Signature, doc, serializer);
                    return(sxml);
                }
                break;

            case EncryptedXml.XmlEncNamespaceUrl:
                switch (reader.LocalName)
                {
                case "EncryptedData":
                    XmlElement el = (XmlElement)doc.ReadNode(reader);
                    return(CreateEncryptedData(el));

                case "ReferenceList":
                    ReferenceList rl = new ReferenceList();
                    reader.Read();
                    for (reader.MoveToContent();
                         reader.NodeType != XmlNodeType.EndElement;
                         reader.MoveToContent())
                    {
                        switch (reader.LocalName)
                        {
                        case "DataReference":
                            DataReference dref = new DataReference();
                            dref.LoadXml((XmlElement)doc.ReadNode(reader));
                            rl.Add(dref);
                            continue;

                        case "KeyReference":
                            KeyReference kref = new KeyReference();
                            kref.LoadXml((XmlElement)doc.ReadNode(reader));
                            rl.Add(kref);
                            continue;
                        }
                        throw new XmlException(String.Format("Unexpected {2} node '{0}' in namespace '{1}' in ReferenceList.", reader.Name, reader.NamespaceURI, reader.NodeType));
                    }
                    reader.ReadEndElement();
                    return(rl);
                }
                break;
            }
            // SecurityTokenReference will be handled here.
            // This order (Token->KeyIdentifierClause) is
            // important because WrappedKey could be read
            // in both context (but must be a token here).
            if (serializer.CanReadToken(reader))
            {
                return(serializer.ReadToken(reader, resolver));
            }
            else if (serializer.CanReadKeyIdentifierClause(reader))
            {
                return(serializer.ReadKeyIdentifierClause(reader));
            }
            else
            {
                throw new XmlException(String.Format("Unexpected element '{0}' in namespace '{1}' as a WS-Security message header content.", reader.Name, reader.NamespaceURI));
            }
        }