Beispiel #1
0
        public static void RemoveService(string internalurl)
        {
            ConfigLoader cf  = new ConfigLoader();
            PCSBinding   svc = GetPCSProxyAdmin(cf.PCSurls[0]);
            DeleteServicePolicyRequestMsg r = new DeleteServicePolicyRequestMsg();

            r.classification        = new SecurityWrapper();
            r.deletePerformanceData = true;
            r.URL = internalurl;
            svc.DeleteServicePolicy(r);
        }
Beispiel #2
0
        public static PCSBinding GetPCSProxyAdmin(string url)
        {
            ServicePointManager.Expect100Continue = false;
            PCSBinding r = new PCSBinding();

            r.Url         = url;
            r.Credentials = new NetworkCredential(ConfigurationManager.AppSettings["FGSMSadmin"], ConfigurationManager.AppSettings["FGSMSadminpass"]);
            return(r);

            /*
             * BasicHttpBinding b = null;
             * b = new BasicHttpBinding(BasicHttpSecurityMode.TransportCredentialOnly);
             * b.Security.Transport.Realm = "FGSMS Services";
             * b.MaxBufferSize = Int32.MaxValue;
             * b.MaxReceivedMessageSize = Int32.MaxValue;
             * b.MaxBufferPoolSize = Int32.MaxValue;
             * b.TransferMode = TransferMode.Buffered;
             * b.Name = "AgentBinding";
             * b.ReaderQuotas.MaxArrayLength = Int32.MaxValue;
             * b.ReaderQuotas.MaxBytesPerRead = Int32.MaxValue;
             * b.ReaderQuotas.MaxDepth = Int32.MaxValue;
             * b.ReaderQuotas.MaxNameTableCharCount = Int32.MaxValue;
             * b.ReaderQuotas.MaxStringContentLength = Int32.MaxValue;
             * b.ReceiveTimeout = new TimeSpan(0, 5, 0);
             * b.SendTimeout = new TimeSpan(0, 5, 0);
             * b.UseDefaultWebProxy = true;
             * b.TextEncoding = Encoding.UTF8;
             * b.OpenTimeout = new TimeSpan(0, 0, 5);
             * //b.Namespace = "urn:org.miloss.FGSMS.services.interfaces.policyConfiguration";
             * b.MessageEncoding = WSMessageEncoding.Text;
             * b.CloseTimeout = new TimeSpan(0, 0, 5);
             *
             *
             * b.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
             *
             *
             * ChannelFactory<PCS> factory =
             *  new ChannelFactory<PCS>(b, url);
             * HttpRequestMessageProperty p = new HttpRequestMessageProperty();
             * p.Headers.Add(HttpRequestHeader.Authorization, "Basic " + Convert.ToBase64String(Encoding.ASCII.GetBytes(ConfigurationManager.AppSettings["FGSMSadmin"] + ":" + ConfigurationManager.AppSettings["FGSMSadminpass"])));
             *
             * // factory.Credentials.UserName = new System.ServiceModel.Security.UserNamePasswordClientCredential();
             * factory.Credentials.UserName.UserName = ConfigurationManager.AppSettings["FGSMSadmin"];
             * factory.Credentials.SupportInteractive = false;
             * factory.Credentials.UserName.Password = ConfigurationManager.AppSettings["FGSMSadminpass"];
             *
             *
             * PCS polservice = factory.CreateChannel();
             * OperationContextScope scope = new OperationContextScope((IClientChannel)polservice);
             * OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = p;
             * return polservice;*/
        }
Beispiel #3
0
 public static PCSBinding GetPCSProxy(string url, string username, string password, ConfigLoader.AuthMode authMode, string pkiinfo)
 {
     ServicePointManager.Expect100Continue = false;
     PCSBinding r = new PCSBinding();
     r.Url = url;
     switch (authMode)
     {
         case ConfigLoader.AuthMode.usernamePassword:
             r.Credentials = new NetworkCredential(username, (password));
             break;
         case ConfigLoader.AuthMode.PKI:
             r.ClientCertificates.Add(FindCert(pkiinfo));
             break;
     }
     return r;
 }
