Пример #1
0
        public void Start()
        {
            DefaultDocumentTypes documentTypes = new DefaultDocumentTypes();

            documentTypes.CleanAdd();
            _searcher = new DocumentTypeConfigSearcher();
        }
Пример #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);
        }
Пример #3
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");
        }
Пример #4
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);
        }
Пример #5
0
        public UtilitiesTest()
        {
            DefaultDocumentTypes documentTypes = new DefaultDocumentTypes();

            documentTypes.CleanAdd();
            _searcher = new DocumentTypeConfigSearcher();
        }
Пример #6
0
 public DocumentTypeConfigSearcherTest()
 {
     ConfigurationHandler.ConfigFilePath = "Resources/DocumentTypeSearcherRaspConfiguration.xml";
     ConfigurationHandler.Reset();
     _documentTypes = new DefaultDocumentTypes();
     _documentTypes.CleanAdd();
     AddNoNamespaceTestDocumentType();
     _searcher = new DocumentTypeConfigSearcher();
     ConfigurationHandler.SaveToFile();
 }
Пример #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));
        }
Пример #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);
     }
 }
Пример #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);
        }
Пример #10
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;
            }
        }
Пример #11
0
 /// <summary>
 /// Constructor that takes a PruningBindingExtensionElement which contains
 /// configuration information to the pruning interceptor.
 /// </summary>
 /// <param name="configuration"></param>
 public ServerXsltTransformationBindingElement(ServerXsltTransformationBindingExtensionElement configuration)
 {
     _configuration = configuration;
     _xsltUtility   = new XsltUtility();
     _searcher      = new DocumentTypeConfigSearcher();
 }
Пример #12
0
 /// <summary>
 /// Constructor
 /// </summary>
 public SchematronValidatorWithLookup()
 {
     this.searcher = new DocumentTypeConfigSearcher();
     this.logger   = LoggerFactory.Create(this.GetType());
 }