Skip to content
This repository was archived by the owner on Jul 9, 2023. It is now read-only.

Support EnableWinAuth per session #633 #640

Merged
merged 1 commit into from
Oct 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/Titanium.Web.Proxy/EventArguments/SessionEventArgsBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ namespace Titanium.Web.Proxy.EventArguments
/// </summary>
public abstract class SessionEventArgsBase : EventArgs, IDisposable
{
private static bool isWindowsAuthenticationSupported => RunTime.IsWindows;

internal readonly CancellationTokenSource CancellationTokenSource;

internal TcpServerConnection ServerConnection => HttpClient.Connection;
Expand All @@ -28,6 +30,7 @@ public abstract class SessionEventArgsBase : EventArgs, IDisposable

protected readonly IBufferPool BufferPool;
protected readonly ExceptionHandler ExceptionFunc;
private bool enableWinAuth;

/// <summary>
/// Relative milliseconds for various events.
Expand All @@ -53,6 +56,7 @@ protected SessionEventArgsBase(ProxyServer server, ProxyEndPoint endPoint,
ProxyClient = new ProxyClient();
HttpClient = new HttpWebClient(request);
LocalEndPoint = endPoint;
EnableWinAuth = server.EnableWinAuth && isWindowsAuthenticationSupported;

HttpClient.ProcessId = new Lazy<int>(() => ProxyClient.Connection.GetProcessId(endPoint));
}
Expand All @@ -72,6 +76,21 @@ public object UserData
set => HttpClient.UserData = value;
}

/// <summary>
/// Enable/disable Windows Authentication (NTLM/Kerberos) for the current session.
/// </summary>
public bool EnableWinAuth
{
get => enableWinAuth;
set
{
if (!isWindowsAuthenticationSupported)
throw new Exception("Windows Authentication is not supported");

enableWinAuth = value;
}
}

/// <summary>
/// Does this session uses SSL?
/// </summary>
Expand Down
5 changes: 1 addition & 4 deletions src/Titanium.Web.Proxy/RequestHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ namespace Titanium.Web.Proxy
/// </summary>
public partial class ProxyServer
{
private bool isWindowsAuthenticationEnabledAndSupported =>
EnableWinAuth && RunTime.IsWindows;

/// <summary>
/// This is the core request handler method for a particular connection from client.
/// Will create new session (request/response) sequence until
Expand Down Expand Up @@ -158,7 +155,7 @@ await clientStreamWriter.WriteResponseAsync(args.HttpClient.Response,
// if win auth is enabled
// we need a cache of request body
// so that we can send it after authentication in WinAuthHandler.cs
if (isWindowsAuthenticationEnabledAndSupported && request.HasBody)
if (args.EnableWinAuth && request.HasBody)
{
await args.GetRequestBody(cancellationToken);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Titanium.Web.Proxy/ResponseHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ private async Task handleHttpSessionResponse(SessionEventArgs args)
args.ReRequest = false;

// check for windows authentication
if (isWindowsAuthenticationEnabledAndSupported)
if (args.EnableWinAuth)
{
if (response.StatusCode == (int)HttpStatusCode.Unauthorized)
{
Expand Down