Exemple #1
0
        public void EnvironmentVars_Expand_Recursive()
        {
            string cfg1;

            // Old style

            cfg1 =
                @"
var1=HELLO
var2=%var1%
var3=WORLD
var4=%var2% %var3%
";
            EnvironmentVars.Load(cfg1);
            Assert.AreEqual("HELLO", EnvironmentVars.Expand("%var2%"));
            Assert.AreEqual("prefix HELLO suffix", EnvironmentVars.Expand("prefix %var2% suffix"));
            Assert.AreEqual("HELLO WORLD", EnvironmentVars.Expand("%var4%"));

            // New style

            cfg1 =
                @"
var1=HELLO
var2=$(var1)
var3=WORLD
var4=$(var2) $(var3)
";
            EnvironmentVars.Load(cfg1);
            Assert.AreEqual("HELLO", EnvironmentVars.Expand("$(var2)"));
            Assert.AreEqual("prefix HELLO suffix", EnvironmentVars.Expand("prefix $(var2) suffix"));
            Assert.AreEqual("HELLO WORLD", EnvironmentVars.Expand("$(var4)"));
        }
Exemple #2
0
        /// <summary>
        /// Static constructor.
        /// </summary>
        static CoreApp()
        {
            // Initialize this to something reasonable so unit tests will work.
#if DEBUG
            CoreApp.InstallPath = EnvironmentVars.Expand(@"$(LT_ROOT)\Main\Platform\Telephony\NeonSwitchCore\bin\x64\Debug");
#else
            CoreApp.InstallPath = EnvironmentVars.Expand(@"$(LT_ROOT)\Main\Platform\Telephony\NeonSwitchCore\bin\x64\Release");
#endif
        }
Exemple #3
0
        public void EnvironmentVars_Expand_InfiniteRecursion()
        {
            string cfg1;

            // Old style

            cfg1 =
                @"
var1=%var2%
var2=%var1%
";
            EnvironmentVars.Load(cfg1);

            try
            {
                EnvironmentVars.Expand("%var2%");
                Assert.Fail();  // Expected a StackOverflowException
            }
            catch (StackOverflowException)
            {
            }
            catch
            {
                Assert.Fail();  // Expected a StackOverflowException
            }

            // New style

            cfg1 =
                @"
var1=$(var2)
var2=$(var1)
";
            EnvironmentVars.Load(cfg1);

            try
            {
                EnvironmentVars.Expand("$(var2)");
                Assert.Fail();  // Expected a StackOverflowException
            }
            catch (StackOverflowException)
            {
            }
            catch
            {
                Assert.Fail();  // Expected a StackOverflowException
            }
        }