Beispiel #4
0
        public static PCSBinding GetPCSProxy(string url, string username, string password, ConfigLoader.AuthMode authMode, string pkiinfo)
        {
            ServicePointManager.Expect100Continue = false;
            PCSBinding r = new PCSBinding();

            r.Url = url;
            switch (authMode)
            {
            case ConfigLoader.AuthMode.usernamePassword:
                r.Credentials = new NetworkCredential(username, (password));
                break;

            case ConfigLoader.AuthMode.PKI:
                r.ClientCertificates.Add(FindCert(pkiinfo));
                break;
            }
            return(r);
        }
Beispiel #5
0
        /// <summary>
        /// This function will return a proxy to the PCS service using the provided username and password
        /// OR if FGSMS is configured for PKI auth, the certinfo field will be used to search for a certificate
        /// </summary>
        /// <param name="url"></param>
        /// <param name="Myusername"></param>
        /// <param name="Mypassword"></param>
        /// <param name="certinfo"></param>
        /// <returns></returns>
        public PCSBinding GetPCSProxy(string url, string Myusername, string Mypassword, string certinfo)
        {
            ServicePointManager.Expect100Continue = false;
            PCSBinding r = new PCSBinding();

            r.Url = url;
            switch (authMode)
            {
            case AuthMode.usernamePassword:
                r.Credentials = new NetworkCredential(Myusername, Mypassword);
                break;

            case AuthMode.PKI:
                r.ClientCertificates.Add(FindCert(certinfo));
                break;
            }
            return(r);
        }
Beispiel #6
0
        public static void SetPolicy(string internalurl, bool recordrequest, bool requestresponse)
        {
            if (String.IsNullOrEmpty(internalurl))
            {
                throw new ArgumentNullException("url");
            }
            TransactionalWebServicePolicy tp = new TransactionalWebServicePolicy();

            tp.PolicyType            = policyType.Transactional;
            tp.URL                   = internalurl;
            tp.RecordHeaders         = true;
            tp.RecordRequestMessage  = recordrequest;
            tp.RecordResponseMessage = requestresponse;
            tp.MachineName           = Environment.MachineName.ToLower();
            tp.BuellerEnabled        = false;
            ConfigLoader cf  = new ConfigLoader();
            PCSBinding   svc = GetPCSProxyAdmin(cf.PCSurls[0]);
            SetServicePolicyRequestMsg req = new SetServicePolicyRequestMsg();

            req.classification = new SecurityWrapper();
            req.policy         = tp;
            req.URL            = internalurl;
            svc.SetServicePolicy(req);
        }
Beispiel #7
0
 /// <summary>
 /// This function will return a proxy to the PCS service using the provided username and password
 /// OR if FGSMS is configured for PKI auth, the certinfo field will be used to search for a certificate
 /// </summary>
 /// <param name="url"></param>
 /// <param name="Myusername"></param>
 /// <param name="Mypassword"></param>
 /// <param name="certinfo"></param>
 /// <returns></returns>
 public PCSBinding GetPCSProxy(string url, string Myusername, string Mypassword, string certinfo)
 {
     ServicePointManager.Expect100Continue = false;
     PCSBinding r = new PCSBinding();
     r.Url = url;
     switch (authMode)
     {
         case AuthMode.usernamePassword:
             r.Credentials = new NetworkCredential(Myusername, Mypassword);
             break;
         case AuthMode.PKI:
             r.ClientCertificates.Add(FindCert(certinfo));
             break;
     }
     return r;
 }
