Skip to content

Commit 7723b20

Browse files
saurabh500Saurabh Singh
andauthored
Login handler for login (#2730)
* adding the Tds Stream APIs * Fix the NS * Fix the enums * adding the change underlying stream * Address CR comments * Initial Prelogin * Adding prelogin handler * Prelogin handler * Adding the ssl work in progress * Prelogin WIP * Prelogin WIP * Adding the prelogin handler changes for encryption * Fix object Id * Clean up the handler * adding the prelogin handler sub handlers * Adding the sub handlers for prelogin : * Simplify * Extract constants * Adding the prelogin handler comment * adding the GUID for the transport * Adding the Login handler * Adding the server info * adding the login handler details * Adding prelogin initial * Checkout unintended * Refactor the handlers and move some methods to context. * Usage of Binary Primitives * adding the prelogin bug fixes * adding the refactored changes * Improve Exception handling * Fix the handler class name casing * Add comments about SNI error and simplify code * Throw the errors * add comments * Adding tests * Preallocate prelogin write buffer * Fix bad commit * adding the comments on the context object * Commit for Exceptions handling * adding the simplification of wirte * Using only the offset * Move to binary primitives * Fix the tests * Adding the tests for Tds Prelogin handler * Address CR comments * address CR comments * Handler Changes for login * adding the csproj changes * Address CR comments * Remove not needed TODO * Move write to BinaryPrimitives * Move the password change request * adding the login handler changes * adding the feature extension * adding the login handler port * adding the chain * More changes * adding the changes * adding the login changes * Finish the writing * Clean up * Adding the login complete * adding the complete login flow * Adding the code * Adding the right compilation * Adding the Login handler * adding the compilation fix * Fixing The NRE * Fixing the Password * Fix bugs * Fix the bugs and added tests * Remove unused code. Refactor * Refactor the login context * Adding the additional refactor * Refactor the code for login * Remove creds * Round 1 of CR comments * Adding the CR changes part 2 * Adding tests and more refactoring * Adding unit tests --------- Co-authored-by: Saurabh Singh <singhsaura@microsoft.com>
1 parent 09b8b16 commit 7723b20

13 files changed

Lines changed: 1554 additions & 20 deletions

File tree

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -929,6 +929,10 @@
929929
<Compile Include="Microsoft\Data\SqlClientX\Handlers\Connection\ConnectionHandlerContext.cs" />
930930
<Compile Include="Microsoft\Data\SqlClientX\Handlers\Connection\DataSourceParsingHandler.cs" />
931931
<Compile Include="Microsoft\Data\SqlClientX\Handlers\Connection\PreloginHandler.cs" />
932+
<Compile Include="Microsoft\Data\SqlClientX\Handlers\Connection\LoginHandler.cs" />
933+
<Compile Include="Microsoft\Data\SqlClientX\Handlers\Connection\Login\LoginHandlerContext.cs" />
934+
<Compile Include="Microsoft\Data\SqlClientX\Handlers\PasswordChangeRequest.cs" />
935+
<Compile Include="Microsoft\Data\SqlClientX\Handlers\Connection\Login\FeatureExtensions.cs" />
932936
<Compile Include="Microsoft\Data\SqlClientX\Handlers\Connection\PreloginSubHandlers\PreloginHandlerContext.cs" />
933937
<Compile Include="Microsoft\Data\SqlClientX\Handlers\Connection\PreloginSubHandlers\PreloginPacketHandler.cs" />
934938
<Compile Include="Microsoft\Data\SqlClientX\Handlers\Connection\PreloginSubHandlers\Tds8TlsHandler.cs" />

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClientX/Handlers/Connection/ConnectionHandlerContext.cs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
using System.Net.Security;
99
using System.Threading;
1010
using System.Threading.Tasks;
11+
using Microsoft.Data.ProviderBase;
1112
using Microsoft.Data.SqlClient;
1213
using Microsoft.Data.SqlClient.SNI;
14+
using Microsoft.Data.SqlClientX.Handlers.Connection.Login;
1315
using Microsoft.Data.SqlClientX.IO;
1416

1517
namespace Microsoft.Data.SqlClientX.Handlers.Connection
@@ -18,13 +20,18 @@ namespace Microsoft.Data.SqlClientX.Handlers.Connection
1820
/// </summary>
1921
internal class ConnectionHandlerContext : HandlerRequest, ICloneable
2022
{
21-
2223
// TODO: Decide if we need a default constructor depending on the latest design
2324
/// <summary>
2425
/// Stream used by readers.
2526
/// </summary>
2627
public Stream ConnectionStream { get; set; }
2728

29+
/// <summary>
30+
/// A timer representing the timeout for the connection.
31+
/// TODO: This might require rethinking.
32+
/// </summary>
33+
internal TimeoutTimer TimeoutTimer { get; set; }
34+
2835
/// <summary>
2936
/// Class that contains data required to handle a connection request.
3037
/// </summary>
@@ -64,7 +71,7 @@ internal class ConnectionHandlerContext : HandlerRequest, ICloneable
6471
/// <summary>
6572
/// Indicates if fed auth needed for this connection.
6673
/// </summary>
67-
public bool IsFedAuthRequired { get; internal set; }
74+
public bool IsFedAuthNegotiatedInPrelogin { get; internal set; }
6875

6976
/// <summary>
7077
/// The access token in bytes.
@@ -96,6 +103,18 @@ internal class ConnectionHandlerContext : HandlerRequest, ICloneable
96103
/// </summary>
97104
internal Func<SqlAuthenticationParameters, CancellationToken, Task<SqlAuthenticationToken>> AccessTokenCallback { get; set; }
98105

106+
/// <summary>
107+
/// Represents a password change request on this connection.
108+
/// </summary>
109+
public PasswordChangeRequest PasswordChangeRequest { get; internal set; }
110+
111+
/// <summary>
112+
/// Features in the login request.
113+
/// This needn't be cloned, since after routing, the feature extensions need to be
114+
/// re-requested like it was for a fresh connection.
115+
/// </summary>
116+
public FeatureExtensions Features { get; } = new();
117+
99118
/// <summary>
100119
/// Clone <see cref="ConnectionHandlerContext"/> as part of history along the chain.
101120
/// </summary>
@@ -112,11 +131,12 @@ public object Clone()
112131
SslOverTdsStream = this.SslOverTdsStream,
113132
TdsStream = this.TdsStream,
114133
IsMarsCapable = this.IsMarsCapable,
115-
IsFedAuthRequired = this.IsFedAuthRequired,
134+
IsFedAuthNegotiatedInPrelogin = this.IsFedAuthNegotiatedInPrelogin,
116135
AccessTokenInBytes = this.AccessTokenInBytes,
117136
ServerInfo = this.ServerInfo,
118137
ErrorCollection = this.ErrorCollection,
119-
AccessTokenCallback = this.AccessTokenCallback // Assuming delegate cloning is not required
138+
AccessTokenCallback = this.AccessTokenCallback, // Assuming delegate cloning is not required
139+
PasswordChangeRequest = this.PasswordChangeRequest,
120140
};
121141
}
122142

0 commit comments

Comments
 (0)