Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ public enum SqlAuthenticationMethod
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlAuthenticationMethod.xml' path='docs/members[@name="SqlAuthenticationMethod"]/SqlPassword/*'/>
SqlPassword = 1,
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlAuthenticationMethod.xml' path='docs/members[@name="SqlAuthenticationMethod"]/ActiveDirectoryPassword/*'/>
[System.Obsolete("ActiveDirectoryPassword is deprecated, use a more secure authentication method. See https://aka.ms/SqlClientEntraIDAuthentication for more details.")]
ActiveDirectoryPassword = 2,
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlAuthenticationMethod.xml' path='docs/members[@name="SqlAuthenticationMethod"]/ActiveDirectoryIntegrated/*'/>
ActiveDirectoryIntegrated = 3,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1363,7 +1363,9 @@ private void Login(ServerInfo server, TimeoutTimer timeout, string newPassword,
// If the workflow being used is Active Directory Authentication and server's prelogin response
// for FEDAUTHREQUIRED option indicates Federated Authentication is required, we have to insert FedAuth Feature Extension
// in Login7, indicating the intent to use Active Directory Authentication for SQL Server.
#pragma warning disable 0618 // Type or member is obsolete
if (ConnectionOptions.Authentication == SqlAuthenticationMethod.ActiveDirectoryPassword
#pragma warning restore 0618 // Type or member is obsolete
|| ConnectionOptions.Authentication == SqlAuthenticationMethod.ActiveDirectoryInteractive
|| ConnectionOptions.Authentication == SqlAuthenticationMethod.ActiveDirectoryDeviceCodeFlow
|| ConnectionOptions.Authentication == SqlAuthenticationMethod.ActiveDirectoryServicePrincipal
Expand Down Expand Up @@ -2579,7 +2581,9 @@ internal SqlFedAuthToken GetFedAuthToken(SqlFedAuthInfo fedAuthInfo)
_activeDirectoryAuthTimeoutRetryHelper.CachedToken = _fedAuthToken;
}
break;
#pragma warning disable 0618 // Type or member is obsolete
case SqlAuthenticationMethod.ActiveDirectoryPassword:
#pragma warning restore 0618 // Type or member is obsolete
case SqlAuthenticationMethod.ActiveDirectoryServicePrincipal:
if (_activeDirectoryAuthTimeoutRetryHelper.State == ActiveDirectoryAuthenticationTimeoutRetryState.Retrying)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ public enum SqlAuthenticationMethod
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlAuthenticationMethod.xml' path='docs/members[@name="SqlAuthenticationMethod"]/SqlPassword/*'/>
SqlPassword = 1,
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlAuthenticationMethod.xml' path='docs/members[@name="SqlAuthenticationMethod"]/ActiveDirectoryPassword/*'/>
[System.ObsoleteAttribute("ActiveDirectoryPassword is deprecated, use a more secure authentication method. See https://aka.ms/SqlClientEntraIDAuthentication for more details.")]
ActiveDirectoryPassword = 2,
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlAuthenticationMethod.xml' path='docs/members[@name="SqlAuthenticationMethod"]/ActiveDirectoryIntegrated/*'/>
ActiveDirectoryIntegrated = 3,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1371,7 +1371,9 @@ private void Login(ServerInfo server, TimeoutTimer timeout, string newPassword,
// If the workflow being used is Active Directory Authentication and server's prelogin response
// for FEDAUTHREQUIRED option indicates Federated Authentication is required, we have to insert FedAuth Feature Extension
// in Login7, indicating the intent to use Active Directory Authentication for SQL Server.
#pragma warning disable 0618 // Type or member is obsolete
if (ConnectionOptions.Authentication == SqlAuthenticationMethod.ActiveDirectoryPassword
#pragma warning restore 0618 // Type or member is obsolete
|| ConnectionOptions.Authentication == SqlAuthenticationMethod.ActiveDirectoryInteractive
|| ConnectionOptions.Authentication == SqlAuthenticationMethod.ActiveDirectoryDeviceCodeFlow
|| ConnectionOptions.Authentication == SqlAuthenticationMethod.ActiveDirectoryServicePrincipal
Expand Down Expand Up @@ -1786,7 +1788,9 @@ private bool ShouldDisableTnir(SqlConnectionString connectionOptions)
Boolean isAzureEndPoint = ADP.IsAzureSqlServerEndpoint(connectionOptions.DataSource);

Boolean isFedAuthEnabled = this._accessTokenInBytes != null ||
#pragma warning disable 0618 // Type or member is obsolete
connectionOptions.Authentication == SqlAuthenticationMethod.ActiveDirectoryPassword ||
#pragma warning restore 0618 // Type or member is obsolete
connectionOptions.Authentication == SqlAuthenticationMethod.ActiveDirectoryIntegrated ||
connectionOptions.Authentication == SqlAuthenticationMethod.ActiveDirectoryInteractive ||
connectionOptions.Authentication == SqlAuthenticationMethod.ActiveDirectoryServicePrincipal ||
Expand Down Expand Up @@ -2622,7 +2626,9 @@ internal SqlFedAuthToken GetFedAuthToken(SqlFedAuthInfo fedAuthInfo)
_activeDirectoryAuthTimeoutRetryHelper.CachedToken = _fedAuthToken;
}
break;
#pragma warning disable 0618 // Type or member is obsolete
case SqlAuthenticationMethod.ActiveDirectoryPassword:
#pragma warning restore 0618 // Type or member is obsolete
case SqlAuthenticationMethod.ActiveDirectoryServicePrincipal:
if (_activeDirectoryAuthTimeoutRetryHelper.State == ActiveDirectoryAuthenticationTimeoutRetryState.Retrying)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ public static void ClearUserTokenCache()
public override bool IsSupported(SqlAuthenticationMethod authentication)
{
return authentication == SqlAuthenticationMethod.ActiveDirectoryIntegrated
#pragma warning disable 0618 // Type or member is obsolete
|| authentication == SqlAuthenticationMethod.ActiveDirectoryPassword
#pragma warning restore 0618 // Type or member is obsolete
|| authentication == SqlAuthenticationMethod.ActiveDirectoryInteractive
|| authentication == SqlAuthenticationMethod.ActiveDirectoryServicePrincipal
|| authentication == SqlAuthenticationMethod.ActiveDirectoryDeviceCodeFlow
Expand Down Expand Up @@ -245,7 +247,9 @@ public override async Task<SqlAuthenticationToken> AcquireTokenAsync(SqlAuthenti
SqlClientEventSource.Log.TryTraceEvent("AcquireTokenAsync | Acquired access token for Active Directory Integrated auth mode. Expiry Time: {0}", result?.ExpiresOn);
}
}
#pragma warning disable 0618 // Type or member is obsolete
else if (parameters.AuthenticationMethod == SqlAuthenticationMethod.ActiveDirectoryPassword)
#pragma warning restore 0618 // Type or member is obsolete
{
string pwCacheKey = GetAccountPwCacheKey(parameters);
object previousPw = s_accountPwCache.Get(pwCacheKey);
Expand Down Expand Up @@ -275,8 +279,7 @@ previousPw is byte[] previousPwBytes &&
{
entry.Value = GetHash(parameters.Password);
entry.AbsoluteExpirationRelativeToNow = TimeSpan.FromHours(s_accountPwCacheTtlInHours);
};

}
SqlClientEventSource.Log.TryTraceEvent("AcquireTokenAsync | Acquired access token for Active Directory Password auth mode. Expiry Time: {0}", result?.ExpiresOn);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace Microsoft.Data.SqlClient
/// </summary>
internal sealed class SqlAuthenticationProviderManager
{
[Obsolete("ActiveDirectoryPassword is deprecated, use a more secure authentication method. See https://aka.ms/SqlClientEntraIDAuthentication for more details.")]
private const string ActiveDirectoryPassword = "active directory password";
private const string ActiveDirectoryIntegrated = "active directory integrated";
private const string ActiveDirectoryInteractive = "active directory interactive";
Expand Down Expand Up @@ -58,7 +59,9 @@ private static void SetDefaultAuthProviders(SqlAuthenticationProviderManager ins
{
var activeDirectoryAuthProvider = new ActiveDirectoryAuthenticationProvider(instance._applicationClientId);
instance.SetProvider(SqlAuthenticationMethod.ActiveDirectoryIntegrated, activeDirectoryAuthProvider);
#pragma warning disable 0618 // Type or member is obsolete
instance.SetProvider(SqlAuthenticationMethod.ActiveDirectoryPassword, activeDirectoryAuthProvider);
#pragma warning restore 0618 // Type or member is obsolete
instance.SetProvider(SqlAuthenticationMethod.ActiveDirectoryInteractive, activeDirectoryAuthProvider);
instance.SetProvider(SqlAuthenticationMethod.ActiveDirectoryServicePrincipal, activeDirectoryAuthProvider);
instance.SetProvider(SqlAuthenticationMethod.ActiveDirectoryDeviceCodeFlow, activeDirectoryAuthProvider);
Expand Down Expand Up @@ -239,8 +242,10 @@ private static SqlAuthenticationMethod AuthenticationEnumFromString(string authe
{
case ActiveDirectoryIntegrated:
return SqlAuthenticationMethod.ActiveDirectoryIntegrated;
#pragma warning disable 0618 // Type or member is obsolete
case ActiveDirectoryPassword:
return SqlAuthenticationMethod.ActiveDirectoryPassword;
#pragma warning restore 0618 // Type or member is obsolete
case ActiveDirectoryInteractive:
return SqlAuthenticationMethod.ActiveDirectoryInteractive;
case ActiveDirectoryServicePrincipal:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2150,7 +2150,9 @@ private bool TryOpen(TaskCompletionSource<DbConnectionInternal> retry, SqlConnec

if (connectionOptions != null &&
(connectionOptions.Authentication == SqlAuthenticationMethod.SqlPassword ||
#pragma warning disable 0618 // Use of obsolete member 'SqlAuthenticationMethod.ActiveDirectoryPassword'
connectionOptions.Authentication == SqlAuthenticationMethod.ActiveDirectoryPassword ||
#pragma warning restore 0618 // Use of obsolete member 'SqlAuthenticationMethod.ActiveDirectoryPassword'
connectionOptions.Authentication == SqlAuthenticationMethod.ActiveDirectoryServicePrincipal) &&
(!connectionOptions._hasUserIdKeyword || !connectionOptions._hasPasswordKeyword) &&
_credential == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1144,6 +1144,7 @@ public enum SqlAuthenticationMethod
SqlPassword,

/// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlAuthenticationMethod.xml' path='docs/members[@name="SqlAuthenticationMethod"]/ActiveDirectoryPassword/*'/>
[Obsolete("ActiveDirectoryPassword is deprecated, use a more secure authentication method. See https://aka.ms/SqlClientEntraIDAuthentication for more details.")]
ActiveDirectoryPassword,

/// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlAuthenticationMethod.xml' path='docs/members[@name="SqlAuthenticationMethod"]/ActiveDirectoryIntegrated/*'/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8731,7 +8731,9 @@ internal int WriteFedAuthFeatureRequest(FederatedAuthenticationFeatureExtensionD
byte workflow = 0x00;
switch (fedAuthFeatureData.authentication)
{
#pragma warning disable 0618 // Type or member is obsolete
case SqlAuthenticationMethod.ActiveDirectoryPassword:
#pragma warning restore 0618 // Type or member is obsolete
workflow = TdsEnums.MSALWORKFLOW_ACTIVEDIRECTORYPASSWORD;
break;
case SqlAuthenticationMethod.ActiveDirectoryIntegrated:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ public class SqlAuthenticationProviderTest
{
[Theory]
[InlineData(SqlAuthenticationMethod.ActiveDirectoryIntegrated)]
#pragma warning disable 0618 // Type or member is obsolete
[InlineData(SqlAuthenticationMethod.ActiveDirectoryPassword)]
#pragma warning restore 0618 // Type or member is obsolete
[InlineData(SqlAuthenticationMethod.ActiveDirectoryServicePrincipal)]
[InlineData(SqlAuthenticationMethod.ActiveDirectoryDeviceCodeFlow)]
[InlineData(SqlAuthenticationMethod.ActiveDirectoryManagedIdentity)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ public override async Task<SqlAuthenticationToken> AcquireTokenAsync(SqlAuthenti

public override bool IsSupported(SqlAuthenticationMethod authenticationMethod)
{
#pragma warning disable 0618 // Type or member is obsolete
return authenticationMethod.Equals(SqlAuthenticationMethod.ActiveDirectoryPassword);
#pragma warning restore 0618 // Type or member is obsolete
}
}

Expand Down Expand Up @@ -260,7 +262,9 @@ public static void TestADPasswordAuthentication()
[ConditionalFact(nameof(IsAADConnStringsSetup))]
public static void TestCustomProviderAuthentication()
{
#pragma warning disable 0618 // Type or member is obsolete
SqlAuthenticationProvider.SetProvider(SqlAuthenticationMethod.ActiveDirectoryPassword, new CustomSqlAuthenticationProvider(DataTestUtility.ApplicationClientId));
#pragma warning restore 0618 // Type or member is obsolete
// Connect to Azure DB with password and retrieve user name using custom authentication provider
using (SqlConnection conn = new SqlConnection(DataTestUtility.AADPasswordConnectionString))
{
Expand All @@ -278,7 +282,9 @@ public static void TestCustomProviderAuthentication()
}
}
// Reset to driver internal provider.
#pragma warning disable 0618 // Type or member is obsolete
SqlAuthenticationProvider.SetProvider(SqlAuthenticationMethod.ActiveDirectoryPassword, new ActiveDirectoryAuthenticationProvider(DataTestUtility.ApplicationClientId));
#pragma warning restore 0618 // Type or member is obsolete
}

[ConditionalFact(nameof(IsAADConnStringsSetup))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ private SqlConnectionStringBuilder CreateBaseConnectionStringBuilder(
}
else if (_source.EntraIdUser.Length != 0)
{
#pragma warning disable 0618 // Type or member is obsolete
builder.Authentication = SqlAuthenticationMethod.ActiveDirectoryPassword;
#pragma warning restore 0618 // Type or member is obsolete
builder.UserID = _source.EntraIdUser;
builder.Password = _source.EntraIdPassword;
}
Expand Down
Loading