Beispiel #8
0
        public static PCSBinding GetPCSProxyAdmin(string url)
        {
            ServicePointManager.Expect100Continue = false;
            PCSBinding r = new PCSBinding();
            r.Url = url;
            r.Credentials = new NetworkCredential( ConfigurationManager.AppSettings["FGSMSadmin"], ConfigurationManager.AppSettings["FGSMSadminpass"]);
            return r;
            /*
            BasicHttpBinding b = null;
            b = new BasicHttpBinding(BasicHttpSecurityMode.TransportCredentialOnly);
            b.Security.Transport.Realm = "FGSMS Services";
            b.MaxBufferSize = Int32.MaxValue;
            b.MaxReceivedMessageSize = Int32.MaxValue;
            b.MaxBufferPoolSize = Int32.MaxValue;
            b.TransferMode = TransferMode.Buffered;
            b.Name = "AgentBinding";
            b.ReaderQuotas.MaxArrayLength = Int32.MaxValue;
            b.ReaderQuotas.MaxBytesPerRead = Int32.MaxValue;
            b.ReaderQuotas.MaxDepth = Int32.MaxValue;
            b.ReaderQuotas.MaxNameTableCharCount = Int32.MaxValue;
            b.ReaderQuotas.MaxStringContentLength = Int32.MaxValue;
            b.ReceiveTimeout = new TimeSpan(0, 5, 0);
            b.SendTimeout = new TimeSpan(0, 5, 0);
            b.UseDefaultWebProxy = true;
            b.TextEncoding = Encoding.UTF8;
            b.OpenTimeout = new TimeSpan(0, 0, 5);
            //b.Namespace = "urn:org.miloss.FGSMS.services.interfaces.policyConfiguration";
            b.MessageEncoding = WSMessageEncoding.Text;
            b.CloseTimeout = new TimeSpan(0, 0, 5);

            b.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;

            ChannelFactory<PCS> factory =
                new ChannelFactory<PCS>(b, url);
            HttpRequestMessageProperty p = new HttpRequestMessageProperty();
            p.Headers.Add(HttpRequestHeader.Authorization, "Basic " + Convert.ToBase64String(Encoding.ASCII.GetBytes(ConfigurationManager.AppSettings["FGSMSadmin"] + ":" + ConfigurationManager.AppSettings["FGSMSadminpass"])));

            // factory.Credentials.UserName = new System.ServiceModel.Security.UserNamePasswordClientCredential();
            factory.Credentials.UserName.UserName = ConfigurationManager.AppSettings["FGSMSadmin"];
            factory.Credentials.SupportInteractive = false;
            factory.Credentials.UserName.Password = ConfigurationManager.AppSettings["FGSMSadminpass"];

            PCS polservice = factory.CreateChannel();
            OperationContextScope scope = new OperationContextScope((IClientChannel)polservice);
            OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = p;
            return polservice;*/
        }
