internal static void CreateSessionId(Guid sessionId) { SamlHttpContext.Current.Request.Cookies.Remove(SessionConstants.SessionCookieName); // Remove cookie from request when creating a new session id. This is necessary because adding a cookie with the same name does not override cookies in the request. SamlHttpCookie httpCookie = new SamlHttpCookie(SessionConstants.SessionCookieName, sessionId.ToString()); httpCookie.Secure = true; httpCookie.HttpOnly = true; SamlHttpContext.Current.Response.Cookies.Add(httpCookie); // When a cookie is added to the response it is automatically added to the request. Thus, SessionId is available immeditly when reading cookies from the request. }
private void LoadCookie() { if (!_isLoaded) { SamlHttpCookie cdc = _cookies[COMMON_DOMAIN_COOKIE_NAME]; if (cdc != null) { ParseCookie(cdc.Value); _isSet = true; } _isLoaded = true; } }
/// <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.SamlContext"/> 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(SamlHttpContext context) { try { Trace.TraceMethodCalled(GetType(), "ProcessRequest()"); SAML20FederationConfig config = SAML20FederationConfig.GetConfig(); if (config == null) { throw new Saml20Exception("Missing SAML20Federation config section in web.config."); } Saml20ServiceEndpoint endp = config.ServiceProvider.serviceEndpoints.Find(delegate(Saml20ServiceEndpoint ep) { return(ep.endpointType == EndpointType.SIGNON); }); if (endp == null) { throw new Saml20Exception("Signon endpoint not found in configuration"); } string returnUrl = config.ServiceProvider.Server + endp.localPath + "?r=1"; SamlHttpCookie samlIdp = context.Request.Cookies[CommonDomainCookie.COMMON_DOMAIN_COOKIE_NAME]; if (samlIdp != null) { returnUrl += "&_saml_idp=" + HttpUtility.UrlEncode(samlIdp.Value); if (Trace.ShouldTrace(TraceEventType.Information)) { Trace.TraceData(TraceEventType.Information, string.Format(Tracing.CDC, samlIdp.Value)); } AuditLogging.logEntry(Direction.OUT, Operation.AUTHNREQUEST_REDIRECT, "Redirection to Signon endpoint found in Common Domain Cookie: " + samlIdp.Value); } else { AuditLogging.logEntry(Direction.OUT, Operation.AUTHNREQUEST_REDIRECT, "Redirection to Signon endpoint, no Common Domain Cookie found: " + returnUrl); } context.Response.Redirect(returnUrl); } catch (Exception ex) { HandleError(context, ex); } }