Skip to content

Commit

Permalink
Nullref?
Browse files Browse the repository at this point in the history
  • Loading branch information
John Luo committed Aug 20, 2020
1 parent 02073d4 commit 8bc6eab
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/Security/Authentication/Negotiate/src/NegotiateHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,6 @@ public class NegotiateHandler : AuthenticationHandler<NegotiateOptions>, IAuthen
public NegotiateHandler(IOptionsMonitor<NegotiateOptions> options, ILoggerFactory logger, UrlEncoder encoder, ISystemClock clock)
: base(options, logger, encoder, clock)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && Options?.LdapConnectionOptions != null)
{
if (string.IsNullOrEmpty(Options.LdapConnectionOptions.Domain))
{
throw new InvalidOperationException($"{nameof(LdapConnectionOptions)} is configured but {nameof(LdapConnectionOptions.Domain)} is not set");
}

_linuxAdapter = new LinuxAdapter(Options, Logger);
}
}

/// <summary>
Expand Down Expand Up @@ -341,6 +332,16 @@ protected override async Task<AuthenticateResult> HandleAuthenticateAsync()
Principal = user
};

if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && Options?.LdapConnectionOptions != null && _linuxAdapter == null)
{
if (string.IsNullOrEmpty(Options.LdapConnectionOptions.Domain))
{
throw new InvalidOperationException($"{nameof(LdapConnectionOptions)} is configured but {nameof(LdapConnectionOptions.Domain)} is not set");
}

_linuxAdapter = new LinuxAdapter(Options, Logger);
}

if (_linuxAdapter != null)
{
await _linuxAdapter.OnAuthenticatedAsync(authenticatedContext);
Expand Down

0 comments on commit 8bc6eab

Please sign in to comment.