This repository was archived by the owner on Nov 1, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#2 Platform handler middleware, sample, tests, functional tests.
- Loading branch information
Showing
29 changed files
with
4,188 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 14 | ||
VisualStudioVersion = 14.0.23107.0 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{04B1EDB6-E967-4D25-89B9-E6F8304038CD}" | ||
EndProject | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{0EF45656-B25D-40D8-959C-726EAF185E60}" | ||
ProjectSection(SolutionItems) = preProject | ||
global.json = global.json | ||
NuGet.Config = NuGet.Config | ||
EndProjectSection | ||
EndProject | ||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.IISPlatformHandler", "src\Microsoft.AspNet.IISPlatformHandler\Microsoft.AspNet.IISPlatformHandler.xproj", "{ABE53415-83CE-4AF0-AF67-E52160C7862B}" | ||
EndProject | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{EF30B533-D715-421A-92B7-92FEF460AC9C}" | ||
EndProject | ||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.IISPlatformHandler.Tests", "test\Microsoft.AspNet.IISPlatformHandler.Tests\Microsoft.AspNet.IISPlatformHandler.Tests.xproj", "{FBBBE015-1CE3-454B-9647-23F8073FB7AB}" | ||
EndProject | ||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.IISPlatformHandler.FunctionalTests", "test\Microsoft.AspNet.IISPlatformHandler.FunctionalTests\Microsoft.AspNet.IISPlatformHandler.FunctionalTests.xproj", "{A83A33D1-3D29-403C-9750-5811AC7B4025}" | ||
EndProject | ||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "TestSites", "test\TestSites\TestSites.xproj", "{E27453AD-9CA0-49A2-94FA-96337D77677D}" | ||
EndProject | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{C74B8F36-FD2F-45C9-9B8A-00E7CF0126A9}" | ||
EndProject | ||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "IISSample", "samples\IISSample\IISSample.xproj", "{E4E2BDC4-A9C6-4AE9-B429-032EC83EDE64}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{ABE53415-83CE-4AF0-AF67-E52160C7862B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{ABE53415-83CE-4AF0-AF67-E52160C7862B}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{ABE53415-83CE-4AF0-AF67-E52160C7862B}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{ABE53415-83CE-4AF0-AF67-E52160C7862B}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{FBBBE015-1CE3-454B-9647-23F8073FB7AB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{FBBBE015-1CE3-454B-9647-23F8073FB7AB}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{FBBBE015-1CE3-454B-9647-23F8073FB7AB}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{FBBBE015-1CE3-454B-9647-23F8073FB7AB}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{A83A33D1-3D29-403C-9750-5811AC7B4025}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{A83A33D1-3D29-403C-9750-5811AC7B4025}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{A83A33D1-3D29-403C-9750-5811AC7B4025}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{A83A33D1-3D29-403C-9750-5811AC7B4025}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{E27453AD-9CA0-49A2-94FA-96337D77677D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{E27453AD-9CA0-49A2-94FA-96337D77677D}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{E27453AD-9CA0-49A2-94FA-96337D77677D}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{E27453AD-9CA0-49A2-94FA-96337D77677D}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{E4E2BDC4-A9C6-4AE9-B429-032EC83EDE64}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{E4E2BDC4-A9C6-4AE9-B429-032EC83EDE64}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{E4E2BDC4-A9C6-4AE9-B429-032EC83EDE64}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{E4E2BDC4-A9C6-4AE9-B429-032EC83EDE64}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(NestedProjects) = preSolution | ||
{ABE53415-83CE-4AF0-AF67-E52160C7862B} = {04B1EDB6-E967-4D25-89B9-E6F8304038CD} | ||
{FBBBE015-1CE3-454B-9647-23F8073FB7AB} = {EF30B533-D715-421A-92B7-92FEF460AC9C} | ||
{A83A33D1-3D29-403C-9750-5811AC7B4025} = {EF30B533-D715-421A-92B7-92FEF460AC9C} | ||
{E27453AD-9CA0-49A2-94FA-96337D77677D} = {EF30B533-D715-421A-92B7-92FEF460AC9C} | ||
{E4E2BDC4-A9C6-4AE9-B429-032EC83EDE64} = {C74B8F36-FD2F-45C9-9B8A-00E7CF0126A9} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion> | ||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath> | ||
</PropertyGroup> | ||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" /> | ||
<PropertyGroup Label="Globals"> | ||
<ProjectGuid>e4e2bdc4-a9c6-4ae9-b429-032ec83ede64</ProjectGuid> | ||
<RootNamespace>IISSample</RootNamespace> | ||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath> | ||
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<SchemaVersion>2.0</SchemaVersion> | ||
<DevelopmentServerPort>65029</DevelopmentServerPort> | ||
</PropertyGroup> | ||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" /> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using System; | ||
using Microsoft.AspNet.Builder; | ||
using Microsoft.AspNet.Http; | ||
using Microsoft.Framework.Logging; | ||
|
||
namespace IISSample | ||
{ | ||
public class Startup | ||
{ | ||
public void Configure(IApplicationBuilder app, ILoggerFactory loggerfactory) | ||
{ | ||
loggerfactory.AddConsole(LogLevel.Verbose); | ||
|
||
var logger = loggerfactory.CreateLogger("Requests"); | ||
|
||
app.Run(async (context) => | ||
{ | ||
logger.LogVerbose("Received request: " + context.Request.Method + " " + context.Request.Path); | ||
|
||
context.Response.ContentType = "text/plain"; | ||
await context.Response.WriteAsync("Hello World - " + DateTimeOffset.Now + Environment.NewLine); | ||
await context.Response.WriteAsync("User - " + context.User.Identity.Name + Environment.NewLine); | ||
foreach (var header in context.Request.Headers) | ||
{ | ||
await context.Response.WriteAsync(header.Key + ": " + header.Value + Environment.NewLine); | ||
} | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
"webroot": "wwwroot", | ||
"version": "1.0.0-*", | ||
|
||
"dependencies": { | ||
"Microsoft.AspNet.IISPlatformHandler": "1.0.0-*", | ||
"Microsoft.AspNet.Server.Kestrel": "1.0.0-*", | ||
"Microsoft.AspNet.Server.WebListener": "1.0.0-*", | ||
"Microsoft.Framework.Logging.Console": "1.0.0-*" | ||
}, | ||
|
||
"commands": { | ||
"weblistener": "Microsoft.AspNet.Server.WebListener", | ||
"web": "Microsoft.AspNet.Server.Kestrel" | ||
}, | ||
|
||
"frameworks": { | ||
"dnx451": { }, | ||
"dnxcore50": { } | ||
}, | ||
|
||
"publishExclude": [ | ||
"node_modules", | ||
"bower_components", | ||
"**.xproj", | ||
"**.user", | ||
"**.vspscc" | ||
], | ||
"exclude": [ | ||
"wwwroot", | ||
"node_modules", | ||
"bower_components" | ||
] | ||
} |
85 changes: 85 additions & 0 deletions
85
src/Microsoft.AspNet.IISPlatformHandler/IISPlatformHandlerMiddleware.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Globalization; | ||
using System.Net; | ||
using System.Security.Principal; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNet.Builder; | ||
using Microsoft.AspNet.Http; | ||
using Microsoft.Framework.Internal; | ||
using Microsoft.Framework.Primitives; | ||
|
||
namespace Microsoft.AspNet.IISPlatformHandler | ||
{ | ||
public class IISPlatformHandlerMiddleware | ||
{ | ||
private const string XForwardedForHeaderName = "X-Forwarded-For"; | ||
private const string XForwardedProtoHeaderName = "X-Forwarded-Proto"; | ||
private const string XIISWindowsAuthToken = "X-IIS-WindowsAuthToken"; | ||
private const string XOriginalProtoName = "X-Original-Proto"; | ||
private const string XOriginalIPName = "X-Original-IP"; | ||
|
||
private readonly RequestDelegate _next; | ||
|
||
public IISPlatformHandlerMiddleware(RequestDelegate next) | ||
{ | ||
_next = next; | ||
} | ||
|
||
public Task Invoke(HttpContext httpContext) | ||
{ | ||
var xForwardProtoHeaderValue = httpContext.Request.Headers[XForwardedProtoHeaderName]; | ||
if (!string.IsNullOrEmpty(xForwardProtoHeaderValue)) | ||
{ | ||
if (!string.IsNullOrEmpty(httpContext.Request.Scheme)) | ||
{ | ||
httpContext.Request.Headers[XOriginalProtoName] = httpContext.Request.Scheme; | ||
} | ||
httpContext.Request.Scheme = xForwardProtoHeaderValue; | ||
} | ||
|
||
var xForwardedForHeaderValue = httpContext.Request.Headers.GetCommaSeparatedValues(XForwardedForHeaderName); | ||
if (xForwardedForHeaderValue != null && xForwardedForHeaderValue.Length > 0) | ||
{ | ||
IPAddress ipFromHeader; | ||
if (IPAddress.TryParse(xForwardedForHeaderValue[0], out ipFromHeader)) | ||
{ | ||
var remoteIPString = httpContext.Connection.RemoteIpAddress?.ToString(); | ||
if (!string.IsNullOrEmpty(remoteIPString)) | ||
{ | ||
httpContext.Request.Headers[XOriginalIPName] = remoteIPString; | ||
} | ||
httpContext.Connection.RemoteIpAddress = ipFromHeader; | ||
} | ||
} | ||
|
||
var xIISWindowsAuthToken = httpContext.Request.Headers[XIISWindowsAuthToken]; | ||
int hexHandle; | ||
if (!StringValues.IsNullOrEmpty(xIISWindowsAuthToken) | ||
&& int.TryParse(xIISWindowsAuthToken, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out hexHandle)) | ||
{ | ||
var handle = new IntPtr(hexHandle); | ||
var winIdentity = new WindowsIdentity(handle); | ||
// WindowsIdentity just duplicated the handle so we need to close the original. | ||
NativeMethods.CloseHandle(handle); | ||
|
||
httpContext.Response.RegisterForDispose(winIdentity); | ||
var winPrincipal = new WindowsPrincipal(winIdentity); | ||
|
||
var existingPrincipal = httpContext.User; | ||
if (existingPrincipal != null) | ||
{ | ||
httpContext.User = SecurityHelper.MergeUserPrincipal(existingPrincipal, winPrincipal); | ||
} | ||
else | ||
{ | ||
httpContext.User = winPrincipal; | ||
} | ||
} | ||
|
||
return _next(httpContext); | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/Microsoft.AspNet.IISPlatformHandler/IISPlatformHandlerMiddlewareExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using Microsoft.AspNet.IISPlatformHandler; | ||
|
||
namespace Microsoft.AspNet.Builder | ||
{ | ||
public static class IISPlatformHandlerMiddlewareExtensions | ||
{ | ||
/// <summary> | ||
/// Adds middleware for interacting with the IIS HttpPlatformHandler reverse proxy module. | ||
/// This will handle forwarded Windows Authentication, request scheme, remote IPs, etc.. | ||
/// </summary> | ||
/// <param name="builder"></param> | ||
/// <returns></returns> | ||
public static IApplicationBuilder UseIISPlatformHandler(this IApplicationBuilder builder) | ||
{ | ||
return builder.UseMiddleware<IISPlatformHandlerMiddleware>(); | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/Microsoft.AspNet.IISPlatformHandler/Microsoft.AspNet.IISPlatformHandler.xproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion> | ||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath> | ||
</PropertyGroup> | ||
|
||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" /> | ||
<PropertyGroup Label="Globals"> | ||
<ProjectGuid>abe53415-83ce-4af0-af67-e52160c7862b</ProjectGuid> | ||
<RootNamespace>Microsoft.AspNet.PlatformHandler</RootNamespace> | ||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath> | ||
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup> | ||
<SchemaVersion>2.0</SchemaVersion> | ||
</PropertyGroup> | ||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" /> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace Microsoft.AspNet.IISPlatformHandler | ||
{ | ||
internal class NativeMethods | ||
{ | ||
#if DNXCORE50 | ||
private const string api_ms_win_core_handle_LIB = "api-ms-win-core-handle-l1-1-0.dll"; | ||
#else | ||
private const string KERNEL32 = "kernel32.dll"; | ||
#endif | ||
|
||
#if DNXCORE50 | ||
[DllImport(api_ms_win_core_handle_LIB, ExactSpelling = true, SetLastError = true)] | ||
#else | ||
[DllImport(KERNEL32, ExactSpelling = true, SetLastError = true)] | ||
#endif | ||
internal static extern bool CloseHandle(IntPtr handle); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"version": "1.0.0-*", | ||
"description": "ASP.NET 5 components for working with the IIS HttpPlatformHandler module.", | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/aspnet/IISIntegration" | ||
}, | ||
"dependencies": { | ||
"Microsoft.AspNet.Http.Extensions": "1.0.0-*", | ||
"Microsoft.Framework.SecurityHelper.Sources": { | ||
"type": "build", | ||
"version": "1.0.0-*" | ||
} | ||
}, | ||
"frameworks": { | ||
"dnx451": { }, | ||
"dnxcore50": { | ||
"dependencies": { | ||
"System.Security.Principal.Windows": "4.0.0-beta-*" | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.