Exemple #4
0
        public void EnvironmentVars_IPAddressing()
        {
            string output;

            // This test exercises the IP address macros without actually checking
            // their values (since they'll differ from machine to machine).  This
            // will test for crashes and also provide a place where these values
            // can be manually verified.

            output = EnvironmentVars.Expand(@"

ip-address = $(ip-address)
ip-mask    = $(ip-mask)
ip-subnet  = $(ip-subnet)
");
        }
Exemple #5
0
        public void EnvironmentVars_BuiltIn()
        {
            EnvironmentVars.Load("");

            Assert.AreEqual(Environment.GetEnvironmentVariable("temp"), EnvironmentVars.Get("temp"));
            Assert.AreEqual(Environment.GetEnvironmentVariable("tmp"), EnvironmentVars.Get("tmp"));
            Assert.AreEqual(Environment.GetEnvironmentVariable("SystemRoot"), EnvironmentVars.Get("SystemRoot"));
            Assert.AreEqual((Environment.GetEnvironmentVariable("SystemRoot") + @"\system32").ToLowerInvariant(), EnvironmentVars.Get("SystemDirectory").ToLowerInvariant());
            Assert.AreEqual(Helper.EntryAssemblyFolder, EnvironmentVars.Get("AppPath"));
            Assert.IsNotNull(EnvironmentVars.Get("OS"));
            Assert.IsNotNull(EnvironmentVars.Get("WINFULL"));
            Assert.IsNull(EnvironmentVars.Get("WINCE"));
            Assert.AreEqual(Helper.GetVersionString(Assembly.GetExecutingAssembly()), EnvironmentVars.Get("appversion"));
            Assert.AreEqual(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), EnvironmentVars.ProgramDataPath);
            Assert.IsTrue(!EnvironmentVars.ProgramDataPath.EndsWith("/"));
            Assert.IsTrue(!EnvironmentVars.ProgramDataPath.EndsWith("\\"));
            Assert.AreNotEqual(EnvironmentVars.Get("guid"), EnvironmentVars.Get("Guid"));
            Assert.AreEqual(Helper.MachineName, EnvironmentVars.Get("MachineName"));
            Assert.AreEqual(Dns.GetHostName(), EnvironmentVars.Get("HostName"));
            Assert.AreEqual(EnvironmentVars.ServerID, EnvironmentVars.Get("ServerID"));

            Assert.AreEqual(Environment.GetEnvironmentVariable("temp"), EnvironmentVars.Expand("$(temp)"));
            Assert.AreEqual(Environment.GetEnvironmentVariable("tmp"), EnvironmentVars.Expand("$(tmp)"));
            Assert.AreEqual(Environment.GetEnvironmentVariable("SystemRoot"), EnvironmentVars.Expand("$(SystemRoot)"));
            Assert.AreEqual((Environment.GetEnvironmentVariable("SystemRoot") + @"\system32").ToLowerInvariant(), EnvironmentVars.Expand("$(SystemDirectory)").ToLowerInvariant());
            Assert.AreEqual(Helper.EntryAssemblyFolder, EnvironmentVars.Expand("$(AppPath)"));
            Assert.IsNotNull(EnvironmentVars.Expand("$(OS)"));
            Assert.IsNotNull(EnvironmentVars.Expand("$(WINFULL)"));
            Assert.AreEqual("$(WINCE)", EnvironmentVars.Expand("$(WINCE)"));
            Assert.AreNotEqual(EnvironmentVars.Expand("$(guid)"), EnvironmentVars.Expand("$(Guid)"));
            Assert.AreEqual(Helper.MachineName, EnvironmentVars.Expand("$(MachineName)"));
            Assert.AreEqual(Environment.ProcessorCount.ToString(), EnvironmentVars.Expand("$(ProcessorCount)"));

            Assert.AreEqual(Const.DCCloudEP.ToString(), EnvironmentVars.Expand("$(LillTek.DC.CloudEP)"));
            Assert.AreEqual(Const.DCCloudGroup.ToString(), EnvironmentVars.Expand("$(LillTek.DC.CloudGroup)"));
            Assert.AreEqual(Const.DCCloudPort.ToString(), EnvironmentVars.Expand("$(LillTek.DC.CloudPort)"));
            Assert.AreEqual(Const.DCRootPort.ToString(), EnvironmentVars.Expand("$(LillTek.DC.RootPort)"));
            Assert.AreEqual(Const.DCDefHubName, EnvironmentVars.Expand("$(LillTek.DC.DefHubName)"));
#if DEBUG
            Assert.AreEqual("true", EnvironmentVars.Expand("$(IsDebug)"));
            Assert.AreEqual("false", EnvironmentVars.Expand("$(IsRelease)"));
#else
            Assert.AreEqual("false", EnvironmentVars.Expand("$(IsDebug)"));
            Assert.AreEqual("true", EnvironmentVars.Expand("$(IsRelease)"));
#endif
        }
Exemple #6
0
        /// <summary>
        /// Queries the realm map provider for the current set of realm mappings.
        /// </summary>
        /// <returns>The list of realm mappings.</returns>
        /// <exception cref="AuthenticationException">Thrown if there's an error getting the map.</exception>
        public List <RealmMapping> GetMap()
        {
            OdbcConnection      dbCon  = null;
            OdbcDataReader      reader = null;
            List <RealmMapping> map    = new List <RealmMapping>();
            OdbcCommand         cmd;

            using (TimedLock.Lock(this))
            {
                if (!IsOpen)
                {
                    throw new AuthenticationException("Provider is closed.");
                }

                dbCon = new OdbcConnection(conString);
                dbCon.Open();

                try
                {
                    cmd             = dbCon.CreateCommand();
                    cmd.CommandText = query;
                    cmd.CommandType = CommandType.Text;

                    reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        map.Add(new RealmMapping(engineSettings,
                                                 SqlHelper.AsString(reader["Realm"]),
                                                 Config.Parse(SqlHelper.AsString(reader["ProviderType"]), (System.Type)null),
                                                 ArgCollection.Parse(EnvironmentVars.Expand(SqlHelper.AsString(reader["Args"]))),
                                                 SqlHelper.AsString(reader["Query"])));
                    }
                }
                finally
                {
                    if (reader != null)
                    {
                        reader.Close();
                    }

                    dbCon.Close();
                }

                return(map);
            }
        }
Exemple #7
0
        /// <summary>
        /// Establishes a session with the authentication extension.
        /// </summary>
        /// <param name="args">The extension specific arguments (see the remarks).</param>
        /// <param name="query">Ignored for this extension.</param>
        /// <param name="perfCounters">The application's performance counter set (or <c>null</c>).</param>
        /// <param name="perfPrefix">The string to prefix any performance counter names (or <c>null</c>).</param>
        /// <remarks>
        /// <para>
        /// This extension recognises the following arguments:
        /// </para>
        /// <list type="table">
        ///     <item>
        ///         <term>Path</term>
        ///         <description>
        ///         The fully qualified path to the credential file.  This argument is required.
        ///         </description>
        ///     </item>
        ///     <item>
        ///         <term>Reload</term>
        ///         <description>
        ///         Indicates whether the credentials file should be reloaded before every authentication
        ///         attempt.  This can have values such as "yes"/"no" or "true"/"false".  This argument
        ///         defaults to "true".
        ///         </description>
        ///     </item>
        ///     <item>
        ///         <term>MaxCacheTime</term>
        ///         <description>
        ///         Specifies the maximum time clients should retain authentication information.
        ///         This is expressed in the same format as timespans parsed by <see cref="Config.Parse(string,TimeSpan)" />.
        ///         This argument defaults to "5m".
        ///         </description>
        ///     </item>
        ///     <item>
        ///         <term>LockoutCount</term>
        ///         <description>
        ///         Specifies the limiting failed authentication count.  Accounts
        ///         will be locked when the fail count reaches this number.
        ///         </description>
        ///     </item>
        ///     <item>
        ///         <term>LockoutThreshold</term>
        ///         <description>
        ///         The period of time that can elapse between failed authentication
        ///         attempts where the failed attempts will <b>not</b> be counted against the
        ///         <b>LockoutCount</b>.  Set this to <see cref="TimeSpan.Zero" />
        ///         to disable account lockout for the realm.
        ///         </description>
        ///     </item>
        ///     <item>
        ///         <term>LockoutTime</term>
        ///         <description>
        ///         The period of time an account will remain locked after being locked
        ///         out due to too many failed authentication attempts.
        ///         </description>
        ///     </item>
        /// </list>
        /// <note>
        /// All calls to <see cref="Open" /> must be matched with a call
        /// to <see cref="Close" /> or <see cref="Dispose" />.
        /// </note>
        /// </remarks>
        public void Open(ArgCollection args, string query, PerfCounterSet perfCounters, string perfPrefix)
        {
            using (TimedLock.Lock(this))
            {
                if (IsOpen)
                {
                    throw new AuthenticationException("Authentication extension is already open.");
                }

                perf         = new Perf(perfCounters, perfPrefix);
                path         = EnvironmentVars.Expand(args["Path"]);
                reload       = args.Get("Reload", true);
                maxCacheTime = args.Get("MaxCacheTime", TimeSpan.FromMinutes(5));

                if (!reload)
                {
                    credentials = LoadCredentials();
                }
            }
        }
Exemple #8
0
        public void EnvironmentVars_Expand()
        {
            string cfg1 =
                @"
var1=INSERT
";

            EnvironmentVars.Load(cfg1);

            // Old style

            Assert.AreEqual("", EnvironmentVars.Expand(""));
            Assert.AreEqual("INSERT", EnvironmentVars.Expand("INSERT"));
            Assert.AreEqual("INSERT", EnvironmentVars.Expand("%var1%"));
            Assert.AreEqual("prefix INSERT suffix", EnvironmentVars.Expand("prefix %VAR1% suffix"));
            Assert.AreEqual("%none%", EnvironmentVars.Expand("%none%"));
            Assert.AreEqual("prefix %none% suffix", EnvironmentVars.Expand("prefix %none% suffix"));
            Assert.AreEqual("%", EnvironmentVars.Expand("%"));
            Assert.AreEqual("%hello", EnvironmentVars.Expand("%hello"));
            Assert.AreEqual("hello%", EnvironmentVars.Expand("hello%"));
            Assert.AreEqual("hello%world", EnvironmentVars.Expand("hello%world"));

            // New style

            Assert.AreEqual("", EnvironmentVars.Expand(""));
            Assert.AreEqual("INSERT", EnvironmentVars.Expand("INSERT"));
            Assert.AreEqual("INSERT", EnvironmentVars.Expand("$(var1)"));
            Assert.AreEqual("prefix INSERT suffix", EnvironmentVars.Expand("prefix $(VAR1) suffix"));
            Assert.AreEqual("$(none)", EnvironmentVars.Expand("$(none)"));
            Assert.AreEqual("prefix $(none) suffix", EnvironmentVars.Expand("prefix $(none) suffix"));
            Assert.AreEqual("$", EnvironmentVars.Expand("$"));
            Assert.AreEqual("$(", EnvironmentVars.Expand("$("));
            Assert.AreEqual("$hello", EnvironmentVars.Expand("$hello"));
            Assert.AreEqual("$(hello", EnvironmentVars.Expand("$(hello"));
            Assert.AreEqual("$(hello)", EnvironmentVars.Expand("$(hello)"));
            Assert.AreEqual("hello)", EnvironmentVars.Expand("hello)"));
            Assert.AreEqual("hello)world", EnvironmentVars.Expand("hello)world"));
        }