Beispiel #9
0
        private static PolicyHelper FetchPolicy(string URL)
        {
            MessageProcessor m = MessageProcessor.Instance;
            if (config.OperatingMode == ConfigLoader.OperationMode.OFFLINE)
                return GetDefaultPolicy(URL);
            PolicyHelper myPolicy = null;
            //first lets check our policy cache, if we don't have one cached or it's out of date, update it.
            lock (policyCache)
            {
                myPolicy = (PolicyHelper)policyCache[URL];
                if (myPolicy == null)
                {
                    switch (config.PCSalgo)
                    {
                        case ConfigLoader.Algorithm.FAILOVER:
                            for (int i = 0; i < config.pcsurl.Count; i++)
                            {
                                if (polservice != null)
                                {
                                    try
                                    {
                                        ((IClientChannel)polservice).Close();
                                        ((IClientChannel)polservice).Dispose();
                                    }
                                    catch (Exception ex)
                                    {
                                        //log.TraceEvent(TraceEventType.Warning, 0, "Uh oh" + ex.Message + ex.StackTrace);
                                    }
                                }
                                polservice = config.GetPCSProxy(config.pcsurl[i]);
                                for (int k = 0; k < config.PCSretrycount; k++)
                                {
                                    try
                                    {

                                        ServicePolicyRequestMsg requestr = new ServicePolicyRequestMsg();
                                        //requestr = new ServicePolicyRequestMsg();
                                        requestr.URI = URL;
                                        //remember, .NET/IIS is not case sensitive
                                        // ServicePolicyRequestMsg r = new ServicePolicyRequestMsg();

                                        requestr.classification = currentlevel;
                                        ServicePolicyResponseMsg responsep1 = polservice.GetServicePolicy(requestr);
                                        PolicyHelper temp = new PolicyHelper();
                                        temp.lastUpdate = DateTime.Now;
                                        if (responsep1.policy.GetType() != typeof(TransactionalWebServicePolicy))
                                        {
                                            Logger.info("FGSMS.MessageProcessor" + "Successfully retrieved a policy from the policy configuration service, however it was of an unexpected type " + URL + " type info " + responsep1.policy.GetType().FullName);
                                            throw new ArgumentOutOfRangeException();
                                        }
                                        temp.policy = (TransactionalWebServicePolicy)responsep1.policy;
                                        MAXCAP = temp.policy.RecordedMessageCap;
                                        Enabled = temp.policy.AgentsEnabled;
                                        try
                                        {
                                            policyCache.Add(URL, temp);
                                        }
                                        catch (Exception e)
                                        {
                                            Logger.debug(e, "error caught adding " + URL + " to the policy cache");
                                        }

                                        currentlevel = responsep1.classification;
                                        Logger.info("FGSMS.MessageProcessor" + "Successfully Refreshed policy from the policy configuration service for " + URL);

                                        myPolicy = policyCache[URL] as PolicyHelper;
                                        return myPolicy;
                                    }
                                    //{"There was no endpoint listening at http://localhost:8080/FGSMSServices/PCS that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details."}
                                    catch (EndpointNotFoundException ex)
                                    {
                                        _lasterror = ex.GetType().FullName + " " + ex.Message;
                                        Logger.info(ex, "FGSMS.MessageProcessor" + "unable to transmit to " + config.pcsurl[i]);
                                        //this means that the current PCS url is not functioning, try moving to the next one
                                        //polservice = config.GetPCSProxy();
                                    }
                                    catch (Exception ex)
                                    {
                                        Logger.info(ex, "FGSMS.MessageProcessor" + "unable to transmit to " + config.pcsurl[i] + " Policy Updater - failed to policy from the policy configuration service for " + URL + " check that the URL and credentials are correct");
                                    }
                                }

                            }
                            break;
                        case ConfigLoader.Algorithm.ROUNDROBIN:
                            for (int k = 0; k < config.PCSretrycount; k++)
                            {
                                for (int i = 0; i < config.pcsurl.Count; i++)
                                {
                                    try
                                    {
                                        if (polservice != null)
                                        {
                                            try
                                            {
                                                ((IClientChannel)polservice).Close();
                                                ((IClientChannel)polservice).Dispose();
                                            }
                                            catch (Exception ex)
                                            {
                                                //       log.TraceEvent(TraceEventType.Warning, 0, "Uh oh" + ex.Message + ex.StackTrace);
                                            }
                                        }
                                        polservice = config.GetPCSProxy(config.pcsurl[i]);
                                        ServicePolicyRequestMsg requestr = new ServicePolicyRequestMsg();
                                        //requestr = new ServicePolicyRequestMsg();
                                        requestr.URI = URL;
                                        //remember, .NET/IIS is not case sensitive
                                        // GetServicePolicyRequest r = new GetServicePolicyRequest();
                                        // r.request = requestr;
                                        requestr.classification = currentlevel;
                                        ServicePolicyResponseMsg responsep1 = polservice.GetServicePolicy(requestr);
                                        PolicyHelper temp = new PolicyHelper();
                                        temp.lastUpdate = DateTime.Now;
                                        if (responsep1.policy.GetType() != typeof(TransactionalWebServicePolicy))
                                        {
                                            Logger.info("FGSMS.MessageProcessor" + "Successfully retrieved a policy from the policy configuration service, however it was of an unexpected type " + URL + " type info " + responsep1.policy.GetType().FullName);
                                            throw new ArgumentOutOfRangeException();
                                        }
                                        temp.policy = (TransactionalWebServicePolicy)responsep1.policy;
                                        MAXCAP = temp.policy.RecordedMessageCap;
                                        Enabled = temp.policy.AgentsEnabled;
                                        try
                                        {
                                            policyCache.Add(URL, temp);
                                        }
                                        catch (Exception e)
                                        {
                                            Logger.debug(e, "error caught adding " + URL + " to the policy cache");
                                            //its possible that there is another instance of this class running, even through there isn't supposed to be.
                                        }

                                        currentlevel = responsep1.classification;
                                        Logger.info("FGSMS.MessageProcessor" + "Successfully Refreshed policy from the policy configuration service for " + URL);

                                        myPolicy = policyCache[URL] as PolicyHelper;
                                        return myPolicy;
                                    }
                                    //{"There was no endpoint listening at http://localhost:8080/FGSMSServices/PCS that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details."}
                                    catch (EndpointNotFoundException ex)
                                    {
                                        _lasterror = ex.GetType().FullName + " " + ex.Message;
                                        //this means that the current PCS url is not function, try moving to the next one
                                        //polservice = config.GetPCSProxy();
                                        Logger.info(ex, "FGSMS.MessageProcessor" + "unable to transmit to " + config.pcsurl[i]);
                                    }
                                    catch (Exception ex)
                                    {
                                        Logger.info(ex, "FGSMS.MessageProcessor" + "unable to transmit to " + config.pcsurl[i] + " Policy Updater - failed to policy from the policy configuration service for " + URL + " check that the URL and credentials are correct");
                                    }
                                }

                            }
                            break;

                    }
                    if (myPolicy == null)
                    {
                        Logger.error("FGSMS.MessageProcessor" + "Cannot contact the policy config service. Reverting to default policy. ");

                        return GetDefaultPolicy(URL);
                    }
                }
            }

            TimeSpan times = XmlConvert.ToTimeSpan(myPolicy.policy.PolicyRefreshRate);
            if ((DateTime.Now.Ticks - myPolicy.lastUpdate.Ticks) > times.Ticks)
            {
                //TODO load balance this
                //if the policy is out of date, update it.
                try
                {
                    //policyConfigurationServiceClient service = new policyConfigurationServiceClient();
                    ServicePolicyRequestMsg requestr = new ServicePolicyRequestMsg();

                    requestr.URI = URL;
                    //ServicePolicyRequest r = new GetServicePolicyRequest();
                    //r.request = requestr;
                    requestr.classification = currentlevel;
                    ServicePolicyResponseMsg responsep = polservice.GetServicePolicy(requestr);
                    policyCache.Remove(URL);
                    PolicyHelper temp = new PolicyHelper();
                    if (responsep.policy.GetType() != typeof(TransactionalWebServicePolicy))
                    {
                        Logger.info("FGSMS.MessageProcessor" + "Successfully retrieved a policy from the policy configuration service, however it was of an unexpected type " + URL + " type info " + responsep.policy.GetType().FullName);
                        throw new ArgumentOutOfRangeException();
                    }
                    temp.policy = (TransactionalWebServicePolicy)responsep.policy;
                    temp.lastUpdate = DateTime.Now;
                    currentlevel = responsep.classification;
                    try
                    {
                        policyCache.Add(URL, temp);
                    }
                    catch (Exception e)
                    {
                        Logger.debug(e, "error caught adding " + URL + " to the policy cache");
                    }
                    Logger.info("Policy Updater- Successfully Refreshed policy from the policy configuration service for " + URL.ToString());
                    return temp;
                }
                catch (Exception ex)
                {
                    Logger.warn(ex, "Policy update failure, unable to update policy for " + URL + ". Using old policy instead. Error:");

                }
            }
            return myPolicy;
        }