forked from i8beef/SAML2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSaml20CDCReader.cs
More file actions
51 lines (44 loc) · 1.95 KB
/
Saml20CDCReader.cs
File metadata and controls
51 lines (44 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System.Linq;
using System.Web;
using SAML2.Config;
using SAML2.Exceptions;
namespace SAML2.Protocol
{
/// <summary>
/// Common Domain Cookie reader endpoint
/// </summary>
public class Saml20CDCReader : AbstractEndpointHandler
{
/// <summary>
/// Enables processing of HTTP Web requests by a custom HttpHandler that implements the <see cref="T:System.Web.IHttpHandler"/> interface.
/// </summary>
/// <param name="context">An <see cref="T:System.Web.HttpContext"/> object that provides references to the intrinsic server objects (for example, Request, Response, Session, and Server) used to service HTTP requests.</param>
public override void ProcessRequest(HttpContext context)
{
Logger.DebugFormat("{0}.{1} called", GetType(), "ProcessRequest()");
var config = Saml2Config.Current;
if (config == null)
{
throw new Saml20Exception("Missing saml2 config section in web.config.");
}
var endp = config.ServiceProvider.Endpoints.FirstOrDefault(ep => ep.Type == EndpointType.SignOn);
if (endp == null)
{
throw new Saml20Exception("Signon endpoint not found in configuration");
}
var returnUrl = config.ServiceProvider.Server + endp.LocalPath + "?r=1";
var samlIdp = context.Request.Cookies[CommonDomainCookie.CommonDomainCookieName];
if (samlIdp != null)
{
returnUrl += "&_saml_idp=" + HttpUtility.UrlEncode(samlIdp.Value);
Logger.DebugFormat(TraceMessages.CommonDomainCookieReceived, samlIdp.Value);
Logger.Debug(TraceMessages.CommonDomainCookieRedirect);
}
else
{
Logger.DebugFormat(TraceMessages.CommonDomainCookieRedirectNotFound, returnUrl);
}
context.Response.Redirect(returnUrl);
}
}
}