Skip to content

Commit 7c9b0f3

Browse files
committed
create separate SspiAuthenticationParameters
1 parent a0f5c7a commit 7c9b0f3

File tree

6 files changed

+36
-26
lines changed

6 files changed

+36
-26
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,9 @@
662662
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\SSPI\SSPIContextProvider.cs">
663663
<Link>Microsoft\Data\SqlClient\SSPI\SSPIContextProvider.cs</Link>
664664
</Compile>
665+
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\SSPI\SspiAuthenticationParameters.cs">
666+
<Link>Microsoft\Data\SqlClient\SSPI\SspiAuthenticationParameters.cs</Link>
667+
</Compile>
665668
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\Utilities\ObjectPool.cs">
666669
<Link>Microsoft\Data\SqlClient\Utilities\ObjectPool.cs</Link>
667670
</Compile>

src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,9 @@
363363
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\SSPI\SSPIContextProvider.cs">
364364
<Link>Microsoft\Data\SqlClient\SSPI\SSPIContextProvider.cs</Link>
365365
</Compile>
366+
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\SSPI\SspiAuthenticationParameters.cs">
367+
<Link>Microsoft\Data\SqlClient\SSPI\SspiAuthenticationParameters.cs</Link>
368+
</Compile>
366369
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\TdsParser.cs">
367370
<Link>Microsoft\Data\SqlClient\TdsParser.cs</Link>
368371
</Compile>

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SSPI/NativeSSPIContextProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ private void LoadSSPILibrary()
4949
}
5050
}
5151

52-
protected override bool GenerateSspiClientContext(ReadOnlySpan<byte> incomingBlob, IBufferWriter<byte> outgoingBlobWriter, SqlAuthenticationParameters authParams)
52+
protected override bool GenerateSspiClientContext(ReadOnlySpan<byte> incomingBlob, IBufferWriter<byte> outgoingBlobWriter, SspiAuthenticationParameters authParams)
5353
{
5454
#if NETFRAMEWORK
5555
SNIHandle handle = _physicalStateObj.Handle;

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SSPI/NegotiateSSPIContextProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ internal sealed class NegotiateSSPIContextProvider : SSPIContextProvider
1212
{
1313
private NegotiateAuthentication? _negotiateAuth = null;
1414

15-
protected override bool GenerateSspiClientContext(ReadOnlySpan<byte> incomingBlob, IBufferWriter<byte> outgoingBlobWriter, SqlAuthenticationParameters authParams)
15+
protected override bool GenerateSspiClientContext(ReadOnlySpan<byte> incomingBlob, IBufferWriter<byte> outgoingBlobWriter, SspiAuthenticationParameters authParams)
1616
{
1717
NegotiateAuthenticationStatusCode statusCode = NegotiateAuthenticationStatusCode.UnknownCredentials;
1818

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SSPI/SSPIContextProvider.cs

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.Buffers;
33
using System.Diagnostics;
4-
using Microsoft.Data.Common;
54

65
#nullable enable
76

@@ -26,7 +25,7 @@ private protected virtual void Initialize()
2625
{
2726
}
2827

29-
protected abstract bool GenerateSspiClientContext(ReadOnlySpan<byte> incomingBlob, IBufferWriter<byte> outgoingBlobWriter, SqlAuthenticationParameters authParams);
28+
protected abstract bool GenerateSspiClientContext(ReadOnlySpan<byte> incomingBlob, IBufferWriter<byte> outgoingBlobWriter, SspiAuthenticationParameters authParams);
3029

3130
internal void SSPIData(ReadOnlySpan<byte> receivedBuff, IBufferWriter<byte> outgoingBlobWriter, string serverSpn)
3231
{
@@ -57,7 +56,13 @@ internal void SSPIData(ReadOnlySpan<byte> receivedBuff, IBufferWriter<byte> outg
5756

5857
private bool RunGenerateSspiClientContext(ReadOnlySpan<byte> incomingBlob, IBufferWriter<byte> outgoingBlobWriter, string serverSpn)
5958
{
60-
var authParams = CreateSqlAuthParams(_parser.Connection, serverSpn);
59+
var options = _parser.Connection.ConnectionOptions;
60+
var authParams = new SspiAuthenticationParameters(serverSpn)
61+
{
62+
DatabaseName = options.InitialCatalog,
63+
UserId = options.UserID,
64+
Password = options.Password,
65+
};
6166

6267
try
6368
{
@@ -72,27 +77,6 @@ private bool RunGenerateSspiClientContext(ReadOnlySpan<byte> incomingBlob, IBuff
7277
}
7378
}
7479

75-
private static SqlAuthenticationParameters CreateSqlAuthParams(SqlInternalConnectionTds connection, string serverSpn)
76-
{
77-
var auth = new SqlAuthenticationParameters.Builder(
78-
connection: connection,
79-
resource: serverSpn,
80-
authority: null);
81-
82-
83-
if (connection.ConnectionOptions.UserID is { } userId)
84-
{
85-
auth.WithUserId(userId);
86-
}
87-
88-
if (connection.ConnectionOptions.Password is { } password)
89-
{
90-
auth.WithPassword(password);
91-
}
92-
93-
return auth;
94-
}
95-
9680
protected void SSPIError(string error, string procedure)
9781
{
9882
Debug.Assert(!string.IsNullOrEmpty(procedure), "TdsParser.SSPIError called with an empty or null procedure string");
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#nullable enable
2+
3+
namespace Microsoft.Data.SqlClient
4+
{
5+
internal sealed class SspiAuthenticationParameters
6+
{
7+
public SspiAuthenticationParameters(string serverName)
8+
{
9+
ServerName = serverName;
10+
}
11+
12+
public string ServerName { get; }
13+
14+
public string? UserId { get; set; }
15+
16+
public string? DatabaseName { get; set; }
17+
18+
public string? Password { get; set; }
19+
}
20+
}

0 commit comments

Comments
 (0)