-
Notifications
You must be signed in to change notification settings - Fork 874
Expand file tree
/
Copy pathIntegratedSecurityHandler.cs
More file actions
38 lines (29 loc) · 1.93 KB
/
IntegratedSecurityHandler.cs
File metadata and controls
38 lines (29 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Npgsql.Properties;
namespace Npgsql.Internal;
class IntegratedSecurityHandler
{
public virtual bool IsSupported => false;
public virtual ValueTask<string?> GetUsername(bool async, bool includeRealm, ILogger connectionLogger, CancellationToken cancellationToken)
{
connectionLogger.LogDebug(string.Format(NpgsqlStrings.IntegratedSecurityDisabled, nameof(NpgsqlSlimDataSourceBuilder.EnableIntegratedSecurity)));
return new();
}
public virtual ValueTask NegotiateAuthentication(bool async, NpgsqlConnector connector, CancellationToken cancellationToken)
=> throw new NotSupportedException(string.Format(NpgsqlStrings.IntegratedSecurityDisabled, nameof(NpgsqlSlimDataSourceBuilder.EnableIntegratedSecurity)));
public virtual ValueTask<GssEncryptionResult> GSSEncrypt(bool async, bool isRequired, NpgsqlConnector connector, CancellationToken cancellationToken)
=> throw new NotSupportedException(string.Format(NpgsqlStrings.IntegratedSecurityDisabled, nameof(NpgsqlSlimDataSourceBuilder.EnableIntegratedSecurity)));
}
sealed class RealIntegratedSecurityHandler : IntegratedSecurityHandler
{
public override bool IsSupported => true;
public override ValueTask<string?> GetUsername(bool async, bool includeRealm, ILogger connectionLogger, CancellationToken cancellationToken)
=> KerberosUsernameProvider.GetUsername(async, includeRealm, connectionLogger, cancellationToken);
public override ValueTask NegotiateAuthentication(bool async, NpgsqlConnector connector, CancellationToken cancellationToken)
=> connector.AuthenticateGSS(async, cancellationToken);
public override ValueTask<GssEncryptionResult> GSSEncrypt(bool async, bool isRequired, NpgsqlConnector connector, CancellationToken cancellationToken)
=> connector.GSSEncrypt(async, isRequired, cancellationToken);
}