Skip to content
Open
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 @@ -59,23 +59,23 @@ private ServerInfo(SqlConnectionOptions userOptions, string serverName)
/// </summary>
internal ServerInfo(
SqlConnectionOptions userOptions,
RoutingInfo routing,
TdsEnvChangeRoutingInfo routingInfo,
string preRoutingServerName,
string serverSpn)
{
Debug.Assert(userOptions != null && routing != null);
Debug.Assert(routing.ServerName != null, "server name should never be null");
Debug.Assert(userOptions != null && routingInfo != null);
Debug.Assert(routingInfo.ServerName != null, "server name should never be null");

// Ensure user server name is not null
// NOTE: string.Format should be used here to ensure invariant culture is used for port number.
UserServerName = routing == null || routing.ServerName == null
UserServerName = routingInfo == null || routingInfo.ServerName == null
? string.Empty
: string.Format(CultureInfo.InvariantCulture, "{0},{1}", routing.ServerName, routing.Port);
: string.Format(CultureInfo.InvariantCulture, "{0},{1}", routingInfo.ServerName, routingInfo.Port);

PreRoutingServerName = preRoutingServerName;
UserProtocol = TdsEnums.TCP;
SetDerivedNames(UserProtocol, UserServerName);
ResolvedDatabaseName = routing?.DatabaseName ?? userOptions.InitialCatalog;
ResolvedDatabaseName = routingInfo?.DatabaseName ?? userOptions.InitialCatalog;
ServerSPN = serverSpn;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ internal SqlConnectionPoolGroupProviderInfo PoolGroupProviderInfo

internal string RoutingDestination { get; private set; }

internal RoutingInfo RoutingInfo { get; private set; } = null;
internal TdsEnvChangeRoutingInfo RoutingInfo { get; private set; } = null;

internal int ServerProcessId
{
Expand Down Expand Up @@ -1841,8 +1841,8 @@ internal void OnFeatureExtAck(int featureId, byte[] data)
/// Generates (if appropriate) and sends a Federated Authentication Access token to the
/// server, using the Federated Authentication Info.
/// </summary>
/// <param name="fedAuthInfo">Federated Authentication Info.</param>
internal void OnFedAuthInfo(SqlFedAuthInfo fedAuthInfo)
/// <param name="fedAuthInfoToken">Federated Authentication Info.</param>
internal void OnFedAuthInfo(TdsFedAuthInfoToken fedAuthInfoToken)
{
// @TODO: Seriously, put this into a hash set or give it a helper or something! We're gonna forget one in *one* spot and cause a big ol bug someday.
Debug.Assert((ConnectionOptions._hasUserIdKeyword && ConnectionOptions._hasPasswordKeyword)
Expand All @@ -1856,7 +1856,7 @@ internal void OnFedAuthInfo(SqlFedAuthInfo fedAuthInfo)
|| ConnectionOptions.Authentication == SqlAuthenticationMethod.ActiveDirectoryWorkloadIdentity
|| (ConnectionOptions.Authentication == SqlAuthenticationMethod.ActiveDirectoryIntegrated && _fedAuthRequired),
"Credentials aren't provided for calling MSAL");
Debug.Assert(fedAuthInfo != null, "info should not be null.");
Debug.Assert(fedAuthInfoToken != null, "info should not be null.");
Debug.Assert(_dbConnectionPoolAuthenticationContextKey == null,
"_dbConnectionPoolAuthenticationContextKey should be null.");
SqlClientEventSource.Log.TryTraceEvent("<sc.SqlInternalConnectionTds.OnFedAuthInfo> {0}, Generating federated authentication token", ObjectID);
Expand All @@ -1877,8 +1877,8 @@ internal void OnFedAuthInfo(SqlFedAuthInfo fedAuthInfo)
// Construct the dbAuthenticationContextKey with information from FedAuthInfo and
// store for later use, when inserting in to the token cache.
_dbConnectionPoolAuthenticationContextKey = new DbConnectionPoolAuthenticationContextKey(
fedAuthInfo.StsUrl,
fedAuthInfo.Spn);
fedAuthInfoToken.StsUrl,
fedAuthInfoToken.Spn);

// Try to retrieve the authentication context from the pool, if one does exist for
// this key.
Expand Down Expand Up @@ -1921,7 +1921,7 @@ internal void OnFedAuthInfo(SqlFedAuthInfo fedAuthInfo)
else if (_forceExpiryLocked)
{
attemptRefreshTokenLocked = TryGetFedAuthTokenLocked(
fedAuthInfo,
fedAuthInfoToken,
dbConnectionPoolAuthenticationContext,
out _fedAuthToken);
}
Expand All @@ -1948,7 +1948,7 @@ internal void OnFedAuthInfo(SqlFedAuthInfo fedAuthInfo)
// context before trying to update. If the lock could not be obtained, it
// will return false, without attempting to fetch a new token.
attemptRefreshTokenLocked = TryGetFedAuthTokenLocked(
fedAuthInfo,
fedAuthInfoToken,
dbConnectionPoolAuthenticationContext,
out _fedAuthToken);

Expand Down Expand Up @@ -1986,7 +1986,7 @@ internal void OnFedAuthInfo(SqlFedAuthInfo fedAuthInfo)
if (dbConnectionPoolAuthenticationContext == null || attemptRefreshTokenUnLocked)
{
// Get the Federated Authentication Token.
_fedAuthToken = GetFedAuthToken(fedAuthInfo);
_fedAuthToken = GetFedAuthToken(fedAuthInfoToken);
Debug.Assert(_fedAuthToken != null, "_fedAuthToken should not be null.");

if (_dbConnectionPool != null)
Expand Down Expand Up @@ -3015,8 +3015,8 @@ private void FailoverPermissionDemand() =>
/// <summary>
/// Get the Federated Authentication Token.
/// </summary>
/// <param name="fedAuthInfo">Information obtained from server as Federated Authentication Info.</param>
private SqlFedAuthToken GetFedAuthToken(SqlFedAuthInfo fedAuthInfo)
/// <param name="fedAuthInfoToken">Information obtained from server as Federated Authentication Info.</param>
private SqlFedAuthToken GetFedAuthToken(TdsFedAuthInfoToken fedAuthInfoToken)
{
// Number of milliseconds to sleep for the initial back off, if a
// retry period is not specified by the provider.
Expand All @@ -3042,8 +3042,8 @@ private SqlFedAuthToken GetFedAuthToken(SqlFedAuthInfo fedAuthInfo)
{
var authParamsBuilder = new SqlAuthenticationParametersBuilder(
authenticationMethod: ConnectionOptions.Authentication,
resource: fedAuthInfo.Spn,
authority: fedAuthInfo.StsUrl,
resource: fedAuthInfoToken.Spn,
authority: fedAuthInfoToken.StsUrl,
serverName: ConnectionOptions.DataSource,
databaseName: ConnectionOptions.InitialCatalog)
.WithConnectionId(_clientConnectionId)
Expand Down Expand Up @@ -4469,20 +4469,20 @@ internal static bool ShouldDisableTnir(
/// Tries to acquire a lock on the authentication context. If successful in acquiring the
/// lock, gets a new token and assigns it in the out parameter. Else returns false.
/// </summary>
/// <param name="fedAuthInfo">Federated Authentication Info</param>
/// <param name="fedAuthInfoToken">Federated Authentication Info</param>
/// <param name="dbConnectionPoolAuthenticationContext">
/// Authentication Context cached in the connection pool.
/// </param>
/// <param name="fedAuthToken">
/// Out parameter, carrying the token if we acquired a lock and got the token.
/// </param>
private bool TryGetFedAuthTokenLocked(
SqlFedAuthInfo fedAuthInfo,
TdsFedAuthInfoToken fedAuthInfoToken,
DbConnectionPoolAuthenticationContext dbConnectionPoolAuthenticationContext,
out SqlFedAuthToken fedAuthToken)
{

Debug.Assert(fedAuthInfo != null, "fedAuthInfo should not be null.");
Debug.Assert(fedAuthInfoToken != null, "fedAuthInfo should not be null.");
Debug.Assert(dbConnectionPoolAuthenticationContext != null,
"dbConnectionPoolAuthenticationContext should not be null.");

Expand Down Expand Up @@ -4526,7 +4526,7 @@ private bool TryGetFedAuthTokenLocked(
if (authenticationContextLocked)
{
// Get the Federated Authentication Token.
fedAuthToken = GetFedAuthToken(fedAuthInfo);
fedAuthToken = GetFedAuthToken(fedAuthInfoToken);

Debug.Assert(fedAuthToken != null, "fedAuthToken should not be null.");
}
Expand Down
Loading
Loading