Ejemplo n.º 1
0
        public void Validate(XmlDocument document)
        {
            try
            {
                this.logger.Trace("SchematronValidation");
                if (document == null)
                {
                    throw new SchematronValidationInterceptionEmptyBodyException();
                }

                DocumentTypeConfig           documentType = searcher.FindUniqueDocumentType(document);
                SchematronStore              store        = new SchematronStore();
                SchematronValidationConfig[] schematronValidationConfigCollection = documentType.SchematronValidationConfigs;
                foreach (SchematronValidationConfig schematronValidationConfig in schematronValidationConfigCollection)
                {
                    CompiledXslt        compiledXsltEntry = store.GetCompiledSchematron(schematronValidationConfig.SchematronDocumentPath);
                    SchematronValidator validator         = new SchematronValidator(schematronValidationConfig.ErrorXPath, schematronValidationConfig.ErrorMessageXPath);
                    validator.SchematronValidateXmlDocument(document, compiledXsltEntry);
                }
            }
            catch (SchematronErrorException ex)
            {
                this.logger.Info("XmlDocument rejected, as it contant at least one schematron error.");
                throw new SchematronValidateDocumentFailedException(ex);
            }
            catch (Exception ex)
            {
                this.logger.Error("Schematron validation failed", ex);
                throw new SchematronValidateDocumentFailedException(ex);
            }
        }
Ejemplo n.º 2
0
        public IRaspRequest PrepareRequest(OiosiMessage message, UddiType uddiType)
        {
            // First we need to find out what type of object we are sending
            DocumentTypeConfigSearcher typeSearcher  = new DocumentTypeConfigSearcher();
            DocumentTypeConfig         docTypeConfig = typeSearcher.FindUniqueDocumentType(message.MessageXml);

            // 1. Lookup the endpoint address and certificate using UDDI
            UddiLookupResponse uddiResponse = this.Uddi(message, docTypeConfig);

            // 2. Download the server certificate using LDAP
            X509Certificate2 serverCert = this.Ldap(uddiResponse.CertificateSubjectSerialNumber);

            // 3. Check the validity status of the certificate using OCSP
            this.Revocation(serverCert);


            // 4. Let the user configure the client certificate
            Console.WriteLine("\nPlease configure the certificate used for sending\n----------------------------------------------------");
            X509Certificate2 clientCert  = this.GetCertificate(uddiType);
            Credentials      credentials = new Credentials(new OcesX509Certificate(clientCert), new OcesX509Certificate(serverCert));

            // Create request
            RaspRequest raspRequest = new RaspRequest(new Request(uddiResponse.EndpointAddress.GetAsUri(), credentials));


            return(raspRequest);
        }
Ejemplo n.º 3
0
        public Message RequestRespond(Message request)
        {
            DocumentTypeConfigSearcher typeSearcher = new DocumentTypeConfigSearcher();
            OiosiMessage oiosiMessage = new OiosiMessage(request);

            // Use on of the two methods below, to retrive the document

            // This one is very expensive in in time/CPU.
            //XmlDocument xmlDocument = oiosiMessage.MessageXml;

            // This is mutch faster, as not converstion between xml an string is performed
            string xmlDocumentAsString = oiosiMessage.MessageAsString;

            DocumentTypeConfig docTypeConfig = typeSearcher.FindUniqueDocumentType(oiosiMessage.MessageXml);

            // Create the reply message (The body can be empty)
            string responseText;

            try
            {
                string version = ConfigurationHandler.Version;
                responseText = ConfigurationManager.AppSettings["ResponseText"];
                responseText = string.Format(responseText, DateTime.Now.ToString(), version);
            }
            catch (Exception)
            {
                responseText = "Request was received " + DateTime.Now.ToString();
            }

            string  body    = responseText;
            Message message = Message.CreateMessage(MessageVersion.Soap12WSAddressing10, docTypeConfig.EndpointType.ReplyAction, body);

            return(message);
        }
