コード例 #1
0
        public static ONOid ValidateTicket(double dtdVersion, string ticket, string clientName)
        {
            try
            {
                string     lServerName = "";
                string     lClientName = "";
                ONOid      lAgentOid;
                ONDateTime lTimeStamp;
                ONNat      lValidity;

                #region Open xml
                string        lTicket    = UncipherTicket(ticket);
                XmlTextReader lXMLReader = new XmlTextReader(new StringReader(lTicket));
                lXMLReader.WhitespaceHandling = WhitespaceHandling.None;
                lXMLReader.MoveToContent();
                #endregion

                #region Load information
                lXMLReader.ReadStartElement("ONTicket");

                // Server name
                lServerName = lXMLReader.ReadElementString("Server");

                // Client name
                lClientName = lXMLReader.ReadElementString("Client");

                // Agent oid
                object[] lParam = new object[2];
                lParam[0] = lXMLReader;
                lParam[1] = dtdVersion;
                lXMLReader.ReadStartElement("Agent");
                string lAgentClass = lXMLReader.GetAttribute("Class");
                lAgentOid = ONContext.InvoqueMethod(ONContext.GetType_XML(lAgentClass), "XML2ON", lParam) as ONOid;
                lXMLReader.ReadEndElement();                 // Agent

                // TimeStamp
                lTimeStamp = ONXmlDateTime.XML2ON(lXMLReader, dtdVersion, "Timestamp");

                // Validity
                lValidity = ONXmlNat.XML2ON(lXMLReader, dtdVersion, "Validity");

                lXMLReader.ReadEndElement();                 // ONTicket
                #endregion

                #region Validate information
                // Server name
                if (lServerName != mServerName)
                {
                    throw new ONAgentValidationException(null);
                }

                // Client name
                if (lClientName != clientName)
                {
                    throw new ONAgentValidationException(null);
                }

                // Agent oid
                if (ONSecureControl.SecureServer)
                {
                    if (lAgentOid == null)
                    {
                        throw new ONAgentValidationException(null);
                    }
                }

                // TimeStamp
                if (ONStdFunctions.datetimeAfter(lTimeStamp, ONStdFunctions.systemDateTime()))
                {
                    throw new ONAgentValidationException(null);
                }
                if (new ONBool(mValidity > 0) && (ONStdFunctions.datetimeBefore(ONStdFunctions.dateTimeAdd(new ONString("s"), lValidity, lTimeStamp), ONStdFunctions.systemDateTime())))
                {
                    throw new ONAgentValidationException(null);
                }

                // Validity
                if (new ONBool(mValidity > 0) && (lValidity != new ONNat(mValidity)))
                {
                    throw new ONAgentValidationException(null);
                }
                #endregion

                #region Close xml
                lXMLReader.Close();
                #endregion

                return(lAgentOid);
            }
            catch (ONAgentValidationException)
            {
                throw;
            }
            catch
            {
                throw new ONAgentValidationException(null);
            }
        }
コード例 #2
0
        public static string GetNextTicket(double dtdVersion, string clientName, ONOid agentOid)
        {
            #region Open xml
            MemoryStream  lXMLMemoryStream = new MemoryStream();
            XmlTextWriter lXMLWriter       = new XmlTextWriter(lXMLMemoryStream, new System.Text.UTF8Encoding());
            lXMLWriter.WriteStartDocument();
            #endregion

            #region Save information
            lXMLWriter.WriteStartElement("ONTicket");

            // Server name
            lXMLWriter.WriteElementString("Server", mServerName);

            // Client name
            lXMLWriter.WriteElementString("Client", clientName);

            // Agent oid
            if (agentOid == null)
            {
                lXMLWriter.WriteStartElement("Agent");
                lXMLWriter.WriteStartElement(ONXml.XMLTAG_OID);
                lXMLWriter.WriteAttributeString(ONXml.XMLATT_CLASS, "Agente");
                lXMLWriter.WriteElementString(ONXml.XMLTAG_OIDFIELD, "DEBUG");
                lXMLWriter.WriteEndElement();                 // Oid
                lXMLWriter.WriteEndElement();                 // Agent
            }
            else
            {
                object[] lParam = new object[4];
                lParam[0] = lXMLWriter;
                lParam[1] = agentOid;
                lParam[2] = dtdVersion;
                lParam[3] = "OID.Field";
                lXMLWriter.WriteStartElement("Agent");
                ONContext.InvoqueMethod(ONContext.GetType_XML(agentOid.ClassName), "ON2XML", lParam);
                lXMLWriter.WriteEndElement();                 // Agent
            }

            // TimeStamp
            ONXmlDateTime.ON2XML(lXMLWriter, ONStdFunctions.systemDateTime(), dtdVersion, "Timestamp");

            // Validity
            ONXmlNat.ON2XML(lXMLWriter, new ONNat(mValidity), dtdVersion, "Validity");

            lXMLWriter.WriteEndElement();             // ONTicket
            #endregion

            #region Get xml
            lXMLWriter.Flush();
            lXMLMemoryStream.Flush();
            lXMLMemoryStream.Position = 0;
            StreamReader lXMLStreamReader = new StreamReader(lXMLMemoryStream);
            string       lText            = lXMLStreamReader.ReadToEnd();
            #endregion

            #region Close xml
            lXMLWriter.Close();
            #endregion

            return(CipherTicket(lText));
        }