Skip to content

Commit 8931357

Browse files
author
rstam
committed
CSHARP-603: Make MongoCredentialStore helper class internal and standarize on Credential (no "s") for singular and Credentials for plural.
1 parent 401a45f commit 8931357

27 files changed

+403
-551
lines changed

MongoDB.Driver/Communication/MongoConnection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ internal void Open()
224224
_stream = stream;
225225
_state = MongoConnectionState.Open;
226226

227-
new Authenticator(this, _serverInstance.Settings.CredentialsStore)
227+
new Authenticator(this, _serverInstance.Settings.Credentials)
228228
.Authenticate();
229229
}
230230

MongoDB.Driver/Communication/Security/Authenticator.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ internal class Authenticator
3838

3939
// private fields
4040
private readonly MongoConnection _connection;
41-
private readonly IEnumerable<MongoCredentials> _credentials;
41+
private readonly IEnumerable<MongoCredential> _credentials;
4242

4343
// constructors
4444
/// <summary>
4545
/// Initializes a new instance of the <see cref="Authenticator" /> class.
4646
/// </summary>
4747
/// <param name="connection">The connection.</param>
4848
/// <param name="credentials">The credentials.</param>
49-
public Authenticator(MongoConnection connection, IEnumerable<MongoCredentials> credentials)
49+
public Authenticator(MongoConnection connection, IEnumerable<MongoCredential> credentials)
5050
{
5151
_connection = connection;
5252
_credentials = credentials;
@@ -71,18 +71,18 @@ public void Authenticate()
7171
}
7272

7373
// private methods
74-
private void Authenticate(MongoCredentials credentials, List<string> serverSupportedMethods)
74+
private void Authenticate(MongoCredential credential, List<string> serverSupportedMethods)
7575
{
7676
foreach (var clientSupportedMethod in __clientSupportedMethods)
7777
{
78-
if (serverSupportedMethods.Contains(clientSupportedMethod.Name) && clientSupportedMethod.CanUse(credentials))
78+
if (serverSupportedMethods.Contains(clientSupportedMethod.Name) && clientSupportedMethod.CanUse(credential))
7979
{
80-
clientSupportedMethod.Authenticate(_connection, credentials);
80+
clientSupportedMethod.Authenticate(_connection, credential);
8181
return;
8282
}
8383
}
8484

85-
var message = string.Format("Unable to negotiate a protocol to authenticate. Credentials for source {0}, username {1} over protocol {2} could not be authenticated", credentials.Source, credentials.Username, credentials.AuthenticationProtocol);
85+
var message = string.Format("Unable to negotiate a protocol to authenticate. Credential for source {0}, username {1} over protocol {2} could not be authenticated", credential.Source, credential.Username, credential.AuthenticationProtocol);
8686
throw new MongoSecurityException(message);
8787
}
8888

MongoDB.Driver/Communication/Security/IAuthenticationMethod.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,19 @@ internal interface IAuthenticationMethod
3232
string Name { get; }
3333

3434
/// <summary>
35-
/// Authenticates the specified connection with the given credentials.
35+
/// Authenticates the specified connection with the given credential.
3636
/// </summary>
3737
/// <param name="connection">The connection.</param>
38-
/// <param name="credentials">The credentials.</param>
39-
void Authenticate(MongoConnection connection, MongoCredentials credentials);
38+
/// <param name="credential">The credential.</param>
39+
void Authenticate(MongoConnection connection, MongoCredential credential);
4040

4141
/// <summary>
42-
/// Determines whether this instance can use the specified credentials.
42+
/// Determines whether this instance can use the specified credential.
4343
/// </summary>
44-
/// <param name="credentials">The credentials.</param>
44+
/// <param name="credential">The credential.</param>
4545
/// <returns>
46-
/// <c>true</c> if this instance can use the specified credentials; otherwise, <c>false</c>.
46+
/// <c>true</c> if this instance can use the specified credential; otherwise, <c>false</c>.
4747
/// </returns>
48-
bool CanUse(MongoCredentials credentials);
48+
bool CanUse(MongoCredential credential);
4949
}
5050
}

