Skip to content

Commit a536885

Browse files
Remove Diagnostic Source + Configuration Manager from .NET Standard DLL as it's not supported (#535)
1 parent 6e09b54 commit a536885

15 files changed

+241
-154
lines changed

src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
<Compile Include="..\..\src\Microsoft\Data\SqlClient\SqlClientEventSource.cs">
3434
<Link>Microsoft\Data\SqlClient\SqlClientEventSource.cs</Link>
3535
</Compile>
36-
<Compile Include="..\..\src\Microsoft\Data\SqlClient\SqlClientLogger.cs" >
36+
<Compile Include="..\..\src\Microsoft\Data\SqlClient\SqlClientLogger.cs">
3737
<Link>Microsoft\Data\SqlClient\SqlClientLogger.cs</Link>
3838
</Compile>
3939
<Compile Include="..\..\src\Microsoft\Data\Sql\SqlNotificationRequest.cs">
@@ -66,7 +66,7 @@
6666
<Compile Include="..\..\src\Microsoft\Data\SqlClient\ColumnEncryptionKeyInfo.cs">
6767
<Link>Microsoft\Data\SqlClient\ColumnEncryptionKeyInfo.cs</Link>
6868
</Compile>
69-
<Compile Include="..\..\src\Microsoft\Data\SqlClient\OnChangedEventHandler.cs" >
69+
<Compile Include="..\..\src\Microsoft\Data\SqlClient\OnChangedEventHandler.cs">
7070
<Link>Microsoft\Data\SqlClient\OnChangedEventHandler.cs</Link>
7171
</Compile>
7272
<Compile Include="..\..\src\Microsoft\Data\SqlClient\SqlAeadAes256CbcHmac256Algorithm.cs">
@@ -143,13 +143,17 @@
143143
<Compile Include="Microsoft.Data.SqlClient.TypeForwards.cs" />
144144
</ItemGroup>
145145
<ItemGroup Condition="'$(OSGroup)' != 'AnyOS' AND '$(TargetGroup)' == 'netstandard'">
146+
<Compile Include="Microsoft\Data\SqlClient\SqlAuthenticationProviderManager.NetStandard.cs" />
147+
<Compile Include="Microsoft\Data\SqlClient\SqlDiagnosticListener.NetStandard.cs" />
146148
<Compile Include="Microsoft\Data\SqlClient\EnclaveDelegate.NetStandard.cs" />
147149
</ItemGroup>
148150
<ItemGroup Condition="'$(OSGroup)' != 'AnyOS' AND '$(TargetGroup)' == 'netcoreapp'">
149151
<Compile Include="Microsoft\Data\Common\DbConnectionStringCommon.NetCoreApp.cs" />
150152
<Compile Include="Microsoft\Data\ProviderBase\DbConnectionPool.NetCoreApp.cs" />
153+
<Compile Include="Microsoft\Data\SqlClient\SqlAuthenticationProviderManager.NetCoreApp.cs" />
151154
<Compile Include="Microsoft\Data\SqlClient\SqlConnectionString.NetCoreApp.cs" />
152155
<Compile Include="Microsoft\Data\SqlClient\SqlConnectionStringBuilder.NetCoreApp.cs" />
156+
<Compile Include="Microsoft\Data\SqlClient\SqlDiagnosticListener.NetCoreApp.cs" />
153157
<Compile Include="Microsoft\Data\SqlClient\PoolBlockingPeriod.cs" />
154158
<Compile Include="Microsoft\Data\SqlClient\SqlColumnEncryptionEnclaveProvider.NetCoreApp.cs" />
155159
<Compile Include="Microsoft\Data\SqlClient\SqlEnclaveAttestationParameters.NetCoreApp.cs" />
@@ -657,12 +661,12 @@
657661
</ItemGroup>
658662
<ItemGroup>
659663
<PackageReference Condition="'$(TargetsWindows)' == 'true' and '$(IsUAPAssembly)' != 'true'" Include="Microsoft.Win32.Registry" Version="$(MicrosoftWin32RegistryVersion)" />
660-
<PackageReference Include="System.Configuration.ConfigurationManager" Version="$(SystemConfigurationConfigurationManagerVersion)" />
664+
<PackageReference Condition="'$(TargetGroup)' == 'netcoreapp'" Include="System.Configuration.ConfigurationManager" Version="$(SystemConfigurationConfigurationManagerVersion)" />
661665
<PackageReference Include="System.Security.Permissions" Version="$(SystemSecurityPermissionsVersion)" />
662666
<PackageReference Include="System.Security.Principal.Windows" Version="$(SystemSecurityPrincipalWindowsVersion)" />
663667
<PackageReference Include="System.Text.Encoding.CodePages" Version="$(SystemTextEncodingCodePagesVersion)" />
664668
<PackageReference Include="runtime.native.System.Data.SqlClient.sni" Version="$(RuntimeNativeSystemDataSqlClientSNIVersion)" />
665-
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="$(SystemDiagnosticsDiagnosticSourceVersion)" />
669+
<PackageReference Condition="$(TargetGroup) == 'netcoreapp' " Include="System.Diagnostics.DiagnosticSource" Version="$(SystemDiagnosticsDiagnosticSourceVersion)" />
666670
<PackageReference Include="System.Threading.Tasks" Version="$(SystemThreadingTasksVersion)" />
667671
<PackageReference Include="System.Memory" Version="$(SystemMemoryVersion)" />
668672
<PackageReference Include="Microsoft.Identity.Client" Version="$(MicrosoftIdentityClientVersion)" />
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
using System.Collections.Concurrent;
7+
using System.Collections.Generic;
8+
using System.Configuration;
9+
10+
namespace Microsoft.Data.SqlClient
11+
{
12+
internal partial class SqlAuthenticationProviderManager
13+
{
14+
private readonly SqlAuthenticationInitializer _initializer;
15+
16+
static SqlAuthenticationProviderManager()
17+
{
18+
var activeDirectoryAuthNativeProvider = new ActiveDirectoryNativeAuthenticationProvider();
19+
SqlAuthenticationProviderConfigurationSection configurationSection;
20+
21+
try
22+
{
23+
configurationSection = (SqlAuthenticationProviderConfigurationSection)ConfigurationManager.GetSection(SqlAuthenticationProviderConfigurationSection.Name);
24+
}
25+
catch (ConfigurationErrorsException e)
26+
{
27+
throw SQL.CannotGetAuthProviderConfig(e);
28+
}
29+
30+
Instance = new SqlAuthenticationProviderManager(configurationSection);
31+
Instance.SetProvider(SqlAuthenticationMethod.ActiveDirectoryPassword, activeDirectoryAuthNativeProvider);
32+
}
33+
34+
/// <summary>
35+
/// Constructor.
36+
/// </summary>
37+
public SqlAuthenticationProviderManager(SqlAuthenticationProviderConfigurationSection configSection = null)
38+
{
39+
var methodName = "Ctor";
40+
_typeName = GetType().Name;
41+
_providers = new ConcurrentDictionary<SqlAuthenticationMethod, SqlAuthenticationProvider>();
42+
var authenticationsWithAppSpecifiedProvider = new HashSet<SqlAuthenticationMethod>();
43+
_authenticationsWithAppSpecifiedProvider = authenticationsWithAppSpecifiedProvider;
44+
45+
if (configSection == null)
46+
{
47+
_sqlAuthLogger.LogInfo(_typeName, methodName, "No SqlAuthProviders configuration section found.");
48+
return;
49+
}
50+
51+
// Create user-defined auth initializer, if any.
52+
if (!string.IsNullOrEmpty(configSection.InitializerType))
53+
{
54+
try
55+
{
56+
var initializerType = Type.GetType(configSection.InitializerType, true);
57+
_initializer = (SqlAuthenticationInitializer)Activator.CreateInstance(initializerType);
58+
_initializer.Initialize();
59+
}
60+
catch (Exception e)
61+
{
62+
throw SQL.CannotCreateSqlAuthInitializer(configSection.InitializerType, e);
63+
}
64+
_sqlAuthLogger.LogInfo(_typeName, methodName, "Created user-defined SqlAuthenticationInitializer.");
65+
}
66+
else
67+
{
68+
_sqlAuthLogger.LogInfo(_typeName, methodName, "No user-defined SqlAuthenticationInitializer found.");
69+
}
70+
71+
// add user-defined providers, if any.
72+
if (configSection.Providers != null && configSection.Providers.Count > 0)
73+
{
74+
foreach (ProviderSettings providerSettings in configSection.Providers)
75+
{
76+
SqlAuthenticationMethod authentication = AuthenticationEnumFromString(providerSettings.Name);
77+
SqlAuthenticationProvider provider;
78+
try
79+
{
80+
var providerType = Type.GetType(providerSettings.Type, true);
81+
provider = (SqlAuthenticationProvider)Activator.CreateInstance(providerType);
82+
}
83+
catch (Exception e)
84+
{
85+
throw SQL.CannotCreateAuthProvider(authentication.ToString(), providerSettings.Type, e);
86+
}
87+
if (!provider.IsSupported(authentication))
88+
{
89+
throw SQL.UnsupportedAuthenticationByProvider(authentication.ToString(), providerSettings.Type);
90+
}
91+
92+
_providers[authentication] = provider;
93+
authenticationsWithAppSpecifiedProvider.Add(authentication);
94+
_sqlAuthLogger.LogInfo(_typeName, methodName, string.Format("Added user-defined auth provider: {0} for authentication {1}.", providerSettings?.Type, authentication));
95+
}
96+
}
97+
else
98+
{
99+
_sqlAuthLogger.LogInfo(_typeName, methodName, "No user-defined auth providers.");
100+
}
101+
}
102+
103+
private static SqlAuthenticationMethod AuthenticationEnumFromString(string authentication)
104+
{
105+
switch (authentication.ToLowerInvariant())
106+
{
107+
case ActiveDirectoryPassword:
108+
return SqlAuthenticationMethod.ActiveDirectoryPassword;
109+
default:
110+
throw SQL.UnsupportedAuthentication(authentication);
111+
}
112+
}
113+
114+
/// <summary>
115+
/// The configuration section definition for reading app.config.
116+
/// </summary>
117+
internal class SqlAuthenticationProviderConfigurationSection : ConfigurationSection
118+
{
119+
public const string Name = "SqlAuthenticationProviders";
120+
121+
/// <summary>
122+
/// User-defined auth providers.
123+
/// </summary>
124+
[ConfigurationProperty("providers")]
125+
public ProviderSettingsCollection Providers => (ProviderSettingsCollection)base["providers"];
126+
127+
/// <summary>
128+
/// User-defined initializer.
129+
/// </summary>
130+
[ConfigurationProperty("initializerType")]
131+
public string InitializerType => base["initializerType"] as string;
132+
}
133+
}
134+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
namespace Microsoft.Data.SqlClient
6+
{
7+
internal partial class SqlAuthenticationProviderManager
8+
{
9+
static SqlAuthenticationProviderManager()
10+
{
11+
var activeDirectoryAuthNativeProvider = new ActiveDirectoryNativeAuthenticationProvider();
12+
Instance = new SqlAuthenticationProviderManager();
13+
Instance.SetProvider(SqlAuthenticationMethod.ActiveDirectoryPassword, activeDirectoryAuthNativeProvider);
14+
}
15+
}
16+
}

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlAuthenticationProviderManager.cs

Lines changed: 6 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -10,106 +10,31 @@
1010

1111
namespace Microsoft.Data.SqlClient
1212
{
13-
1413
/// <summary>
1514
/// Authentication provider manager.
1615
/// </summary>
17-
internal class SqlAuthenticationProviderManager
16+
internal partial class SqlAuthenticationProviderManager
1817
{
1918
private const string ActiveDirectoryPassword = "active directory password";
2019
private const string ActiveDirectoryIntegrated = "active directory integrated";
2120
private const string ActiveDirectoryInteractive = "active directory interactive";
2221

23-
static SqlAuthenticationProviderManager()
24-
{
25-
var activeDirectoryAuthNativeProvider = new ActiveDirectoryNativeAuthenticationProvider();
26-
SqlAuthenticationProviderConfigurationSection configurationSection;
27-
try
28-
{
29-
configurationSection = (SqlAuthenticationProviderConfigurationSection)ConfigurationManager.GetSection(SqlAuthenticationProviderConfigurationSection.Name);
30-
}
31-
catch (ConfigurationErrorsException e)
32-
{
33-
throw SQL.CannotGetAuthProviderConfig(e);
34-
}
35-
Instance = new SqlAuthenticationProviderManager(configurationSection);
36-
Instance.SetProvider(SqlAuthenticationMethod.ActiveDirectoryPassword, activeDirectoryAuthNativeProvider);
37-
}
38-
public static readonly SqlAuthenticationProviderManager Instance;
39-
4022
private readonly string _typeName;
41-
private readonly SqlAuthenticationInitializer _initializer;
4223
private readonly IReadOnlyCollection<SqlAuthenticationMethod> _authenticationsWithAppSpecifiedProvider;
4324
private readonly ConcurrentDictionary<SqlAuthenticationMethod, SqlAuthenticationProvider> _providers;
4425
private readonly SqlClientLogger _sqlAuthLogger = new SqlClientLogger();
4526

27+
public static readonly SqlAuthenticationProviderManager Instance;
28+
4629
/// <summary>
4730
/// Constructor.
4831
/// </summary>
49-
public SqlAuthenticationProviderManager(SqlAuthenticationProviderConfigurationSection configSection)
32+
public SqlAuthenticationProviderManager()
5033
{
5134
_typeName = GetType().Name;
52-
var methodName = "Ctor";
5335
_providers = new ConcurrentDictionary<SqlAuthenticationMethod, SqlAuthenticationProvider>();
54-
var authenticationsWithAppSpecifiedProvider = new HashSet<SqlAuthenticationMethod>();
55-
_authenticationsWithAppSpecifiedProvider = authenticationsWithAppSpecifiedProvider;
56-
57-
if (configSection == null)
58-
{
59-
_sqlAuthLogger.LogInfo(_typeName, methodName, "No SqlAuthProviders configuration section found.");
60-
return;
61-
}
62-
63-
// Create user-defined auth initializer, if any.
64-
//
65-
if (!string.IsNullOrEmpty(configSection.InitializerType))
66-
{
67-
try
68-
{
69-
var initializerType = Type.GetType(configSection.InitializerType, true);
70-
_initializer = (SqlAuthenticationInitializer)Activator.CreateInstance(initializerType);
71-
_initializer.Initialize();
72-
}
73-
catch (Exception e)
74-
{
75-
throw SQL.CannotCreateSqlAuthInitializer(configSection.InitializerType, e);
76-
}
77-
_sqlAuthLogger.LogInfo(_typeName, methodName, "Created user-defined SqlAuthenticationInitializer.");
78-
}
79-
else
80-
{
81-
_sqlAuthLogger.LogInfo(_typeName, methodName, "No user-defined SqlAuthenticationInitializer found.");
82-
}
83-
84-
// add user-defined providers, if any.
85-
//
86-
if (configSection.Providers != null && configSection.Providers.Count > 0)
87-
{
88-
foreach (ProviderSettings providerSettings in configSection.Providers)
89-
{
90-
SqlAuthenticationMethod authentication = AuthenticationEnumFromString(providerSettings.Name);
91-
SqlAuthenticationProvider provider;
92-
try
93-
{
94-
var providerType = Type.GetType(providerSettings.Type, true);
95-
provider = (SqlAuthenticationProvider)Activator.CreateInstance(providerType);
96-
}
97-
catch (Exception e)
98-
{
99-
throw SQL.CannotCreateAuthProvider(authentication.ToString(), providerSettings.Type, e);
100-
}
101-
if (!provider.IsSupported(authentication))
102-
throw SQL.UnsupportedAuthenticationByProvider(authentication.ToString(), providerSettings.Type);
103-
104-
_providers[authentication] = provider;
105-
authenticationsWithAppSpecifiedProvider.Add(authentication);
106-
_sqlAuthLogger.LogInfo(_typeName, methodName, string.Format("Added user-defined auth provider: {0} for authentication {1}.", providerSettings?.Type, authentication));
107-
}
108-
}
109-
else
110-
{
111-
_sqlAuthLogger.LogInfo(_typeName, methodName, "No user-defined auth providers.");
112-
}
36+
_authenticationsWithAppSpecifiedProvider = new HashSet<SqlAuthenticationMethod>();
37+
_sqlAuthLogger.LogInfo(_typeName, "Ctor", "No SqlAuthProviders configuration section found.");
11338
}
11439

11540
/// <summary>
@@ -156,17 +81,6 @@ public bool SetProvider(SqlAuthenticationMethod authenticationMethod, SqlAuthent
15681
return true;
15782
}
15883

159-
private static SqlAuthenticationMethod AuthenticationEnumFromString(string authentication)
160-
{
161-
switch (authentication.ToLowerInvariant())
162-
{
163-
case ActiveDirectoryPassword:
164-
return SqlAuthenticationMethod.ActiveDirectoryPassword;
165-
default:
166-
throw SQL.UnsupportedAuthentication(authentication);
167-
}
168-
}
169-
17084
private static string GetProviderType(SqlAuthenticationProvider provider)
17185
{
17286
if (provider == null)
@@ -175,26 +89,6 @@ private static string GetProviderType(SqlAuthenticationProvider provider)
17589
}
17690
}
17791

178-
/// <summary>
179-
/// The configuration section definition for reading app.config.
180-
/// </summary>
181-
internal class SqlAuthenticationProviderConfigurationSection : ConfigurationSection
182-
{
183-
public const string Name = "SqlAuthenticationProviders";
184-
185-
/// <summary>
186-
/// User-defined auth providers.
187-
/// </summary>
188-
[ConfigurationProperty("providers")]
189-
public ProviderSettingsCollection Providers => (ProviderSettingsCollection)base["providers"];
190-
191-
/// <summary>
192-
/// User-defined initializer.
193-
/// </summary>
194-
[ConfigurationProperty("initializerType")]
195-
public string InitializerType => base["initializerType"] as string;
196-
}
197-
19892
/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlAuthenticationInitializer.xml' path='docs/members[@name="SqlAuthenticationInitializer"]/SqlAuthenticationInitializer/*'/>
19993
public abstract class SqlAuthenticationInitializer
20094
{

0 commit comments

Comments
 (0)