コード例 #1
0
ファイル: Assertion.cs プロジェクト: AArnott/dotnetxri
        /*
        ****************************************************************************
        * fromDOM()
        ****************************************************************************
        */
        /**
        *  This method populates the obj from DOM.  It does not keep a
        * copy of the DOM around.  Whitespace information is lost in this process.
        */
        public void fromDOM(XmlElement oElem)
        {
            reset();

            // get the id attribute
            if (oElem.hasAttributeNS(null, Tags.ATTR_ID_CAP))
            {
            msXmlID = oElem.getAttributeNS(null, Tags.ATTR_ID_CAP);
            }

            if (oElem.hasAttributeNS(null, Tags.ATTR_ISSUEINSTANT))
            {
            msIssueInstant = oElem.getAttributeNS(null, Tags.ATTR_ISSUEINSTANT);
            }

            for (
            XmlNode oChild = oElem.FirstChild; oChild != null;
            oChild = oChild.NextSibling)
            {
            if (oChild.LocalName.Equals(Tags.TAG_ISSUER))
            {
                // only accept the first XRIAuthority
                if (moIssuer == null)
                {
                    moIssuer = new NameID((XmlElement) oChild);
                }
            }
            else if (oChild.LocalName.Equals(Tags.TAG_SIGNATURE))
            {
                // only accept the first XRIAuthority
                if (moSignature == null)
                {
                    try
                    {
                        XmlDocument oDoc = new XmlDocument();
                        XmlElement oChildCopy =
                            (XmlElement) oDoc.ImportNode(oChild, true);
                        moSignature = new XMLSignature(oChildCopy, null);
                    }
                    catch (Exception oEx)
                    {
                        soLog.Warn(
                            "Caught exception while parsing Signature", oEx);
                    }
                }
            }
            else if (oChild.LocalName.Equals(Tags.TAG_SUBJECT))
            {
                // only accept the first XRIAuthority
                if (moSubject == null)
                {
                    moSubject = new Subject((XmlElement) oChild);
                }
            }
            else if (oChild.LocalName.Equals(Tags.TAG_CONDITIONS))
            {
                // only accept the first XRIAuthority
                if (moConditions == null)
                {
                    moConditions = new Conditions((XmlElement) oChild);
                }
            }
            else if (oChild.LocalName.Equals(Tags.TAG_ATTRIBUTESTATEMENT))
            {
                // only accept the first XRIAuthority
                if (moAttrStatement == null)
                {
                    moAttrStatement = new AttributeStatement((XmlElement) oChild);
                }
            }
            }
        }
コード例 #2
0
ファイル: DOM3Utils.cs プロジェクト: AArnott/dotnetxri
        /*
        ****************************************************************************
        * bestEffortSetIDAttr()
        ****************************************************************************
        */
        /**
        * Makes a best effort at setting the ID attribute so that it can be looked
        * up using XmlDocument::getElementsById
        */
        public static void bestEffortSetIDAttr(
        XmlElement oElem, string sNS, string sAttr)
        {
            // do nothing if there is nothing to do
            if ((oElem == null) || (sAttr == null))
            {
            return;
            }

            // if we are using DOM3, use the setIdAttributeNode API
            if (hasDOM3Support())
            {
            Attr oAttr = oElem.getAttributeNodeNS(sNS, sAttr);

            // compiler-friendly way of doing setId as follows:
            // oElem.setIdAttributeNode(oAttr, true);
            try {
                oElem.GetType().getMethod("setIdAttributeNode", new Class[] { oAttr.GetType(), Boolean.TYPE })
                    .invoke(oElem, new Object[] { oAttr, true });
            }
            /*
            catch (IllegalArgumentException e) { }
            catch (SecurityException e) { }
            catch (IllegalAccessException e) { }
            catch (InvocationTargetException e) { }
            catch (NoSuchMethodException e) { }
            */
            catch (Exception e) {
                throw new RuntimeException("Exception caught while calling setIdAttributeNode: " + e);
            }

            if (!oAttr.isId()) {
                throw new RuntimeException("attribute node is not of type Id even after calling setIdAttributeNode!");
            }
            return;
            }

            // if it is an XmlDocument, use the putIdentifier method
            if (isXercesDocument(oElem.getOwnerDocument()))
            {
            string sAttrVal = oElem.getAttributeNS(sNS, sAttr);
            ((XmlDocument) oElem.getOwnerDocument()).putIdentifier(
                sAttrVal, oElem);
            return;
            }

            throw new RuntimeException(
            "No known method to set a signable ID attribute. " +
            "Try using a DOM3-compliant Parser or a DOM2 Xerces XmlDocument.");
        }