Ejemplo n.º 4
0
        public void _02_GetTwiceTest()
        {
            Console.WriteLine(DateTime.Now + " GetTwiceTest start");
            XmlDocument document = new XmlDocument();

            document.Load(TestConstants.PATH_INVOICE_XML);
            DocumentTypeConfigSearcher searcher           = new DocumentTypeConfigSearcher();
            DocumentTypeConfig         documentTypeConfig = searcher.FindUniqueDocumentType(document);
            SchematronStore            store = new SchematronStore();

            SchematronValidationConfig[] schematronValidationConfigCollection = documentTypeConfig.SchematronValidationConfigs;
            foreach (SchematronValidationConfig schematronValidationConfig in schematronValidationConfigCollection)
            {
                CompiledXslt transform = store.GetCompiledSchematron(schematronValidationConfig.SchematronDocumentPath);
                Assert.IsNotNull(transform);
                Assert.IsNotNull(transform.XslCompiledTransform);
            }

            schematronValidationConfigCollection = documentTypeConfig.SchematronValidationConfigs;
            foreach (SchematronValidationConfig schematronValidationConfig in schematronValidationConfigCollection)
            {
                CompiledXslt transform = store.GetCompiledSchematron(schematronValidationConfig.SchematronDocumentPath);
                Assert.IsNotNull(transform);
                Assert.IsNotNull(transform.XslCompiledTransform);
            }

            Console.WriteLine(DateTime.Now + " GetTwiceTest stop");
        }
Ejemplo n.º 5
0
        public void Validate(XmlDocument document)
        {
            this.logger.Trace("Schema validate xml document.");
            try
            {
                if (document == null)
                {
                    throw new SchemaValidationInterceptionEmptyBodyException();
                }

                DocumentTypeConfig documentType = searcher.FindUniqueDocumentType(document);


                if (string.IsNullOrEmpty(documentType.SchemaPath))
                {
                    // Empty schema path equal no schema exist.
                }
                else
                {
                    SchemaStore            schemaStore            = new SchemaStore();
                    XmlSchemaSet           XmlSchemaSet           = schemaStore.GetCompiledXmlSchemaSet(documentType);
                    SchemaValidator        schemaValidator        = new SchemaValidator();
                    ValidationEventHandler validationEventHandler = new ValidationEventHandler(ValidationCallBack);

                    schemaValidator.SchemaValidateXmlDocument(document, XmlSchemaSet, validationEventHandler);
                }
            }
            catch (SchemaValidateDocumentFailedException)
            {
                throw;
            }
            catch (SchemaValidationFailedException)
            {
                throw;
            }
            catch (Exception ex)
            {
                this.logger.Debug("Schema validate xml document.", ex);
                throw new SchemaValidateDocumentFailedException(ex);
            }

            this.logger.Trace("Schema validate xml document - Finish.");
        }
