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 ...@@ -20,6 +20,8 @@ namespace Titanium.Web.Proxy.EventArguments
/// </summary> /// </summary>
public abstract class SessionEventArgsBase : EventArgs, IDisposable public abstract class SessionEventArgsBase : EventArgs, IDisposable
{ {
private static bool isWindowsAuthenticationSupported => RunTime.IsWindows;
internal readonly CancellationTokenSource CancellationTokenSource; internal readonly CancellationTokenSource CancellationTokenSource;
internal TcpServerConnection ServerConnection => HttpClient.Connection; internal TcpServerConnection ServerConnection => HttpClient.Connection;
...@@ -28,6 +30,7 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -28,6 +30,7 @@ namespace Titanium.Web.Proxy.EventArguments
protected readonly IBufferPool BufferPool; protected readonly IBufferPool BufferPool;
protected readonly ExceptionHandler ExceptionFunc; protected readonly ExceptionHandler ExceptionFunc;
private bool enableWinAuth;
/// <summary> /// <summary>
/// Relative milliseconds for various events. /// Relative milliseconds for various events.
...@@ -53,6 +56,7 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -53,6 +56,7 @@ namespace Titanium.Web.Proxy.EventArguments
ProxyClient = new ProxyClient(); ProxyClient = new ProxyClient();
HttpClient = new HttpWebClient(request); HttpClient = new HttpWebClient(request);
LocalEndPoint = endPoint; LocalEndPoint = endPoint;
EnableWinAuth = server.EnableWinAuth && isWindowsAuthenticationSupported;
HttpClient.ProcessId = new Lazy<int>(() => ProxyClient.Connection.GetProcessId(endPoint)); HttpClient.ProcessId = new Lazy<int>(() => ProxyClient.Connection.GetProcessId(endPoint));
} }
...@@ -72,6 +76,21 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -72,6 +76,21 @@ namespace Titanium.Web.Proxy.EventArguments
set => HttpClient.UserData = value; 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> /// <summary>
/// Does this session uses SSL? /// Does this session uses SSL?
/// </summary> /// </summary>
......
...@@ -27,9 +27,6 @@ namespace Titanium.Web.Proxy ...@@ -27,9 +27,6 @@ namespace Titanium.Web.Proxy
/// </summary> /// </summary>
public partial class ProxyServer public partial class ProxyServer
{ {
private bool isWindowsAuthenticationEnabledAndSupported =>
EnableWinAuth && RunTime.IsWindows;
/// <summary> /// <summary>
/// This is the core request handler method for a particular connection from client. /// This is the core request handler method for a particular connection from client.
/// Will create new session (request/response) sequence until /// Will create new session (request/response) sequence until
...@@ -158,7 +155,7 @@ namespace Titanium.Web.Proxy ...@@ -158,7 +155,7 @@ namespace Titanium.Web.Proxy
// if win auth is enabled // if win auth is enabled
// we need a cache of request body // we need a cache of request body
// so that we can send it after authentication in WinAuthHandler.cs // so that we can send it after authentication in WinAuthHandler.cs
if (isWindowsAuthenticationEnabledAndSupported && request.HasBody) if (args.EnableWinAuth && request.HasBody)
{ {
await args.GetRequestBody(cancellationToken); await args.GetRequestBody(cancellationToken);
} }
......
...@@ -39,7 +39,7 @@ namespace Titanium.Web.Proxy ...@@ -39,7 +39,7 @@ namespace Titanium.Web.Proxy
args.ReRequest = false; args.ReRequest = false;
// check for windows authentication // check for windows authentication
if (isWindowsAuthenticationEnabledAndSupported) if (args.EnableWinAuth)
{ {
if (response.StatusCode == (int)HttpStatusCode.Unauthorized) 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