/// <summary> /// Opens the authenticator using the settings passed. /// </summary> /// <param name="router">The router to be used for messaging.</param> /// <param name="settings">The <see cref="AuthenticatorSettings" /> instance to use.</param> public void Open(MsgRouter router, AuthenticatorSettings settings) { using (TimedLock.Lock(this)) { if (isOpen) { throw new AuthenticationException("Authenticator is already open."); } // Load the configuration settings cacheFlushInterval = settings.CacheFlushInterval; successTTL = settings.SuccessTTL; failTTL = settings.FailTTL; // Crank this sucker up. if (settings.MaxCacheSize > 0) { cache = new TimedLRUCache <string, AuthenticationResult>(); cache.MaxItems = settings.MaxCacheSize; } else { cache = null; } this.router = router; this.bkTimer = new GatedTimer(new TimerCallback(OnBkTimer), null, settings.BkTaskInterval); this.isOpen = true; this.cacheFlushTime = SysTime.Now + cacheFlushInterval; router.Dispatcher.AddTarget(this); } }
//--------------------------------------------------------------------- // Static members /// <summary> /// Loads the <see cref="Authenticator" /> settings from the application configuration. /// </summary> /// <param name="keyPrefix">The configuration key prefix.</param> /// <returns>The settings.</returns> /// <remarks> /// <para> /// The settings will loaded are: /// </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>BkTaskInterval</td> /// <td>1s</td> /// <td>The interval at which background tasks are scheduled for the instance.</td> /// </tr> /// <tr valign="top"> /// <td>CacheFlushInterval</td> /// <td>1m</td> /// <td>Time interval between scheduled cache flushes.</td> /// </tr> /// <tr valign="top"> /// <td>MaxCacheSize</td> /// <td>10000</td> /// <td>Maximum number of authentication credentials to be cached. Use 0 to disable caching.</td> /// </tr> /// <tr valign="top"> /// <td>SuccessTTL</td> /// <td>5m</td> /// <td>Duration that successfully authenticated credentials will be cached. Use 0 to disable success caching.</td> /// </tr> /// <tr valign="top"> /// <td>FailTTL</td> /// <td>5m</td> /// <td>Duration that invalid credentials will be cached. Use 0 to disable failure caching.</td> /// </tr> /// </table> /// </div> /// </remarks> public static AuthenticatorSettings LoadConfig(string keyPrefix) { var settings = new AuthenticatorSettings(); var config = new Config(keyPrefix); settings.BkTaskInterval = config.Get("BkTaskInterval", settings.BkTaskInterval); settings.CacheFlushInterval = config.Get("CacheFlushInterval", settings.CacheFlushInterval); settings.MaxCacheSize = config.Get("MaxCacheSize", settings.MaxCacheSize); settings.SuccessTTL = config.Get("SuccessTTL", settings.SuccessTTL); settings.FailTTL = config.Get("FailTTL", settings.FailTTL); return(settings); }
/// <summary> /// Opens the authenticator instance using settings loaded from the /// application configuration. /// </summary> /// <param name="router">The router to be used for messaging.</param> /// <param name="keyPrefix">Application configuration key prefix for the instance settings.</param> /// <exception cref="AuthenticationException">Thrown if the authenticator is already open.</exception> /// <remarks> /// See <see cref="AuthenticatorSettings" /> for a description of the configuration /// settings loaded. /// </remarks> public void Open(MsgRouter router, string keyPrefix) { Open(router, AuthenticatorSettings.LoadConfig(keyPrefix)); }