Unverified Commit ab36896e authored by honfika's avatar honfika Committed by GitHub

Merge pull request #640 from justcoding121/master

Support EnableWinAuth per session #633
parents d0a7738b b88a11b3
......@@ -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;
......@@ -28,6 +30,7 @@ namespace Titanium.Web.Proxy.EventArguments
protected readonly IBufferPool BufferPool;
protected readonly ExceptionHandler ExceptionFunc;
private bool enableWinAuth;
/// <summary>
/// Relative milliseconds for various events.
......@@ -53,6 +56,7 @@ namespace Titanium.Web.Proxy.EventArguments
ProxyClient = new ProxyClient();
HttpClient = new HttpWebClient(request);
LocalEndPoint = endPoint;
EnableWinAuth = server.EnableWinAuth && isWindowsAuthenticationSupported;
HttpClient.ProcessId = new Lazy<int>(() => ProxyClient.Connection.GetProcessId(endPoint));
}
......@@ -72,6 +76,21 @@ namespace Titanium.Web.Proxy.EventArguments
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>
......
......@@ -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
......@@ -158,7 +155,7 @@ namespace Titanium.Web.Proxy
// 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);
}
......
......@@ -39,7 +39,7 @@ namespace Titanium.Web.Proxy
args.ReRequest = false;
// check for windows authentication
if (isWindowsAuthenticationEnabledAndSupported)
if (args.EnableWinAuth)
{
if (response.StatusCode == (int)HttpStatusCode.Unauthorized)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment