Example #1
0
        // Static Methods

        /// <summary>
        /// Creates a new <see cref="ISecurityProvider"/> based on the settings in the config file.
        /// </summary>
        /// <param name="username">Username of the user for whom the <see cref="ISecurityProvider"/> is to be created.</param>
        /// <returns>An object that implements <see cref="ISecurityProvider"/>.</returns>
        public static ISecurityProvider CreateProvider(string username)
        {
            // Initialize the username
            if (string.IsNullOrEmpty(username))
            {
                username = Thread.CurrentPrincipal.Identity.Name;
            }

            // If an application is being launched from an installer it will have the NT AUTHORITY\System Identity which
            // will not have available user information - so we pickup username from Environment instead
            if (username.StartsWith("NT AUTHORITY\\", StringComparison.OrdinalIgnoreCase))
            {
                username = Environment.UserDomainName + "\\" + Environment.UserName;
            }

            // Instantiate the provider
            // ReSharper disable once AssignNullToNotNullAttribute
            ISecurityProvider provider = ProviderFactory(username);

            // Initialize the provider
            provider.LoadSettings();

            if (provider.CanRefreshData)
            {
                provider.RefreshData();
            }

            // Return initialized provider
            return(provider);
        }
Example #2
0
            /// <summary>
            /// Refreshes the provider managed by this <see cref="CacheContext"/>.
            /// </summary>
            public bool Refresh()
            {
                try
                {
                    ISecurityProvider provider = _Provider;

                    if ((object)provider == null)
                    {
                        return(false);
                    }

                    if (provider.CanRefreshData)
                    {
                        provider.RefreshData();
                    }

                    provider.Authenticate();
                    LastRefreshTime = DateTime.UtcNow;

                    return(true);
                }
                catch (ObjectDisposedException)
                {
                    m_disposed = true;
                    return(false);
                }
            }
Example #3
0
            /// <summary>
            /// Refreshes the provider managed by this <see cref="CacheContext"/>.
            /// </summary>
            public bool Refresh()
            {
                ISecurityProvider provider = Provider;

                if ((object)provider == null)
                {
                    return(false);
                }

                provider.RefreshData();
                provider.Authenticate();
                m_lastRefreshTime = DateTime.UtcNow;

                return(true);
            }