MongoDB.Driver/Communication/Security/ISaslMechanism.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,20 @@ internal interface ISaslMechanism
3232
string Name { get; }
3333

3434
/// <summary>
35-
/// Determines whether this instance can authenticate with the specified credentials.
35+
/// Determines whether this instance can authenticate with the specified credential.
3636
/// </summary>
37-
/// <param name="credentials">The credentials.</param>
37+
/// <param name="credential">The credential.</param>
3838
/// <returns>
39-
/// <c>true</c> if this instance can authenticate with the specified credentials; otherwise, <c>false</c>.
39+
/// <c>true</c> if this instance can authenticate with the specified credential; otherwise, <c>false</c>.
4040
/// </returns>
41-
bool CanUse(MongoCredentials credentials);
41+
bool CanUse(MongoCredential credential);
4242

4343
/// <summary>
4444
/// Initializes the mechanism.
4545
/// </summary>
4646
/// <param name="connection">The connection.</param>
47-
/// <param name="credentials">The credentials.</param>
47+
/// <param name="credential">The credential.</param>
4848
/// <returns>The initial step.</returns>
49-
ISaslStep Initialize(MongoConnection connection, MongoCredentials credentials);
49+
ISaslStep Initialize(MongoConnection connection, MongoCredential credential);
5050
}
5151
}

MongoDB.Driver/Communication/Security/Mechanisms/CramMD5Mechanism.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,28 +38,28 @@ public string Name
3838

3939
// public methods
4040
/// <summary>
41-
/// Determines whether this instance can authenticate with the specified credentials.
41+
/// Determines whether this instance can authenticate with the specified credential.
4242
/// </summary>
43-
/// <param name="credentials">The credentials.</param>
43+
/// <param name="credential">The credential.</param>
4444
/// <returns>
45-
/// <c>true</c> if this instance can authenticate with the specified credentials; otherwise, <c>false</c>.
45+
/// <c>true</c> if this instance can authenticate with the specified credential; otherwise, <c>false</c>.
4646
/// </returns>
4747
/// <exception cref="System.NotImplementedException"></exception>
48-
public bool CanUse(MongoCredentials credentials)
48+
public bool CanUse(MongoCredential credential)
4949
{
50-
return credentials.AuthenticationProtocol == MongoAuthenticationProtocol.Strongest &&
51-
credentials.Evidence is PasswordEvidence;
50+
return credential.AuthenticationProtocol == MongoAuthenticationProtocol.Strongest &&
51+
credential.Evidence is PasswordEvidence;
5252
}
5353

5454
/// <summary>
5555
/// Initializes the mechanism.
5656
/// </summary>
5757
/// <param name="connection">The connection.</param>
58-
/// <param name="credentials">The credentials.</param>
58+
/// <param name="credential">The credential.</param>
5959
/// <returns>The initial step.</returns>
60-
public ISaslStep Initialize(MongoConnection connection, MongoCredentials credentials)
60+
public ISaslStep Initialize(MongoConnection connection, MongoCredential credential)
6161
{
62-
return new ManagedCramMD5Implementation(credentials.Username, ((PasswordEvidence)credentials.Evidence).Password);
62+
return new ManagedCramMD5Implementation(credential.Username, ((PasswordEvidence)credential.Evidence).Password);
6363
//return new GsaslCramMD5Implementation(identity);
6464
}
6565
}

MongoDB.Driver/Communication/Security/Mechanisms/DigestMD5Mechanism.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,31 +38,31 @@ public string Name
3838

