Exemplo n.º 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);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a new <see cref="ISecurityProvider"/> based on the settings in the config file.
        /// </summary>
        /// <param name="userData">Object that contains data about the user to be used by the security provider.</param>
        /// <returns>An object that implements <see cref="ISecurityProvider"/>.</returns>
        public static ISecurityProvider CreateProvider(UserData userData)
        {
            // Initialize the username
            string username = userData.Username;

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

            // Initialize the provider
            provider.LoadSettings();
            provider.UserData.Clone(userData);

            // Return initialized provider
            return(provider);
        }