Skip to content

Commit 0a2a1ab

Browse files
authored
CSHARP-5315: Mark API as obsolete: Auth (#1486)
1 parent ca12a03 commit 0a2a1ab

26 files changed

+62
-4
lines changed

src/MongoDB.Driver.Core/Core/Authentication/AuthenticationHelper.cs

+4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ namespace MongoDB.Driver.Core.Authentication
2929
{
3030
internal static class AuthenticationHelper
3131
{
32+
#pragma warning disable CS0618 // Type or member is obsolete
3233
public static void Authenticate(IConnection connection, ConnectionDescription description, IReadOnlyList<IAuthenticator> authenticators, CancellationToken cancellationToken)
34+
#pragma warning restore CS0618 // Type or member is obsolete
3335
{
3436
Ensure.IsNotNull(connection, nameof(connection));
3537
Ensure.IsNotNull(description, nameof(description));
@@ -45,7 +47,9 @@ public static void Authenticate(IConnection connection, ConnectionDescription de
4547
}
4648
}
4749

50+
#pragma warning disable CS0618 // Type or member is obsolete
4851
public static async Task AuthenticateAsync(IConnection connection, ConnectionDescription description, IReadOnlyList<IAuthenticator> authenticators, CancellationToken cancellationToken)
52+
#pragma warning restore CS0618 // Type or member is obsolete
4953
{
5054
Ensure.IsNotNull(connection, nameof(connection));
5155
Ensure.IsNotNull(description, nameof(description));

src/MongoDB.Driver.Core/Core/Authentication/AuthenticatorFactory.cs

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ namespace MongoDB.Driver.Core.Authentication
2121
/// <summary>
2222
/// Represents an authenticator factory.
2323
/// </summary>
24+
[Obsolete("This class will be made internal in a later release.")]
2425
public class AuthenticatorFactory : IAuthenticatorFactory
2526
{
2627
private readonly Func<IAuthenticator> _authenticatorFactoryFunc;

src/MongoDB.Driver.Core/Core/Authentication/DefaultAuthenticator.cs

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ namespace MongoDB.Driver.Core.Authentication
2929
/// Else, uses SCRAM-SHA-256 if present in the list of mechanisms. Otherwise, uses
3030
/// SCRAM-SHA-1 the default, regardless of whether SCRAM-SHA-1 is in the list.
3131
/// </summary>
32+
[Obsolete("This class will be made internal in a later release.")]
3233
public class DefaultAuthenticator : IAuthenticator
3334
{
3435
// fields

src/MongoDB.Driver.Core/Core/Authentication/GssapiAuthenticator.cs

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ namespace MongoDB.Driver.Core.Authentication
2828
/// <summary>
2929
/// A GSSAPI SASL authenticator.
3030
/// </summary>
31+
[Obsolete("This class will be made internal in a later release.")]
3132
public sealed class GssapiAuthenticator : SaslAuthenticator
3233
{
3334
// constants

src/MongoDB.Driver.Core/Core/Authentication/IAuthenticator.cs

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* limitations under the License.
1414
*/
1515

16+
using System;
1617
using System.Threading;
1718
using System.Threading.Tasks;
1819
using MongoDB.Bson;
@@ -23,6 +24,7 @@ namespace MongoDB.Driver.Core.Authentication
2324
/// <summary>
2425
/// Represents a connection authenticator.
2526
/// </summary>
27+
[Obsolete("This interface will be made internal in a later release.")]
2628
public interface IAuthenticator
2729
{
2830
/// <summary>

src/MongoDB.Driver.Core/Core/Authentication/IAuthenticatorFactory.cs

+3
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@
1313
* limitations under the License.
1414
*/
1515

16+
using System;
17+
1618
namespace MongoDB.Driver.Core.Authentication
1719
{
1820
/// <summary>
1921
/// Represents an authenticator factory.
2022
/// </summary>
23+
[Obsolete("This interface will be made internal in a later release.")]
2124
public interface IAuthenticatorFactory
2225
{
2326
/// <summary>

src/MongoDB.Driver.Core/Core/Authentication/MongoAWSAuthenticator.cs

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ namespace MongoDB.Driver.Core.Authentication
3030
/// <summary>
3131
/// The Mongo AWS authenticator.
3232
/// </summary>
33+
[Obsolete("This class will be made internal in a later release.")]
3334
public class MongoAWSAuthenticator : SaslAuthenticator
3435
{
3536
// constants

src/MongoDB.Driver.Core/Core/Authentication/MongoDBX509Authenticator.cs

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ namespace MongoDB.Driver.Core.Authentication
2727
/// <summary>
2828
/// A MongoDB-X509 authenticator.
2929
/// </summary>
30+
[Obsolete("This class will be made internal in a later release.")]
3031
public sealed class MongoDBX509Authenticator : IAuthenticator
3132
{
3233
// static properties

src/MongoDB.Driver.Core/Core/Authentication/NoTransitionClientLastSaslStep.cs

+4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ namespace MongoDB.Driver.Core.Authentication
2222
/// <summary>
2323
/// Represents a last SASL step.
2424
/// </summary>
25+
#pragma warning disable CS0618 // Type or member is obsolete
2526
internal sealed class NoTransitionClientLastSaslStep : SaslAuthenticator.ISaslStep
27+
#pragma warning restore CS0618 // Type or member is obsolete
2628
{
2729
private readonly byte[] _bytesToSendToServer;
2830

@@ -41,6 +43,7 @@ public NoTransitionClientLastSaslStep(byte[] bytesToSendToServer)
4143
public bool IsComplete => false;
4244

4345
/// <inheritdoc/>
46+
#pragma warning disable CS0618 // Type or member is obsolete
4447
public SaslAuthenticator.ISaslStep Transition(SaslAuthenticator.SaslConversation conversation, byte[] bytesReceivedFromServer)
4548
{
4649
if (bytesReceivedFromServer?.Length > 0)
@@ -54,5 +57,6 @@ public SaslAuthenticator.ISaslStep Transition(SaslAuthenticator.SaslConversation
5457

5558
public Task<SaslAuthenticator.ISaslStep> TransitionAsync(SaslAuthenticator.SaslConversation conversation, byte[] bytesReceivedFromServer, CancellationToken cancellationToken)
5659
=> Task.FromResult(Transition(conversation, bytesReceivedFromServer));
60+
#pragma warning restore CS0618 // Type or member is obsolete
5761
}
5862
}

src/MongoDB.Driver.Core/Core/Authentication/Oidc/MongoOidcAuthenticator.cs

+2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424

2525
namespace MongoDB.Driver.Core.Authentication.Oidc
2626
{
27+
#pragma warning disable CS0618 // Type or member is obsolete
2728
internal sealed class MongoOidcAuthenticator : SaslAuthenticator
29+
#pragma warning restore CS0618 // Type or member is obsolete
2830
{
2931
#region static
3032
public const string MechanismName = "MONGODB-OIDC";

src/MongoDB.Driver.Core/Core/Authentication/Oidc/OidcSaslMechanism.cs

+4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121

2222
namespace MongoDB.Driver.Core.Authentication.Oidc
2323
{
24+
#pragma warning disable CS0618 // Type or member is obsolete
2425
internal sealed class OidcSaslMechanism : SaslAuthenticator.ISaslMechanism
26+
#pragma warning restore CS0618 // Type or member is obsolete
2527
{
2628
private readonly IOidcCallbackAdapter _oidcCallback;
2729
private readonly string _principalName;
@@ -37,6 +39,7 @@ public OidcSaslMechanism(IOidcCallbackAdapter oidcCallback, string principalName
3739

3840
public bool HasCachedCredentials => _oidcCallback.CachedCredentials != null;
3941

42+
#pragma warning disable CS0618 // Type or member is obsolete
4043
public SaslAuthenticator.ISaslStep Initialize(
4144
IConnection connection,
4245
SaslAuthenticator.SaslConversation conversation,
@@ -80,5 +83,6 @@ private SaslAuthenticator.ISaslStep CreateNoTransitionClientLastSaslStep(OidcCre
8083
_usedCredentials = oidcCredentials;
8184
return new NoTransitionClientLastSaslStep(new BsonDocument("jwt", oidcCredentials.AccessToken).ToBson());
8285
}
86+
#pragma warning restore CS0618 // Type or member is obsolete
8387
}
8488
}

src/MongoDB.Driver.Core/Core/Authentication/PlainAuthenticator.cs

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ namespace MongoDB.Driver.Core.Authentication
2525
/// <summary>
2626
/// A PLAIN SASL authenticator.
2727
/// </summary>
28+
[Obsolete("This class will be made internal in a later release.")]
2829
public sealed class PlainAuthenticator : SaslAuthenticator
2930
{
3031
// static properties

src/MongoDB.Driver.Core/Core/Authentication/SaslAuthenticator.cs

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ namespace MongoDB.Driver.Core.Authentication
2828
/// <summary>
2929
/// Base class for a SASL authenticator.
3030
/// </summary>
31+
[Obsolete("This class will be made internal in a later release.")]
3132
public abstract class SaslAuthenticator : IAuthenticator
3233
{
3334
/// <summary>

src/MongoDB.Driver.Core/Core/Authentication/ScramSha1Authenticator.cs

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ namespace MongoDB.Driver.Core.Authentication
3131
/// <summary>
3232
/// A SCRAM-SHA1 SASL authenticator.
3333
/// </summary>
34+
[Obsolete("This class will be made internal in a later release.")]
3435
public sealed class ScramSha1Authenticator : ScramShaAuthenticator
3536
{
3637
// static properties

src/MongoDB.Driver.Core/Core/Authentication/ScramSha256Authenticator.cs

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ namespace MongoDB.Driver.Core.Authentication
3333
/// <summary>
3434
/// A SCRAM-SHA256 SASL authenticator.
3535
/// </summary>
36+
[Obsolete("This class will be made internal in a later release.")]
3637
public sealed class ScramSha256Authenticator : ScramShaAuthenticator
3738
{
3839
// static properties

src/MongoDB.Driver.Core/Core/Authentication/ScramShaAuthenticator.cs

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ namespace MongoDB.Driver.Core.Authentication
2828
/// <summary>
2929
/// A SCRAM-SHA SASL authenticator.
3030
/// </summary>
31+
[Obsolete("This class will be made internal in a later release.")]
3132
public abstract class ScramShaAuthenticator : SaslAuthenticator
3233
{
3334
/// <summary>

src/MongoDB.Driver.Core/Core/Authentication/UsernamePasswordCredential.cs

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ namespace MongoDB.Driver.Core.Authentication
2424
/// <summary>
2525
/// Represents a username/password credential.
2626
/// </summary>
27+
[Obsolete("This class will be made internal in a later release.")]
2728
public sealed class UsernamePasswordCredential
2829
{
2930
// fields

src/MongoDB.Driver.Core/Core/Configuration/ClusterBuilder.cs

+2
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,9 @@ private ServerFactory CreateServerFactory()
290290
private IServerMonitorFactory CreateServerMonitorFactory()
291291
{
292292
var serverMonitorConnectionSettings = _connectionSettings
293+
#pragma warning disable CS0618 // Type or member is obsolete
293294
.With(authenticatorFactories: new IAuthenticatorFactory[] { });
295+
#pragma warning restore CS0618 // Type or member is obsolete
294296

295297
var heartbeatConnectTimeout = _tcpStreamSettings.ConnectTimeout;
296298
if (heartbeatConnectTimeout == TimeSpan.Zero || heartbeatConnectTimeout == Timeout.InfiniteTimeSpan)

src/MongoDB.Driver.Core/Core/Configuration/ClusterBuilderExtensions.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,9 @@ public static ClusterBuilder ConfigureWithConnectionString(
160160
// Connection
161161
if (connectionString.Username != null)
162162
{
163+
#pragma warning disable CS0618 // Type or member is obsolete
163164
var authenticatorFactory = new AuthenticatorFactory(() => CreateAuthenticator(connectionString, serverApi));
165+
#pragma warning restore CS0618 // Type or member is obsolete
164166
builder = builder.ConfigureConnection(s => s.With(authenticatorFactories: new[] { authenticatorFactory }));
165167
}
166168
if (connectionString.ApplicationName != null)
@@ -262,6 +264,7 @@ SslPolicyErrors sslPolicyErrors
262264
return true;
263265
}
264266

267+
#pragma warning disable CS0618 // Type or member is obsolete
265268
private static string GetAuthSource(ConnectionString connectionString)
266269
{
267270
var defaultSource = GetDefaultAuthSource(connectionString);
@@ -301,11 +304,9 @@ private static IAuthenticator CreateAuthenticator(ConnectionString connectionStr
301304
{
302305
return new DefaultAuthenticator(credential, serverApi);
303306
}
304-
#pragma warning disable 618
305307
else if (connectionString.AuthMechanism == MongoDBCRAuthenticator.MechanismName)
306308
{
307309
return new MongoDBCRAuthenticator(credential, serverApi);
308-
#pragma warning restore 618
309310
}
310311
else if (connectionString.AuthMechanism == ScramSha1Authenticator.MechanismName)
311312
{
@@ -359,6 +360,7 @@ private static IAuthenticator CreateAuthenticator(ConnectionString connectionStr
359360

360361
throw new NotSupportedException("Unable to create an authenticator.");
361362
}
363+
#pragma warning restore CS0618 // Type or member is obsolete
362364

363365
#if NET472
364366
/// <summary>

src/MongoDB.Driver.Core/Core/Configuration/ConnectionSettings.cs

+10
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ public class ConnectionSettings
2828
{
2929
// fields
3030
private readonly string _applicationName;
31+
#pragma warning disable CS0618 // Type or member is obsolete
3132
private readonly IReadOnlyList<IAuthenticatorFactory> _authenticatorFactories;
33+
#pragma warning restore CS0618 // Type or member is obsolete
3234
private readonly IReadOnlyList<CompressorConfiguration> _compressors;
3335
private readonly LibraryInfo _libraryInfo;
3436
private readonly bool _loadBalanced;
@@ -47,15 +49,19 @@ public class ConnectionSettings
4749
/// <param name="maxLifeTime">The maximum life time.</param>
4850
/// <param name="applicationName">The application name.</param>
4951
public ConnectionSettings(
52+
#pragma warning disable CS0618 // Type or member is obsolete
5053
Optional<IEnumerable<IAuthenticatorFactory>> authenticatorFactories = default,
54+
#pragma warning restore CS0618 // Type or member is obsolete
5155
Optional<IEnumerable<CompressorConfiguration>> compressors = default(Optional<IEnumerable<CompressorConfiguration>>),
5256
Optional<LibraryInfo> libraryInfo = default,
5357
Optional<bool> loadBalanced = default,
5458
Optional<TimeSpan> maxIdleTime = default(Optional<TimeSpan>),
5559
Optional<TimeSpan> maxLifeTime = default(Optional<TimeSpan>),
5660
Optional<string> applicationName = default(Optional<string>))
5761
{
62+
#pragma warning disable CS0618 // Type or member is obsolete
5863
_authenticatorFactories = Ensure.IsNotNull(authenticatorFactories.WithDefault(Enumerable.Empty<IAuthenticatorFactory>()), nameof(authenticatorFactories)).ToList().AsReadOnly();
64+
#pragma warning restore CS0618 // Type or member is obsolete
5965
_compressors = Ensure.IsNotNull(compressors.WithDefault(Enumerable.Empty<CompressorConfiguration>()), nameof(compressors)).ToList();
6066
_libraryInfo = libraryInfo.WithDefault(null);
6167
_loadBalanced = loadBalanced.WithDefault(false);
@@ -82,7 +88,9 @@ public string ApplicationName
8288
/// <value>
8389
/// The authenticator factories.
8490
/// </value>
91+
#pragma warning disable CS0618 // Type or member is obsolete
8592
public IReadOnlyList<IAuthenticatorFactory> AuthenticatorFactories
93+
#pragma warning restore CS0618 // Type or member is obsolete
8694
{
8795
get { return _authenticatorFactories; }
8896
}
@@ -149,7 +157,9 @@ public TimeSpan MaxLifeTime
149157
/// <param name="applicationName">The application name.</param>
150158
/// <returns>A new ConnectionSettings instance.</returns>
151159
public ConnectionSettings With(
160+
#pragma warning disable CS0618 // Type or member is obsolete
152161
Optional<IEnumerable<IAuthenticatorFactory>> authenticatorFactories = default,
162+
#pragma warning restore CS0618 // Type or member is obsolete
153163
Optional<IEnumerable<CompressorConfiguration>> compressors = default(Optional<IEnumerable<CompressorConfiguration>>),
154164
Optional<LibraryInfo> libraryInfo = default,
155165
Optional<bool> loadBalanced = default,

src/MongoDB.Driver.Core/Core/Connections/ConnectionInitializer.cs

+4
Original file line numberDiff line numberDiff line change
@@ -165,15 +165,19 @@ private CommandWireProtocol<BsonDocument> CreateGetLastErrorProtocol(ServerApi s
165165
return getLastErrorProtocol;
166166
}
167167

168+
#pragma warning disable CS0618 // Type or member is obsolete
168169
private BsonDocument CreateInitialHelloCommand(IReadOnlyList<IAuthenticator> authenticators, bool loadBalanced = false, CancellationToken cancellationToken = default)
170+
#pragma warning restore CS0618 // Type or member is obsolete
169171
{
170172
var command = HelloHelper.CreateCommand(_serverApi, loadBalanced: loadBalanced);
171173
HelloHelper.AddClientDocumentToCommand(command, _clientDocument);
172174
HelloHelper.AddCompressorsToCommand(command, _compressors);
173175
return HelloHelper.CustomizeCommand(command, authenticators, cancellationToken);
174176
}
175177

178+
#pragma warning disable CS0618 // Type or member is obsolete
176179
private List<IAuthenticator> CreateAuthenticators(IConnection connection)
180+
#pragma warning restore CS0618 // Type or member is obsolete
177181
{
178182
if (connection.Description.IsInitialized())
179183
{

src/MongoDB.Driver.Core/Core/Connections/HelloHelper.cs

+2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ internal static BsonDocument CreateCommand(ServerApi serverApi, bool helloOk = f
6161
};
6262
}
6363

64+
#pragma warning disable CS0618 // Type or member is obsolete
6465
internal static BsonDocument CustomizeCommand(BsonDocument command, IReadOnlyList<IAuthenticator> authenticators, CancellationToken cancellationToken)
66+
#pragma warning restore CS0618 // Type or member is obsolete
6567
{
6668
return authenticators.Count == 1 ? authenticators[0].CustomizeInitialHelloCommand(command, cancellationToken) : command;
6769
}

src/MongoDB.Driver.Core/Core/Connections/IConnectionInitializer.cs

+4
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,17 @@ namespace MongoDB.Driver.Core.Connections
2323
{
2424
internal sealed class ConnectionInitializerContext
2525
{
26+
#pragma warning disable CS0618 // Type or member is obsolete
2627
public ConnectionInitializerContext(ConnectionDescription description, IReadOnlyList<IAuthenticator> authenticators)
28+
#pragma warning restore CS0618 // Type or member is obsolete
2729
{
2830
Description = Ensure.IsNotNull(description, nameof(description));
2931
Authenticators = Ensure.IsNotNull(authenticators, nameof(authenticators));
3032
}
3133

34+
#pragma warning disable CS0618 // Type or member is obsolete
3235
public IReadOnlyList<IAuthenticator> Authenticators { get; }
36+
#pragma warning restore CS0618 // Type or member is obsolete
3337
public ConnectionDescription Description { get; }
3438
}
3539

src/MongoDB.Driver.Core/Core/Operations/RetryabilityHelper.cs

+2
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,10 @@ static RetryabilityHelper()
9494

9595
__saslCommands = new HashSet<string>
9696
{
97+
#pragma warning disable CS0618 // Type or member is obsolete
9798
SaslAuthenticator.SaslStartCommand,
9899
SaslAuthenticator.SaslContinueCommand
100+
#pragma warning restore CS0618 // Type or member is obsolete
99101
};
100102
}
101103

src/MongoDB.Driver/ClusterRegistry.cs

+2
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ private ConnectionPoolSettings ConfigureConnectionPool(ConnectionPoolSettings se
119119
private ConnectionSettings ConfigureConnection(ConnectionSettings settings, ClusterKey clusterKey)
120120
{
121121
var endPoints = clusterKey.Servers.Select(s => new DnsEndPoint(s.Host, s.Port)).ToArray();
122+
#pragma warning disable CS0618 // Type or member is obsolete
122123
var authenticatorFactories = clusterKey.Credentials.Select(c => new AuthenticatorFactory(() => c.ToAuthenticator(endPoints, clusterKey.ServerApi)));
123124
return settings.With(
124125
authenticatorFactories: Optional.Enumerable<IAuthenticatorFactory>(authenticatorFactories),
@@ -128,6 +129,7 @@ private ConnectionSettings ConfigureConnection(ConnectionSettings settings, Clus
128129
maxIdleTime: clusterKey.MaxConnectionIdleTime,
129130
maxLifeTime: clusterKey.MaxConnectionLifeTime,
130131
applicationName: clusterKey.ApplicationName);
132+
#pragma warning restore CS0618 // Type or member is obsolete
131133
}
132134

133135
#pragma warning disable CS0618 // Type or member is obsolete

src/MongoDB.Driver/MongoCredential.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@ public MongoCredential WithMechanismProperty(string key, object value)
418418
}
419419

420420
// internal methods
421+
#pragma warning disable CS0618 // Type or member is obsolete
421422
internal IAuthenticator ToAuthenticator(IReadOnlyList<EndPoint> endPoints, ServerApi serverApi, IEnvironmentVariableProvider environmentVariableProvider = null)
422423
{
423424
var passwordEvidence = _evidence as PasswordEvidence;
@@ -433,11 +434,9 @@ internal IAuthenticator ToAuthenticator(IReadOnlyList<EndPoint> endPoints, Serve
433434
{
434435
return new DefaultAuthenticator(credential, serverApi);
435436
}
436-
#pragma warning disable 618
437437
if (_mechanism == MongoDBCRAuthenticator.MechanismName)
438438
{
439439
return new MongoDBCRAuthenticator(credential, serverApi);
440-
#pragma warning restore 618
441440
}
442441
if (_mechanism == ScramSha1Authenticator.MechanismName)
443442
{
@@ -515,6 +514,7 @@ internal IAuthenticator ToAuthenticator(IReadOnlyList<EndPoint> endPoints, Serve
515514

516515
throw new NotSupportedException("Unable to create an authenticator.");
517516
}
517+
#pragma warning restore CS0618 // Type or member is obsolete
518518

519519
// internal static methods
520520
internal static MongoCredential CreateRawOidcCredential(string userName)

0 commit comments

Comments
 (0)