forked from Sustainsys/Saml2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move the HttpModule to an own assembly and remove System.Web depdency.
- Fixes Sustainsys#97, Closes Sustainsys#179. - Improved config handling from code, no longer requires a <System.IdentityModel> section.
- Loading branch information
Showing
57 changed files
with
1,052 additions
and
322 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 |
---|---|---|
|
@@ -7,3 +7,4 @@ Rosanna Wahlstr | |
Lisa Bylund | ||
Sebastian Allard | ||
Jozef Raschmann | ||
Tor-Bj�rn Holmstr�m |
84 changes: 84 additions & 0 deletions
84
Kentor.AuthServices.HttpModule/CommandResultHttpExtension.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,84 @@ | ||
using Kentor.AuthServices.WebSso; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.IdentityModel.Services; | ||
using System.IdentityModel.Tokens; | ||
using System.Linq; | ||
using System.Net; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Web; | ||
|
||
namespace Kentor.AuthServices.HttpModule | ||
{ | ||
/// <summary> | ||
/// Extension methods to CommandResult to update a HttpResponseBase. | ||
/// </summary> | ||
public static class CommandResultHttpExtension | ||
{ | ||
/// <summary> | ||
/// Apply the command result to a bare HttpResponse. | ||
/// </summary> | ||
/// <param name="commandResult">The CommandResult that will update the HttpResponse.</param> | ||
/// <param name="response">Http Response to write the result to.</param> | ||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "HttpStatusCode")] | ||
public static void Apply(this CommandResult commandResult, HttpResponseBase response) | ||
{ | ||
if (commandResult == null) | ||
{ | ||
throw new ArgumentNullException("commandResult"); | ||
} | ||
|
||
if (response == null) | ||
{ | ||
throw new ArgumentNullException("response"); | ||
} | ||
|
||
response.Cache.SetCacheability((HttpCacheability)commandResult.Cacheability); | ||
|
||
if (commandResult.HttpStatusCode == HttpStatusCode.SeeOther || commandResult.Location != null) | ||
{ | ||
if (commandResult.Location == null) | ||
{ | ||
throw new InvalidOperationException("Missing Location on redirect."); | ||
} | ||
if (commandResult.HttpStatusCode != HttpStatusCode.SeeOther) | ||
{ | ||
throw new InvalidOperationException("Invalid HttpStatusCode for redirect, but Location is specified"); | ||
} | ||
|
||
response.Redirect(commandResult.Location.OriginalString); | ||
} | ||
else | ||
{ | ||
response.StatusCode = (int)commandResult.HttpStatusCode; | ||
response.ContentType = commandResult.ContentType; | ||
response.Write(commandResult.Content); | ||
|
||
response.End(); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Establishes an application session by calling the session authentication module. | ||
/// </summary> | ||
[ExcludeFromCodeCoverage] | ||
public static void SignInSessionAuthenticationModule(this CommandResult commandResult) | ||
{ | ||
if(commandResult == null) | ||
{ | ||
throw new ArgumentNullException("commandResult"); | ||
} | ||
|
||
// Ignore this if we're not running inside IIS, e.g. in unit tests. | ||
if (commandResult.Principal != null && HttpContext.Current != null) | ||
{ | ||
var sessionToken = new SessionSecurityToken(commandResult.Principal); | ||
|
||
FederatedAuthentication.SessionAuthenticationModule | ||
.AuthenticateSessionSecurityToken(sessionToken, true); | ||
} | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
Kentor.AuthServices.HttpModule/HttpRequestBaseExtensions.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,36 @@ | ||
using Kentor.AuthServices.WebSso; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Web; | ||
|
||
namespace Kentor.AuthServices.HttpModule | ||
{ | ||
/// <summary> | ||
/// Static class that hold extension methods for <see cref="HttpRequestBase"/>. | ||
/// </summary> | ||
public static class HttpRequestBaseExtensions | ||
{ | ||
/// <summary> | ||
/// Extension method to convert a HttpRequestBase to a HttpRequestData. | ||
/// </summary> | ||
/// <param name="requestBase">The request object used to populate the <c>HttpRequestData</c>.</param> | ||
/// <returns>The <c>HttpRequestData</c> object that has been populated by the request.</returns> | ||
public static HttpRequestData ToHttpRequestData(this HttpRequestBase requestBase) | ||
{ | ||
if (requestBase == null) | ||
{ | ||
throw new ArgumentNullException("requestBase"); | ||
} | ||
|
||
return new HttpRequestData( | ||
requestBase.HttpMethod, | ||
requestBase.Url, | ||
requestBase.ApplicationPath, | ||
requestBase.Form.Cast<string>().Select((de, i) => | ||
new KeyValuePair<string, string[]>(de, ((string)requestBase.Form[i]).Split(',')))); | ||
} | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
Kentor.AuthServices.HttpModule/Kentor.AuthServices.HttpModule.csproj
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,75 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{86A588E8-2E2D-4394-9545-24D8EA939CF2}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>Kentor.AuthServices.HttpModule</RootNamespace> | ||
<AssemblyName>Kentor.AuthServices.HttpModule</AssemblyName> | ||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
<RunCodeAnalysis>true</RunCodeAnalysis> | ||
<CodeAnalysisRuleSet>..\Kentor.AuthServices.ruleset</CodeAnalysisRuleSet> | ||
<DocumentationFile>bin\Debug\Kentor.AuthServices.HttpModule.XML</DocumentationFile> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.IdentityModel" /> | ||
<Reference Include="System.identitymodel.services" /> | ||
<Reference Include="System.Web" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Xml" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="..\VersionInfo.cs"> | ||
<Link>VersionInfo.cs</Link> | ||
</Compile> | ||
<Compile Include="CommandResultHttpExtension.cs" /> | ||
<Compile Include="HttpRequestBaseExtensions.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
<Compile Include="Saml2AuthenticationModule.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\Kentor.AuthServices\Kentor.AuthServices.csproj"> | ||
<Project>{93ba675e-a159-4701-b68b-c4b81015c556}</Project> | ||
<Name>Kentor.AuthServices</Name> | ||
</ProjectReference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<CodeAnalysisDictionary Include="..\CustomDictionary.xml"> | ||
<Link>CustomDictionary.xml</Link> | ||
</CodeAnalysisDictionary> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. | ||
Other similar extension points exist, see Microsoft.Common.targets. | ||
<Target Name="BeforeBuild"> | ||
</Target> | ||
<Target Name="AfterBuild"> | ||
</Target> | ||
--> | ||
</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
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 @@ | ||
using System; | ||
using System.Reflection; | ||
using System.Runtime.InteropServices; | ||
|
||
// General Information about an assembly is controlled through the following | ||
// set of attributes. Change these attribute values to modify the information | ||
// associated with an assembly. | ||
[assembly: AssemblyTitle("Kentor.AuthServices.HttpModule")] | ||
[assembly: AssemblyDescription("SAML2 Authentication for ASP.NET")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyProduct("Kentor.AuthServices.HttpModule")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
// Setting ComVisible to false makes the types in this assembly not visible | ||
// to COM components. If you need to access a type in this assembly from | ||
// COM, set the ComVisible attribute to true on that type. | ||
[assembly: ComVisible(false)] | ||
|
||
// The following GUID is for the ID of the typelib if this project is exposed to COM | ||
[assembly: Guid("5466be68-ecee-4495-96e9-ee3a8ae14987")] | ||
|
||
[assembly: CLSCompliant(true)] |
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
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
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
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
Oops, something went wrong.