/// <summary> /// Set an authentication provider by method. /// </summary> /// <param name="authenticationMethod">Authentication method.</param> /// <param name="provider">Authentication provider.</param> /// <returns>True if succeeded, false otherwise, e.g., the existing provider disallows overriding.</returns> public bool SetProvider(SqlAuthenticationMethod authenticationMethod, SqlAuthenticationProvider provider) { if (!provider.IsSupported(authenticationMethod)) { throw SQL.UnsupportedAuthenticationByProvider(authenticationMethod.ToString(), provider.GetType().Name); } var methodName = "SetProvider"; if (_authenticationsWithAppSpecifiedProvider.Contains(authenticationMethod)) { _sqlAuthLogger.LogError(_typeName, methodName, $"Failed to add provider {GetProviderType(provider)} because a user-defined provider with type {GetProviderType(_providers[authenticationMethod])} already existed for authentication {authenticationMethod}."); return(false); } _providers.AddOrUpdate(authenticationMethod, provider, (key, oldProvider) => { if (oldProvider != null) { oldProvider.BeforeUnload(authenticationMethod); } if (provider != null) { provider.BeforeLoad(authenticationMethod); } _sqlAuthLogger.LogInfo(_typeName, methodName, $"Added auth provider {GetProviderType(provider)}, overriding existed provider {GetProviderType(oldProvider)} for authentication {authenticationMethod}."); return(provider); }); return(true); }
/// <summary> /// Set an authentication provider by method. /// </summary> /// <param name="authenticationMethod">Authentication method.</param> /// <param name="provider">Authentication provider.</param> /// <returns>True if succeeded, false otherwise, e.g., the existing provider disallows overriding.</returns> public bool SetProvider(SqlAuthenticationMethod authenticationMethod, SqlAuthenticationProvider provider) { if (!provider.IsSupported(authenticationMethod)) { throw SQL.UnsupportedAuthenticationByProvider(authenticationMethod.ToString(), provider.GetType().Name); } if (_authenticationsWithAppSpecifiedProvider.Contains(authenticationMethod)) { } _providers.AddOrUpdate(authenticationMethod, provider, (key, oldProvider) => { if (oldProvider != null) { oldProvider.BeforeUnload(authenticationMethod); } if (provider != null) { provider.BeforeLoad(authenticationMethod); } return(provider); }); return(true); }