Ejemplo n.º 6
0
        private Identifier GetIdentifierValue(string path)
        {
            XmlDocument document = new XmlDocument();

            document.Load(path);
            DocumentTypeConfig config   = _searcher.FindUniqueDocumentType(document);
            string             keyXpath = config.EndpointType.Key.XPath;

            PrefixedNamespace[] namespaces = config.Namespaces;
            string     code       = "ean";
            Identifier identifier = Utilities.GetEndpointKeyByXpath(document, keyXpath, namespaces, code);

            return(identifier);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Handles request and respond
        /// </summary>
        /// <param name="request">the message</param>
        /// <returns>Message</returns>
        public virtual Message RequestRespond(Message request)
        {
            // The incoming message + metadata
            ListenerRequest listenerReq = new ListenerRequest(new OiosiMessage(request));


            try {
                // If any properties with the attribute MessageProperty were sent with the message
                // they should be attached to the ListenerRequest message as well
                foreach (object o in request.Properties.Values)
                {
                    if (o is InterceptorChannelExceptionCollection)
                    {
                        listenerReq.AddProperty(o);
                    }
                    else
                    {
                        object[] attributes = o.GetType().GetCustomAttributes(typeof(OiosiMessagePropertyAttribute), false);
                        if (attributes.Length > 0)
                        {
                            listenerReq.AddProperty(o);
                        }
                    }
                }
                //TODO: this is not needed?
                //foreach (MessageHeader h in request.Headers) {
                //    listenerReq.RequestMessage.MessageHeaders.Add(new XmlQualifiedName(h.Name, h.Namespace), h);
                //}
            }
            catch (Exception e) {
                dk.gov.oiosi.logging.WCFLogger.Write(System.Diagnostics.TraceEventType.Error, "Exception occurred in service implementation: " + e);
            }


            // Trigger the message receive event
            try {
                Listener.TriggerMessageReceiveEvent(listenerReq, MessageProcessStatus.messageReceiveOk);
            }
            catch (Exception exception) {
                return(System.ServiceModel.Channels.Message.CreateMessage(MessageVersion.Soap12WSAddressing10,
                                                                          new OiosiMessageFault(exception, OiosiFaultCode.Receiver, OiosiInnerFaultCode.MessagePersistencyFault),
                                                                          common.Definitions.DefaultOiosiNamespace2007 + OiosiInnerFaultCode.MessagePersistencyFault.ToString()));
            }

            var typeSearcher = new DocumentTypeConfigSearcher();
            DocumentTypeConfig docTypeConfig = typeSearcher.FindUniqueDocumentType(listenerReq.RequestMessage.MessageXml);

            // Reply with an empty message
            return(Message.CreateMessage(MessageVersion.Soap12WSAddressing10, docTypeConfig.EndpointType.ReplyAction));
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Overrides the abstract method and implements the basic intercept on a
 /// request.
 /// </summary>
 /// <param name="interceptorMessage"></param>
 public override void InterceptRequest(InterceptorMessage interceptorMessage)
 {
     try {
         X509Certificate2           certificate  = interceptorMessage.Certificate;
         XmlDocument                xmlDocument  = interceptorMessage.GetBody();
         DocumentTypeConfigSearcher searcher     = new DocumentTypeConfigSearcher();
         DocumentTypeConfig         documentType = searcher.FindUniqueDocumentType(xmlDocument);
         bool authorised = _authoriser.Authorise(certificate, xmlDocument, documentType);
         if (!authorised)
         {
             throw new NotAuthorisedException(certificate, xmlDocument, documentType);
         }
     } catch (NotAuthorisedException) {
         throw;
     } catch (Exception ex) {
         throw new AuthorisationProcessFailedException(ex);
     }
 }
Ejemplo n.º 9
0
        protected RaspRequest GetRaspRequest(OiosiMessage oiosiMessage)
        {
            DocumentTypeConfigSearcher documentTypeConfigSearcher = new DocumentTypeConfigSearcher();
            DocumentTypeConfig         documentTypeConfig         = documentTypeConfigSearcher.FindUniqueDocumentType(oiosiMessage.MessageXml);
            LookupParameters           messageParameters          = this.GetMessageParameters(oiosiMessage, documentTypeConfig);
            UddiLookupResponse         uddiResponse = this.PerformUddiLookup(messageParameters);
            Uri endpointAddressUri = uddiResponse.EndpointAddress.GetAsUri();

            OcesX509Certificate endpointCertificate = this.GetEndpointCertificateFromLdap(uddiResponse.CertificateSubjectSerialNumber);

            this.ValidateEndpointCertificate(endpointCertificate);
            //X509Certificate2 clientCertificate = CertificateUtil.InstallAndGetFunctionCertificateFromCertificateStore();
            X509Certificate2 clientCertificate = this.ClientCertificate;

            Credentials credentials = new Credentials(new OcesX509Certificate(clientCertificate), endpointCertificate);
            Request     request     = new Request(endpointAddressUri, credentials);
            RaspRequest raspRequest = new RaspRequest(request);

            return(raspRequest);
        }
Ejemplo n.º 10
0
        private CompiledXslt LoadStyleSheet(XmlDocument body)
        {
            DocumentTypeConfig documentType = _searcher.FindUniqueDocumentType(body);
            //string path = documentType.XsltTransformStylesheetPath;

            string stylesheetPath;
            string basePath = ConfigurationManager.AppSettings["ResourceBasePath"];

            if (string.IsNullOrEmpty(basePath))
            {
                stylesheetPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, documentType.XsltTransformStylesheetPath);
            }
            else
            {
                stylesheetPath = Path.Combine(basePath, documentType.XsltTransformStylesheetPath);
            }

            CompiledXslt compiledXslt = new CompiledXslt(new FileInfo(stylesheetPath));

            return(compiledXslt);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Adds custom RASP headers to a given OiosiMessage
        /// </summary>
        /// <param name="message">The message on which the headers should be added</param>
        /// <param name="documentId">The document Id used in the MessageIdentifier header</param>
        private void AddCustomHeaders(OiosiMessage message, string documentId)
        {
            var typeSearcher = new DocumentTypeConfigSearcher();
            DocumentTypeConfig docTypeConfig = typeSearcher.FindUniqueDocumentType(message.MessageXml);

            // Add custom headers to the message
            Identifier senderIdentifier   = getSenderID(message, docTypeConfig);
            Identifier receiverIdentifier = GetReceiverID(message, docTypeConfig);

            string key = PartyIdentifierHeaderSettings.MessagePropertyKey;
            var    partyIdentifierSetting = new PartyIdentifierHeaderSettings(senderIdentifier, receiverIdentifier);

            message.UbiquitousProperties[key] = partyIdentifierSetting;

            // Adds custom headers by xpaths
            foreach (CustomHeaderXPathConfiguration xpath in docTypeConfig.CustomHeaderConfiguration.XPaths)
            {
                var value         = DocumentXPathResolver.GetElementValueByXPathNavigator(message.MessageXml, xpath.XPath, docTypeConfig.Namespaces);
                var qualifiedName = new XmlQualifiedName(xpath.Name, Definitions.DefaultOiosiNamespace2007);
                message.MessageHeaders[qualifiedName] = MessageHeader.CreateHeader(qualifiedName.Name, qualifiedName.Namespace, value);
            }

            // Add the MessageIdentifier header
            var messageIdentifierHeaderName = new XmlQualifiedName("MessageIdentifier", Definitions.DefaultOiosiNamespace2007);

            message.MessageHeaders[messageIdentifierHeaderName] = MessageHeader.CreateHeader(messageIdentifierHeaderName.Name, messageIdentifierHeaderName.Namespace, documentId);

            // Change the SOAP actions
            if (!string.IsNullOrEmpty(docTypeConfig.EndpointType.RequestAction))
            {
                message.RequestAction = docTypeConfig.EndpointType.RequestAction;
            }
            if (!string.IsNullOrEmpty(docTypeConfig.EndpointType.ReplyAction))
            {
                message.ReplyAction = docTypeConfig.EndpointType.ReplyAction;
            }
        }
Ejemplo n.º 12
0
        private void Validate(string xmlDocumentPath, SchemaValidator validator, string schemaPath)
        {
            // Need the schema cache from the cacheConfiguration
            ConfigurationHandler.ConfigFilePath = "Resources/RaspConfiguration.Live.xml";
            ConfigurationHandler.Reset();

            XmlDocument document = new XmlDocument();

            document.Load(xmlDocumentPath);

            DocumentTypeConfig documentType = _searcher.FindUniqueDocumentType(document);


            if (string.IsNullOrEmpty(documentType.SchemaPath))
            {
                // Empty schema path equal no schema exist.
            }
            else
            {
                SchemaStore  schemaStore  = new SchemaStore();
                XmlSchemaSet xmlSchemaSet = schemaStore.GetCompiledXmlSchemaSet(documentType);
                validator.SchemaValidateXmlDocument(document, xmlSchemaSet);
            }
        }
Ejemplo n.º 13
0
 public void NullArguementTest()
 {
     Assert.Throws <exception.NullArgumentException>(() => _searcher.FindUniqueDocumentType(null));
 }