3939
// public methods
4040
/// <summary>
41-
/// Determines whether this instance can authenticate with the specified credentials.
41+
/// Determines whether this instance can authenticate with the specified credential.
4242
/// </summary>
43-
/// <param name="credentials">The credentials.</param>
43+
/// <param name="credential">The credential.</param>
4444
/// <returns>
45-
/// <c>true</c> if this instance can authenticate with the specified credentials; otherwise, <c>false</c>.
45+
/// <c>true</c> if this instance can authenticate with the specified credential; otherwise, <c>false</c>.
4646
/// </returns>
4747
/// <exception cref="System.NotImplementedException"></exception>
48-
public bool CanUse(MongoCredentials credentials)
48+
public bool CanUse(MongoCredential credential)
4949
{
50-
return credentials.AuthenticationProtocol == MongoAuthenticationProtocol.Strongest &&
51-
credentials.Evidence is PasswordEvidence;
50+
return credential.AuthenticationProtocol == MongoAuthenticationProtocol.Strongest &&
51+
credential.Evidence is PasswordEvidence;
5252
}
5353

5454
/// <summary>
5555
/// Initializes the mechanism.
5656
/// </summary>
5757
/// <param name="connection">The connection.</param>
58-
/// <param name="credentials">The credentials.</param>
58+
/// <param name="credential">The credential.</param>
5959
/// <returns>The initial step.</returns>
60-
public ISaslStep Initialize(Internal.MongoConnection connection, MongoCredentials credentials)
60+
public ISaslStep Initialize(Internal.MongoConnection connection, MongoCredential credential)
6161
{
6262
return new ManagedDigestMD5Implementation(
6363
connection.ServerInstance.Address.Host,
64-
credentials.Username,
65-
((PasswordEvidence)credentials.Evidence).Password);
64+
credential.Username,
65+
((PasswordEvidence)credential.Evidence).Password);
6666
}
6767
}
6868
}

MongoDB.Driver/Communication/Security/Mechanisms/GssapiMechanism.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,26 +37,26 @@ public string Name
3737

3838
// public methods
3939
/// <summary>
40-
/// Determines whether this instance can authenticate with the specified credentials.
40+
/// Determines whether this instance can authenticate with the specified credential.
4141
/// </summary>
42-
/// <param name="credentials">The credentials.</param>
42+
/// <param name="credential">The credential.</param>
4343
/// <returns>
44-
/// <c>true</c> if this instance can authenticate with the specified credentials; otherwise, <c>false</c>.
44+
/// <c>true</c> if this instance can authenticate with the specified credential; otherwise, <c>false</c>.
4545
/// </returns>
4646
/// <exception cref="System.NotImplementedException"></exception>
47-
public bool CanUse(MongoCredentials credentials)
47+
public bool CanUse(MongoCredential credential)
4848
{
49-
return credentials.AuthenticationProtocol == MongoAuthenticationProtocol.Gssapi &&
50-
credentials.Identity is MongoExternalIdentity;
49+
return credential.AuthenticationProtocol == MongoAuthenticationProtocol.Gssapi &&
50+
credential.Identity is MongoExternalIdentity;
5151
}
5252

5353
/// <summary>
5454
/// Initializes the mechanism.
5555
/// </summary>
5656
/// <param name="connection">The connection.</param>
57-
/// <param name="credentials">The credentials.</param>
57+
/// <param name="credential">The credential.</param>
5858
/// <returns>The initial step.</returns>
59-
public ISaslStep Initialize(MongoConnection connection, MongoCredentials credentials)
59+
public ISaslStep Initialize(MongoConnection connection, MongoCredential credential)
6060
{
6161
// TODO: provide an override to force the use of gsasl?
6262
bool useGsasl = !Environment.OSVersion.Platform.ToString().Contains("Win");
@@ -65,14 +65,14 @@ public ISaslStep Initialize(MongoConnection connection, MongoCredentials credent
6565
throw new NotImplementedException("Gssapi Support on Non-Windows Machinse is Not Implemented.");
6666
//return new GsaslGssapiImplementation(
6767
// connection.ServerInstance.Address.Host,
68-
// credentials.Username,
69-
// credentials.Evidence);
68+
// credential.Username,
69+
// credential.Evidence);
7070
}
7171

7272
return new WindowsGssapiImplementation(
7373
connection.ServerInstance.Address.Host,
74-
credentials.Username,
75-
credentials.Evidence);
74+
credential.Username,
75+
credential.Evidence);
7676
}
7777
}
7878
}