コード例 #3
0
ファイル: XRD.cs プロジェクト: AArnott/dotnetxri
        //throws UriFormatException, ParseException
        /**
        * This method populates the obj from DOM.  It does not keep a
        * copy of the DOM around.  Whitespace information is lost in this process.
        */
        public void fromDOM(XmlElement oElem)
        {
            reset();

            // get the id attribute
            if (oElem.hasAttributeNS(Tags.NS_XML, Tags.ATTR_ID_LOW))
                xmlID = oElem.getAttributeNS(Tags.NS_XML, Tags.ATTR_ID_LOW);

            if (oElem.hasAttributeNS(Tags.NS_XML, Tags.ATTR_IDREF))
                idRef = oElem.getAttributeNS(Tags.NS_XML, Tags.ATTR_IDREF);

            if (oElem.hasAttributeNS(null, Tags.ATTR_XRD_VERSION))
                version = oElem.getAttributeNS(null, Tags.ATTR_XRD_VERSION);

            for (XmlElement oChild = (XmlElement)oElem.FirstChild; oChild != null; oChild = (XmlElement)oChild.NextSibling) {

                string sChildName = oChild.LocalName ?? oChild.Name;

                if (sChildName.Equals(Tags.TAG_TYPE)) {
                    XRDType t = new XRDType();
                    t.fromXML(oChild);
                    types.Add(t);
                } else if (sChildName.Equals(Tags.TAG_QUERY)) {
                    Query q = new Query();
                    q.fromXML(oChild);
                    this.query = q;
                } else if (sChildName.Equals(Tags.TAG_STATUS)) {
                    Status s = new Status();
                    s.fromXML(oChild);
                    this.status = s;
                } else if (sChildName.Equals(Tags.TAG_SERVERSTATUS)) {
                    ServerStatus s = new ServerStatus();
                    s.fromXML(oChild);
                    this.serverStatus = s;
                } else if (sChildName.Equals(Tags.TAG_EXPIRES)) {
                    // only accept the first Expires element and make sure it
                    expires = new Expires(XmlConvert.ToDateTime(oChild.FirstChild.Value));
                } else if (sChildName.Equals(Tags.TAG_PROVIDERID)) {
                    ProviderID p = new ProviderID();
                    p.fromXML(oChild);
                    this.providerID = p;
                } else if (sChildName.Equals(Tags.TAG_LOCALID)) {
                    addLocalID(new LocalID(oChild));
                } else if (sChildName.Equals(Tags.TAG_EQUIVID)) {
                    equivIDs.Add(new EquivID(oChild));
                } else if (sChildName.Equals(Tags.TAG_CANONICALID)) {
                    canonicalIDs.Add(new CanonicalID(oChild));
                } else if (sChildName.Equals(Tags.TAG_CANONICALEQUIVID)) {
                    canonicalEquivID = new CanonicalEquivID();
                    canonicalEquivID.fromXML(oChild);
                } else if (sChildName.Equals(Tags.TAG_REDIRECT)) {
                    Redirect _ref = new Redirect(oChild);
                    addRedirect(_ref);
                } else if (sChildName.Equals(Tags.TAG_REF)) {
                    Ref _ref = new Ref(oChild);
                    addRef(_ref);
                } else if (sChildName.Equals(Tags.TAG_SERVICE)) {
                    addService(new Service(oChild));
                } else if (
                          (oChild.NamespaceURI != null) &&
                          oChild.NamespaceURI.Equals(Tags.NS_SAML) &&
                          (oChild.LocalName != null) &&
                          oChild.LocalName.Equals(Tags.TAG_ASSERTION)) {
                    samlAssertion = new Assertion(oChild);
                }
                    // Added this code to support extensions in Authority XmlElement
                  else {
                    ArrayList oVector =
                        (ArrayList)moOtherChildrenVectorsMap[sChildName];

                    if (oVector == null) {
                        oVector = new ArrayList();
                        moOtherChildrenVectorsMap[sChildName] = oVector;
                    }

                    oVector.Add(oChild.CloneNode(true));
                }
            }
        }
コード例 #4
0
ファイル: Attribute.cs プロジェクト: AArnott/dotnetxri
        /*
        ****************************************************************************
        * fromDOM()
        ****************************************************************************
        */
        /**
        *  This method populates the XRD from DOM.  It does not keep a
        * copy of the DOM around.  Whitespace information is lost in this process.
        */
        public void fromDOM(XmlElement oElem)
        {
            reset();

            // get the id attribute
            if (oElem.hasAttributeNS(null, Tags.ATTR_NAME))
            {
            msName = oElem.getAttributeNS(null, Tags.ATTR_NAME);
            }

            for (
            XmlNode oChild = oElem.FirstChild; oChild != null;
            oChild = oChild.NextSibling)
            {
            if (oChild.LocalName.Equals(Tags.TAG_ATTRIBUTEVALUE))
            {
                // only accept the first  element and make sure it
                // is a text node
                if (
                    (msValue.Equals("")) && (oChild.FirstChild != null) &&
                    (oChild.FirstChild.NodeType == XmlNode.TEXT_NODE))
                {
                    msValue = oChild.FirstChild.getNodeValue();
                }
            }
            }
        }