Exemple #9
0
        public void EnvironmentVars_ServerID()
        {
            string orgServerID;

            orgServerID = EnvironmentVars.ServerID;
            if (String.Compare(orgServerID, Dns.GetHostName(), true) == 0)
            {
                orgServerID = null;
            }

            try
            {
                EnvironmentVars.ServerID = "www.lilltek.com";
                Assert.AreEqual("www.lilltek.com", EnvironmentVars.Expand("$(ServerID)"));

                EnvironmentVars.ServerID = null;
                Assert.AreEqual(Dns.GetHostName(), EnvironmentVars.Expand("$(ServerID)"));
            }
            finally
            {
                EnvironmentVars.ServerID = orgServerID;
            }
        }
Exemple #10
0
        public void EnvironmentVars_Basic()
        {
            string cfg1 =
                @"
var1=10
// This is a comment  
   var2  =  20   

VAR3=30

path=$(ProgramDataPath)\Foo
";

            EnvironmentVars.Load(cfg1);
            Assert.AreEqual("10", EnvironmentVars.Get("var1"));
            Assert.AreEqual("20", EnvironmentVars.Get("VAR2"));
            Assert.AreEqual("30", EnvironmentVars.Get("var3"));
            Assert.IsNull(EnvironmentVars.Get("var4"));
            Assert.AreEqual(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Foo"), EnvironmentVars.Expand(EnvironmentVars.Get("path")));
        }
Exemple #11
0
        /// <summary>
        /// Starts the router, reading configuration parameters from the
        /// application's configuration settings.
        /// </summary>
        /// <remarks>
        /// <para>
        /// This method will gather the instance settings from the application's
        /// configuration settings, as described below.  Multiple router instances
        /// can be specified in a single configuration file.  The router name
        /// parameter is used to distinguish between the settings for each router
        /// instance.  The method will look for configuration keys prefixed by
        /// </para>
        /// <code language="none">
        /// "MsgRouter." + name + "."
        /// </code>
        /// <para>
        /// So, when loading the TcpEP setting, Start("Foo") will query for
        /// "Router.Foo.TcpEP".
        /// </para>
        /// <para>
        /// Here are the configuration settings LeafRouter expects: (note
        /// that all settings are prefixed by "MsgRouter." as in "MsgRouter.RouterEP".
        /// </para>
        /// <div class="tablediv">
        /// <table class="dtTABLE" cellspacing="0" ID="Table1">
        /// <tr valign="top">
        /// <th width="1">Setting</th>
        /// <th width="1">Default</th>
        /// <th width="90%">Description</th>
        /// </tr>
        /// <tr valign="top"><td>AppName</td><td>EXE file name</td><td>Name of the application hosting the router</td></tr>
        /// <tr valign="top"><td>AppDescription</td><td>(none)</td><td>Description of the application hosting thr router</td></tr>
        /// <tr valign="top">
        ///     <td>RouterEP</td>
        ///     <td>physical://DETACHED/$(LillTek.DC.DefHubName)/$(Guid)</td>
        ///     <td>
        ///         Physical MsgEP for this instance.  The endpoint should be three levels deep
        ///         such as physical://root.com:40/hub/leaf and the leaf name should be unique across
        ///         all leaf routers beneath the hub.  One way to guarantee uniquness is to use the $(guid)
        ///         environment variable in the endpoint, as in physical://root.com:40/hub/$(MachineName)-$(Guid).
        ///         This will be replaced with a newly generated GUID when the configuration variable
        ///         is processed.
        ///     </td>
        /// </tr>
        /// <tr valign="top">
        ///     <td>DiscoveryMode</td>
        ///     <td>MULTICAST</td>
        ///     <td>
        ///     <para>
        ///     Specifies how the router will go about discovering other routers on the
        ///     network.  The possible values are <b>MULTICAST</b> (the default) and
        ///     <b>UDPBROADCAST</b>.
        ///     </para>
        ///     <para>
        ///     If <b>MULTICAST</b> is specified then the router will broadcast and listen
        ///     for presence packets on the specified <see cref="RouterSettings.CloudAdapter"/> for the
        ///     <see cref="RouterSettings.CloudEP" /> multicast endpoint.
        ///     </para>
        ///     <para>
        ///     If <b>UDPBROADCAST</b> is specified then the router will use the LillTek
        ///     Broadcast Server to handle the transmission and reception presence packets
        ///     on networks that don't support multicast.  The <see cref="RouterSettings.BroadcastSettings" />
        ///     property can be used to configure the internal <see cref="UdpBroadcastClient" />
        ///     used to manage these broadcasts.
        ///     </para>
        ///     </td>
        /// </tr>
        /// <tr valign="top"><td>CloudEP</td><td><see cref="Const.DCCloudEP" /></td><td>The discovery UDP multicast network group and port</td></tr>
        /// <tr valign="top"><td>CloudAdapter</td><td>ANY</td><td>The discovery UDP multicast network adapter address</td></tr>
        /// <tr valign="top"><td>MulticastSendBufferSize</td><td>64K</td><td>UDP multicast socket send buffer size</td></tr>
        /// <tr valign="top"><td>MulticastReceiveBufferSize</td><td>64K</td><td>Multicast socket receive buffer size</td></tr>
        /// <tr valign="top">
        ///     <td>BroadcastSettings</td>
        ///     <td>(see note)</td>
        ///     <td>
        ///     Settings for the <see cref="UdpBroadcastClient" /> used to manage the precence
        ///     packets used for router discovery when operating in <see cref="DiscoveryMode.UdpBroadcast "/>
        ///     discovery mode.  This is initialized with reasonable default values.
        ///     </td>
        /// </tr>
        /// <tr valign="top"><td>UdpEP</td><td>ANY:0</td><td>UDP network endpoint</td></tr>
        /// <tr valign="top"><td>UdpMsgQueueCountMax</td><td>1000</td><td>Max queued outbound UDP normal priority messages.</td></tr>
        /// <tr valign="top"><td>UdpMsgQueueSizeMax</td><td>10MB</td><td>Max bytes of serialized queued outbound UDP normal priority messages.</td></tr>
        /// <tr valign="top"><td>UdpSendBufferSize</td><td>64K</td><td>UDP unicast socket send buffer size</td></tr>
        /// <tr valign="top"><td>UdpReceiveBufferSize</td><td>64K</td><td>UDP unicast socket receive buffer size</td></tr>
        /// <tr valign="top"><td>TcpEP</td><td>ANY:0</td><td>TCP listening network endpoint</td></tr>
        /// <tr valign="top"><td>TcpMsgQueueCountMax</td><td>1000</td><td>Max queued outbound TCP normal priority messages.</td></tr>
        /// <tr valign="top"><td>TcpMsgQueueSizeMax</td><td>10MB</td><td>Max bytes of serialized queued outbound TCP normal priority messages.</td></tr>
        /// <tr valign="top"><td>TcpBacklog</td><td>100</td><td>Max pending connecting TCP sockets</td></tr>
        /// <tr valign="top"><td>TcpDelay</td><td>off</td><td>Enables Nagle on TCP channels</td></tr>
        /// <tr valign="top"><td>TcpSendBufferSize</td><td>64K</td><td>TCP socket send buffer size</td></tr>
        /// <tr valign="top"><td>TcpReceiveBufferSize</td><td>64K</td><td>TCP socket receive buffer size</td></tr>
        /// <tr valign="top"><td>BkInterval</td><td>1s</td><td>Background task interval</td></tr>
        /// <tr valign="top"><td>MaxIdle</td><td>5m</td><td>Maximum time a TCP socket should idle before being closed automatically</td></tr>
        /// <tr valign="top"><td>EnableP2P</td><td>true</td><td>Enables peer-to-peer routing between routers on the same subnet</td></tr>
        /// <tr valign="top"><td>AdvertiseTime</td><td>1m</td><td>RouterAdvertiseMsg multicast interval</td></tr>
        /// <tr valign="top"><td>PhysicalRouteTTL</td><td>3m</td><td>Maximum time a physical route will be maintained without being refreshed with a RouterAdvertiseMsg</td></tr>
        /// <tr valign="top"><td>DefMsgTTL</td><td>5</td><td>Default message time-to-live (max hops)</td></tr>
        /// <tr valign="top"><td>SharedKey</td><td>PLAINTEXT</td><td>The shared encryption key used to encrypt all message traffic.</td></tr>
        /// <tr valign="top"><td>SessionCacheTime</td><td>2m</td><td>Default time the router's session manager will cache idempotent replies.</td></tr>
        /// <tr valign="top"><td>SessionRetries</td><td>3</td><td>Maximum session initiation retries.</td></tr>
        /// <tr valign="top"><td>SessionTimeout</td><td>10s</td><td>Default session timeout</td></tr>
        /// <tr valign="top"><td>MaxLogicalAdvertiseEPs</td><td>256</td><td>Maximum number of logical endpoints to be included in a single LogicalAdvertiseMsg</td></tr>
        /// <tr valign="top"><td>DeadRouterTTL</td><td>0s</td><td>Maximum time to wait for a <see cref="ReceiptMsg" /> before declaring a dead router.  Use 0 to disable dead router detection.</td></tr>
        /// <tr valign="top">
        ///     <td>RouteLocal</td>
        ///     <td>(none)</td>
        ///     <td>
        ///     <para>
        ///     An array of zero or more logical routes for which messages should favor
        ///     local destinations.  These routes may include wildcards.  Here's an example
        ///     configuration fragment:
        ///     </para>
        ///     <code lang="none">
        ///     #section MsgRouter
        ///
        ///         RouteLocal[0] = abstract://Test/Local
        ///         RouteLocal[1] = abstract://MyApps/*
        ///
        ///     #endsection
        ///     </code>
        ///     </td>
        /// </tr>
        /// </table>
        /// </div>
        /// </remarks>
        public void Start()
        {
            RouterSettings settings;
            MsgEP          routerEP;
            Config         config;
            string         v;

            // Load the configuration settings

            config = new Config(MsgHelper.ConfigPrefix);

            v = config.Get("RouterEP", EnvironmentVars.Expand("physical://DETACHED/$(LillTek.DC.DefHubName)/$(Guid)"));

            try
            {
                routerEP = MsgEP.Parse(v);
            }
            catch
            {
                throw new MsgException("[MsgRouter.RouterEP] configuration setting is invalid.");
            }

            if (routerEP.Segments.Length != 2)
            {
                throw new MsgException("[MsgRouter.RouterEP] must specify a valid two segment leaf endpoint (eg: physical://root/hub/leaf).");
            }

            settings                            = new RouterSettings(routerEP);
            settings.AppName                    = config.Get("AppName", settings.AppName);
            settings.AppDescription             = config.Get("AppDescription", settings.AppDescription);
            settings.DiscoveryMode              = config.Get <DiscoveryMode>("DiscoveryMode", settings.DiscoveryMode);
            settings.CloudAdapter               = config.Get("CloudAdapter", settings.CloudAdapter);
            settings.CloudEP                    = config.Get("CloudEP", settings.CloudEP);
            settings.BroadcastSettings          = new UdpBroadcastClientSettings(Config.CombineKeys(MsgHelper.ConfigPrefix, "BroadcastSettings"));
            settings.UdpEP                      = config.Get("UdpEP", settings.UdpEP);
            settings.UdpMsgQueueCountMax        = config.Get("UdpMsgQueueCountMax", settings.UdpMsgQueueCountMax);
            settings.UdpMsgQueueSizeMax         = config.Get("UdpMsgQueueSizeMax", settings.UdpMsgQueueSizeMax);
            settings.TcpEP                      = config.Get("TcpEP", settings.TcpEP);
            settings.TcpMsgQueueCountMax        = config.Get("TcpMsgQueueCountMax", settings.TcpMsgQueueCountMax);
            settings.TcpMsgQueueSizeMax         = config.Get("TcpMsgQueueSizeMax", settings.TcpMsgQueueSizeMax);
            settings.TcpBacklog                 = config.Get("TcpBacklog", settings.TcpBacklog);
            settings.MaxIdle                    = config.Get("MaxIdle", settings.MaxIdle);
            settings.EnableP2P                  = config.Get("EnableP2P", settings.EnableP2P);
            settings.SessionCacheTime           = config.Get("SessionCacheTime", settings.SessionCacheTime);
            settings.SessionRetries             = config.Get("SessionRetries", settings.SessionRetries);
            settings.SessionTimeout             = config.Get("SessionTimeout", settings.SessionTimeout);
            settings.TcpDelay                   = config.Get("TcpDelay", settings.TcpDelay);
            settings.BkInterval                 = config.Get("BkInterval", settings.BkInterval);
            settings.DefMsgTTL                  = config.Get("DefMsgTTL", settings.DefMsgTTL);
            settings.PhysicalRouteTTL           = config.Get("PhysicalRouteTTL", settings.PhysicalRouteTTL);
            settings.MaxLogicalAdvertiseEPs     = config.Get("MaxLogicalAdvertiseEPs", settings.MaxLogicalAdvertiseEPs);
            settings.DeadRouterTTL              = config.Get("DeadRouterTTL", settings.DeadRouterTTL);
            settings.MulticastSendBufferSize    = config.Get("MulticastSendBufferSize", settings.MulticastSendBufferSize);
            settings.MulticastReceiveBufferSize = config.Get("MulticastReceiveBufferSize", settings.MulticastReceiveBufferSize);
            settings.UdpSendBufferSize          = config.Get("UdpSendBufferSize", settings.UdpSendBufferSize);
            settings.UdpReceiveBufferSize       = config.Get("UdpReceiveBufferSize", settings.UdpReceiveBufferSize);
            settings.TcpSendBufferSize          = config.Get("TcpSendBufferSize", settings.TcpSendBufferSize);
            settings.TcpReceiveBufferSize       = config.Get("TcpReceiveBufferSize", settings.TcpReceiveBufferSize);
            settings.AdvertiseTime              = config.Get("AdvertiseTime", settings.AdvertiseTime);

            v = config.Get("SharedKey");
            if (!string.IsNullOrWhiteSpace(v))
            {
                try
                {
                    settings.SharedKey = new SymmetricKey(v);
                }
                catch
                {
                    // Ignoring
                }
            }

            // Get the local route endpoints

            foreach (string ep in config.GetArray("RouteLocal"))
            {
                settings.LocalityMap.Add(ep);
            }

            Start(settings);
        }
Exemple #12
0
        /// <summary>
        /// Attempts to load the realm map from the text file.
        /// </summary>
        /// <returns>The new realm map.</returns>
        private List <RealmMapping> LoadMap()
        {
            StreamReader        reader;
            List <RealmMapping> realmMap;
            int lineNum;

            reader = new StreamReader(path, Helper.AnsiEncoding);

            try
            {
                lineNum  = 0;
                realmMap = new List <RealmMapping>();

                while (true)
                {
                    string      map;
                    string[]    fields;
                    string      realm;
                    System.Type providerType;
                    string      args;
                    string      query;

                    map = reader.ReadLine();
                    if (map == null)
                    {
                        break;
                    }

                    lineNum++;

                    map = map.Trim();
                    if (map.Length == 0 || map.StartsWith("//"))
                    {
                        continue;
                    }

                    map = EnvironmentVars.Expand(map);

                    fields = map.Split(new string[] { "$$" }, StringSplitOptions.None);
                    if (fields.Length != 4)
                    {
                        throw new AuthenticationException("{0}({1}): Four realm map fields expected: [{2}]", Path.GetFileName(path), lineNum, map);
                    }

                    realm = fields[0].Trim();
                    args  = fields[2].Trim();
                    query = fields[3].Trim();

                    providerType = Config.Parse(fields[1], (System.Type)null);
                    if (providerType == null)
                    {
                        throw new AuthenticationException("{0}({1}): Unable to instantiate provider class: [{2}]", Path.GetFileName(path), lineNum, fields[1]);
                    }

                    for (int i = 0; i < realmMap.Count; i++)
                    {
                        if (String.Compare(realmMap[i].Realm, realm, true) == 0)
                        {
                            throw new AuthenticationException("{0}({1}): Duplicate realm: {2}", Path.GetFileName(path), realm);
                        }
                    }

                    realmMap.Add(new RealmMapping(engineSettings, realm, providerType, new ArgCollection(args), query));
                }
            }
            finally
            {
                reader.Close();
            }

            return(realmMap);
        }
Exemple #13
0
        /// <summary>
        /// Establishes a session with the realm map provider.
        /// </summary>
        /// <param name="engineSettings">The associated authentication engine's settings.</param>
        /// <param name="key">
        /// This is simply the name of the configuration array that holds the
        /// static realm mappings.
        /// </param>
        /// <remarks>
        /// <para>
        /// This provider simply loads a static list of provider mappings from the
        /// application's configuration settings.  The mappings are loaded from
        /// the configuration key array specified by the <b>key</b> parameter.
        /// Each element in the array specifies a single realm mapping.  The format
        /// of each is mapping is:
        /// </para>
        /// <code language="none">
        ///     &lt;realm&gt;$$&lt;extension typeref&gt;$$&lt;args&gt;$$&lt;query&gt;
        /// </code>
        /// <para>
        /// where <b>realm</b> identifies the authentication realm, <b>extension typeref</b>
        /// specifies the type implementing <see cref="IAuthenticationExtension" /> formatted as
        /// specified for <see cref="Config.Parse(string,System.Type)" />, <b>key</b>
        /// are the provider arguments and <b>query</b> is the optional provider query
        /// string.  Note the use of <b>$$</b> as field separators.  Here's an example
        /// configuration:
        /// </para>
        /// <code language="none">
        /// realm-map[0] = lilltek.com$$LillTek.Datacenter.Server.FileAuthenticationExtension:LillTek.Datacenter.Server.dll$$path=c:\lilltek.txt$$
        /// realm-map[1] = test.com$$LillTek.Datacenter..Server.FileAuthenticationExtension:LillTek.Datacenter.Server.dll$$path=c:\test.txt$$
        /// </code>
        /// <note>
        /// Every call to <see cref="Open" /> should be matched by a call to
        /// <see cref="Close" /> or <see cref="Dispose" />.
        /// </note>
        /// </remarks>
        /// <exception cref="AuthenticationException">Thrown if there's an error loading the map.</exception>
        public void Open(AuthenticationEngineSettings engineSettings, string key)
        {
            string[] configMap;

            using (TimedLock.Lock(this))
            {
                if (IsOpen)
                {
                    throw new AuthenticationException("Provider is already open.");
                }

                this.engineSettings = engineSettings;

                configMap = Config.Global.GetArray(key);
                if (configMap == null)
                {
                    throw new AuthenticationException("Configuration key [{0}] not found.", key);
                }

                realmMap = new List <RealmMapping>();
                foreach (string map in configMap)
                {
                    string[]    fields;
                    string      realm;
                    System.Type providerType;
                    string      args;
                    string      query;

                    fields = map.Split(new string[] { "$$" }, StringSplitOptions.None);
                    if (fields.Length != 4)
                    {
                        throw new AuthenticationException("Four realm map fields expected: [{0}]", map);
                    }

                    realm = fields[0].Trim();
                    args  = fields[2].Trim();
                    query = fields[3].Trim();

                    if (realm.Length == 0)
                    {
                        throw new AuthenticationException("<realm> field cannot be empty.");
                    }

                    providerType = Config.Parse(fields[1], (System.Type)null);
                    if (providerType == null)
                    {
                        throw new AuthenticationException("Unable to instantiate provider class: [{0}]", fields[1]);
                    }

                    for (int i = 0; i < realmMap.Count; i++)
                    {
                        if (String.Compare(realmMap[i].Realm, realm, true) == 0)
                        {
                            throw new AuthenticationException("Duplicate realm: {0}", realm);
                        }
                    }

                    realmMap.Add(new RealmMapping(engineSettings, realm, providerType, new ArgCollection(EnvironmentVars.Expand(args)), query));
                }
            }
        }
Exemple #14
0
        public void SentinelServiceDB_DeployDB()
        {
            SqlTestDatabase    dbTest;
            Package            dbPackage = null;
            DBPackageInstaller dbInstaller;
            DBInstallParams    dbParams;
            DBInstallResult    result;

            using (dbTest = SqlTestDatabase.Create())
            {
                SqlConnectionInfo conInfo;
                SqlContext        ctx = null;
                SqlCommand        cmd;
                DataTable         dt;

                try
                {
                    // Deploy to a non-existent database

                    dbPackage   = new Package(EnvironmentVars.Expand("$(LT_BUILD)\\LillTek.SentinelService.dbpack"));
                    dbParams    = new DBInstallParams("SentinelService", dbTest.ConnectionInfo.Database);
                    dbInstaller = new DBPackageInstaller(dbPackage);

                    result = dbInstaller.Install(dbParams);
                    Assert.AreEqual(DBInstallResult.Installed, result);

                    conInfo = SqlConnectionInfo.Parse(dbInstaller.ConnectionString);
                    ctx     = new SqlContext(conInfo);
                    ctx.Open();

                    cmd = ctx.CreateSPCall("GetProductInfo");
                    dt  = ctx.ExecuteTable(cmd);
                    Assert.AreEqual(1, dt.Rows.Count);

                    cmd = ctx.CreateSPCall("Ping");
                    dt  = ctx.ExecuteTable(cmd);
                    Assert.AreEqual(1, dt.Rows.Count);
                    Assert.AreEqual("OK", SqlHelper.AsString(dt.Rows[0]["STATUS"]));

                    ctx.Close();
                    ctx = null;

                    // Deploy again and we should see that the database is up-to-date.

                    SqlConnection.ClearAllPools();
                    result = dbInstaller.Install(dbParams);
                    Assert.AreEqual(DBInstallResult.UpToDate, result);
                }
                finally
                {
                    if (dbPackage != null)
                    {
                        dbPackage.Close();
                    }

                    if (ctx != null)
                    {
                        ctx.Close();
                    }
                }
            }
        }
Exemple #15
0
 /// <summary>
 /// Constructs the default router settings.
 /// </summary>
 public RouterSettings()
 {
     this.RouterEP = EnvironmentVars.Expand("physical://DETACHED/$(LillTek.DC.DefHubName)/$(Guid)");
 }