MongoDB.Driver/Communication/Security/Mechanisms/Sspi/SecurityContext.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace MongoDB.Driver.Communication.Security.Mechanisms.Sspi
2525
internal class SecurityContext : SafeHandle
2626
{
2727
// private fields
28-
private SecurityCredentials _credentials;
28+
private SecurityCredential _credential;
2929
private SspiHandle _sspiHandle;
3030
private bool _isInitialized;
3131

@@ -43,15 +43,15 @@ public SecurityContext()
4343
/// <summary>
4444
/// Initializes the context.
4545
/// </summary>
46-
/// <param name="credentials">The credentials.</param>
46+
/// <param name="credential">The credential.</param>
4747
/// <param name="servicePrincipalName">Name of the service principal.</param>
4848
/// <param name="input">The input.</param>
4949
/// <param name="output">The output.</param>
5050
/// <returns></returns>
51-
public static SecurityContext Initialize(SecurityCredentials credentials, string servicePrincipalName, byte[] input, out byte[] output)
51+
public static SecurityContext Initialize(SecurityCredential credential, string servicePrincipalName, byte[] input, out byte[] output)
5252
{
5353
var context = new SecurityContext();
54-
context._credentials = credentials;
54+
context._credential = credential;
5555

5656
context.Initialize(servicePrincipalName, input, out output);
5757
return context;
@@ -261,21 +261,21 @@ public void Initialize(string servicePrincipalName, byte[] inBytes, out byte[] o
261261

262262
var outputBuffer = new SecurityBufferDescriptor(Win32.MAX_TOKEN_SIZE);
263263

264-
bool credentialsAddRefSuccess = false;
264+
bool credentialAddRefSuccess = false;
265265
bool contextAddRefSuccess = false;
266266

267267
RuntimeHelpers.PrepareConstrainedRegions();
268268
try
269269
{
270-
_credentials.DangerousAddRef(ref credentialsAddRefSuccess);
270+
_credential.DangerousAddRef(ref credentialAddRefSuccess);
271271
DangerousAddRef(ref contextAddRefSuccess);
272272
}
273273
catch (Exception ex)
274274
{
275-
if (credentialsAddRefSuccess)
275+
if (credentialAddRefSuccess)
276276
{
277-
_credentials.DangerousRelease();
278-
credentialsAddRefSuccess = false;
277+
_credential.DangerousRelease();
278+
credentialAddRefSuccess = false;
279279
}
280280
if (contextAddRefSuccess)
281281
{
@@ -296,11 +296,11 @@ public void Initialize(string servicePrincipalName, byte[] inBytes, out byte[] o
296296

297297
uint result;
298298
long timestamp;
299-
var credentialsHandle = _credentials._sspiHandle;
299+
var credentialHandle = _credential._sspiHandle;
300300
if (inBytes == null || inBytes.Length == 0)
301301
{
302302
result = Win32.InitializeSecurityContext(
303-
ref credentialsHandle,
303+
ref credentialHandle,
304304
IntPtr.Zero,
305305
servicePrincipalName,
306306
flags,
@@ -319,7 +319,7 @@ public void Initialize(string servicePrincipalName, byte[] inBytes, out byte[] o
319319
try
320320
{
321321
result = Win32.InitializeSecurityContext(
322-
ref credentialsHandle,
322+
ref credentialHandle,
323323
ref _sspiHandle,
324324
servicePrincipalName,
325325
flags,
@@ -338,7 +338,7 @@ public void Initialize(string servicePrincipalName, byte[] inBytes, out byte[] o
338338
}
339339
}
340340

341-
_credentials.DangerousRelease();
341+
_credential.DangerousRelease();
342342
DangerousRelease();
343343

344344
if (result != Win32.SEC_E_OK && result != Win32.SEC_I_CONTINUE_NEEDED)

0 commit comments

Comments
 (0)