public CompareProductsService(CatalogSettings catalogSettings, CookieSettings cookieSettings, IHttpContextAccessor httpContextAccessor, IProductService productService, IWebHelper webHelper) { _catalogSettings = catalogSettings; _cookieSettings = cookieSettings; _httpContextAccessor = httpContextAccessor; _productService = productService; _webHelper = webHelper; }
/// <summary> /// Overloaded constructor that is given the Settings node from the Config file and /// populates the settings object. /// </summary> /// <param name="node"></param> public SecurityConfig(XmlNode node) { // try to find a node with the name of the server. var serverName = Environment.MachineName.ToLower(); XmlNode serverNode = node.SelectSingleNode(serverName); // if no server node exists, look for a "default" node. if (serverNode == null) { serverNode = node.SelectSingleNode("default"); } //#Region "cookie" XmlNode cookieNode = serverNode.SelectSingleNode("./cookie"); if (cookieNode != null) { // if a cookie domain name exists (and is NOT localhost) use it. var domainName = cookieNode.Attributes["domain"] == null ? null : cookieNode.Attributes["domain"].Value.ToLower().Trim() == ".localhost" ? null : cookieNode.Attributes["domain"].Value; // if a cookie domain name exists (and is NOT localhost) use it. var timeout = cookieNode.Attributes["timeout"] == null ? 30 : int.Parse(cookieNode.Attributes["timeout"].Value); var slidingExpiration = cookieNode.Attributes["slidingexpiration"] == null ? false : cookieNode.Attributes["slidingexpiration"].Value == "true" ? true : false; var passwordHashed = cookieNode.Attributes["passwordhashed"] == null ? false : cookieNode.Attributes["passwordhashed"].Value == "true" ? true : false; var cookieOnlyCheck = cookieNode.Attributes["cookieonlycheck"] == null ? false : cookieNode.Attributes["cookieonlycheck"].Value == "true" ? true : false; var maximumPasswordRetries = cookieNode.Attributes["maximumpasswordretries"] == null ? 5 : int.Parse(cookieNode.Attributes["maximumpasswordretries"].Value); var enable2FA = cookieNode.Attributes["enable2fa"] == null ? true : cookieNode.Attributes["enable2fa"].Value == "true" ? true : false; var exemptlocaluserfrom2fa = cookieNode.Attributes["exemptlocaluserfrom2fa"] == null ? true : cookieNode.Attributes["exemptlocaluserfrom2fa"].Value == "true" ? true : false; this.Cookie = new CookieSettings(domainName, timeout.ToString(), slidingExpiration, passwordHashed, cookieOnlyCheck, maximumPasswordRetries, enable2FA, exemptlocaluserfrom2fa); } //#End Region //#Region "login" XmlNode loginNode = serverNode.SelectSingleNode("./login"); if (loginNode != null) { var url = loginNode.Attributes["url"] == null ? null : loginNode.Attributes["url"].Value; var page = loginNode.Attributes["page"] == null ? null : loginNode.Attributes["page"].Value; this.Login = new LoginSettings(url, page); //#End Region } }
public IActionResult CookieSettingsGet() { CookieSettings cookieSettings = CookieHelper.GetCookieSettingsCookie(Request); var cookieSettingsViewModel = new CookieSettingsViewModel { GoogleAnalyticsGpg = cookieSettings.GoogleAnalyticsGpg ? "On" : "Off", GoogleAnalyticsGovUk = cookieSettings.GoogleAnalyticsGovUk ? "On" : "Off", RememberSettings = cookieSettings.RememberSettings ? "On" : "Off" }; return(View("CookieSettings", cookieSettingsViewModel)); }
public IActionResult AcceptAllCookies() { var cookieSettings = new CookieSettings { GoogleAnalyticsGpg = true, GoogleAnalyticsGovUk = true, RememberSettings = true }; CookieHelper.SetCookieSettingsCookie(Response, cookieSettings); CookieHelper.SetSeenCookieMessageCookie(Response); return(RedirectToAction("Index", "Viewing")); }
public IActionResult CookieConsent(CookieConsent consent) { var additionalCookiesConsent = consent.AdditionalCookies == "accept"; var cookieSettings = new CookieSettings { GoogleAnalyticsGpg = additionalCookiesConsent, GoogleAnalyticsGovUk = additionalCookiesConsent, RememberSettings = additionalCookiesConsent }; CookieHelper.SetCookieSettingsCookie(Response, cookieSettings); CookieHelper.SetSeenCookieMessageCookie(Response); return(RedirectToAction("Index", "Viewing")); }
public void SaveComparedEmployersToCookie(HttpRequest request) { IList <string> employerIds = ComparedEmployers.Value.ToList(); CookieSettings cookieSettings = CookieHelper.GetCookieSettingsCookie(request); if (cookieSettings.RememberSettings) { //Save into the cookie HttpContext.SetResponseCookie( CookieNames.LastCompareQuery, employerIds.ToDelimitedString(), VirtualDateTime.Now.AddMonths(1), secure: true); } }
public void UsesProvidedValues() { var cookieName = new CookieName("foo"); const bool httpOnly = false; const CookieSecurePreference secureOnly = CookieSecurePreference.Never; const CookieSameSiteMode sameSiteMode = CookieSameSiteMode.Strict; var expectedCookieSettings = new CookieSettings(cookieName, httpOnly, secureOnly, sameSiteMode); var cookieSettings = new CookieSettingsBuilder() .Name(cookieName) .HttpOnly(httpOnly) .SecurePreference(secureOnly) .SameSiteMode(sameSiteMode) .Build(); Assert.Equal(expectedCookieSettings, cookieSettings); }
public async Task <OneOf <ModelWithErrors <Command>, Success> > Handle(Command request, CancellationToken cancellationToken) { var validator = new CommandValidator(); var validationResult = await validator.ValidateAsync(request); if (!validationResult.IsValid) { return(new ModelWithErrors <Command>(request, validationResult)); } var preferences = new CookieSettings() { AllowAnalyticsCookies = request.AllowAnalyticsCookies.Value }; _cookiePreferencesProvider.SetPreferencesForCurrentUser(preferences); return(new Success()); }
public void CookieController_CookieConsent_Cookies_Rejected() { // Arrange var controllerBuilder = new ControllerBuilder <CookieController>(); var controller = controllerBuilder .Build(); var cookieConsent = new CookieConsent { AdditionalCookies = "reject" }; var expectedCookieSettings = new CookieSettings { GoogleAnalyticsGpg = false, GoogleAnalyticsGovUk = false, RememberSettings = false }; // Act controller.CookieConsent(cookieConsent); // Assert controller.AssertCookieAdded("cookie_settings", JsonConvert.SerializeObject(expectedCookieSettings)); controller.AssertCookieAdded("seen_cookie_message", "{\"Version\":1}"); }
protected void Application_BeginRequest(Object sender, EventArgs e) { string CountryCodeInUrl = "", redirectUrl = ""; var countryCode = CookieSettings.ReadCookie(); if (countryCode == "") { countryCode = "gb"; } if (System.Web.HttpContext.Current.Request.RawUrl.Length >= 2) { CountryCodeInUrl = System.Web.HttpContext.Current.Request.RawUrl.Substring(1, 2); } if (countryCode != CountryCodeInUrl) { if (System.Web.HttpContext.Current.Request.RawUrl.Length >= 2) { if (System.Web.HttpContext.Current.Request.RawUrl.Substring(1, 2) != "") { countryCode = System.Web.HttpContext.Current.Request.RawUrl.Substring(1, 2); } } if (!System.Web.HttpContext.Current.Request.RawUrl.Contains(countryCode)) { redirectUrl = string.Format("/{0}{1}", countryCode, System.Web.HttpContext.Current.Request.RawUrl); } else { redirectUrl = System.Web.HttpContext.Current.Request.RawUrl; } CookieSettings.SaveCookie(countryCode); System.Web.HttpContext.Current.Response.RedirectPermanent(redirectUrl); } }
public async Task Invoke(HttpContext context) { string CountryCodeInUrl = "", redirectUrl = ""; var countryCode = CookieSettings.ReadCookie(); if (countryCode == "") { countryCode = "gb"; } if (context.Request.Path.Value.Length >= 2) { CountryCodeInUrl = context.Request.Path.Value.Substring(1, 2); } if (countryCode != CountryCodeInUrl) { if (context.Request.Path.Value.Length >= 2) { if (context.Request.Path.Value.Substring(1, 2) != "") { countryCode = context.Request.Path.Value.Substring(1, 2); } } if (!context.Request.Path.Value.Contains(countryCode)) { redirectUrl = string.Format("/{0}{1}", countryCode, context.Request.Path.Value); } else { redirectUrl = context.Request.Path.Value; } CookieSettings.SaveCookie(countryCode); context.Response.Redirect(redirectUrl, true); } await _next.Invoke(context); }
public void SetUp() { theSettings = new CookieSettings(); }
public Cookie(CookieSettings settings, string value, DateTime expiration) { Settings = settings; Value = value; Expiration = expiration; }
public CompositionRootBuilder CookieSettings(CookieSettings cookieSettings) => ShallowClone(cookieSettings: cookieSettings);
public void SetPreferencesForCurrentUser(CookieSettings preferences) => _settings = preferences;
public void Reset() => _settings = null;