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

Commit ab36896

Browse files
authored
Merge pull request #640 from justcoding121/master
Support EnableWinAuth per session #633
2 parents d0a7738 + b88a11b commit ab36896

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

src/Titanium.Web.Proxy/EventArguments/SessionEventArgsBase.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ namespace Titanium.Web.Proxy.EventArguments
2020
/// </summary>
2121
public abstract class SessionEventArgsBase : EventArgs, IDisposable
2222
{
23+
private static bool isWindowsAuthenticationSupported => RunTime.IsWindows;
24+
2325
internal readonly CancellationTokenSource CancellationTokenSource;
2426

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

2931
protected readonly IBufferPool BufferPool;
3032
protected readonly ExceptionHandler ExceptionFunc;
33+
private bool enableWinAuth;
3134

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

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

79+
/// <summary>
80+
/// Enable/disable Windows Authentication (NTLM/Kerberos) for the current session.
81+
/// </summary>
82+
public bool EnableWinAuth
83+
{
84+
get => enableWinAuth;
85+
set
86+
{
87+
if (!isWindowsAuthenticationSupported)
88+
throw new Exception("Windows Authentication is not supported");
89+
90+
enableWinAuth = value;
91+
}
92+
}
93+
7594
/// <summary>
7695
/// Does this session uses SSL?
7796
/// </summary>

src/Titanium.Web.Proxy/RequestHandler.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ namespace Titanium.Web.Proxy
2727
/// </summary>
2828
public partial class ProxyServer
2929
{
30-
private bool isWindowsAuthenticationEnabledAndSupported =>
31-
EnableWinAuth && RunTime.IsWindows;
32-
3330
/// <summary>
3431
/// This is the core request handler method for a particular connection from client.
3532
/// Will create new session (request/response) sequence until
@@ -158,7 +155,7 @@ await clientStreamWriter.WriteResponseAsync(args.HttpClient.Response,
158155
// if win auth is enabled
159156
// we need a cache of request body
160157
// so that we can send it after authentication in WinAuthHandler.cs
161-
if (isWindowsAuthenticationEnabledAndSupported && request.HasBody)
158+
if (args.EnableWinAuth && request.HasBody)
162159
{
163160
await args.GetRequestBody(cancellationToken);
164161
}

src/Titanium.Web.Proxy/ResponseHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ private async Task handleHttpSessionResponse(SessionEventArgs args)
3939
args.ReRequest = false;
4040

4141
// check for windows authentication
42-
if (isWindowsAuthenticationEnabledAndSupported)
42+
if (args.EnableWinAuth)
4343
{
4444
if (response.StatusCode == (int)HttpStatusCode.Unauthorized)
4545
{

0 commit comments

Comments
 (0)