public async void SetValue(CookieName cookieName, KeyName[] keyName, string[] value) { if (keyName.Length != value.Length) { return; } var principal = _user as ClaimsPrincipal; var cp = principal.Identities.First(i => i.AuthenticationType == ((CookieName)cookieName).ToString()); for (int i = 0; i < keyName.Length; i++) { if (cp.FindFirst(((KeyName)keyName[i]).ToString()) != null) { cp.RemoveClaim(cp.FindFirst(((KeyName)keyName[i]).ToString())); cp.AddClaim(new Claim(((KeyName)keyName[i]).ToString(), value[i])); } } await _httpContext.SignOutAsync(CookieName.UserProfilCookie.ToString()); await _httpContext.SignInAsync(CookieName.UserProfilCookie.ToString(), new ClaimsPrincipal(cp), new AuthenticationProperties { IsPersistent = bool.Parse(cp.FindFirst(KeyName.IsPersistent.ToString()).Value), AllowRefresh = true }); }
public Authentication(ElmcityUtils.Authentication.Mode mode, ElmcityUtils.Authentication.TrustedTable trusted_table, ElmcityUtils.Authentication.TrustedField trusted_field, ElmcityUtils.Authentication.CookieName cookie_name) { this.mode = mode; this.trusted_field = trusted_field; this.trusted_table = trusted_table; this.cookie_name = cookie_name; }
public SessionLoader( ISessionStorage sessionStorage, CookieName cookieName) { _sessionStorage = sessionStorage; _cookieName = cookieName; }
public string GetValue(CookieName cookieName, KeyName keyName) { var principal = _user as ClaimsPrincipal; var cp = principal.Identities.First(i => i.AuthenticationType == ((CookieName)cookieName).ToString()); return(cp.FindFirst(((KeyName)keyName).ToString()).Value); }
/// <summary> /// Gets the hash code /// </summary> /// <returns>Hash code</returns> public override int GetHashCode() { unchecked // Overflow is fine, just wrap { var hashCode = 41; // Suitable nullity checks etc, of course :) if (FeatureName != null) { hashCode = hashCode * 59 + FeatureName.GetHashCode(); } if (FeatureDescription != null) { hashCode = hashCode * 59 + FeatureDescription.GetHashCode(); } if (ActivePercentage != null) { hashCode = hashCode * 59 + ActivePercentage.GetHashCode(); } if (CookieName != null) { hashCode = hashCode * 59 + CookieName.GetHashCode(); } if (CookieMaxAge != null) { hashCode = hashCode * 59 + CookieMaxAge.GetHashCode(); } return(hashCode); } }
public void ThrowsIfCookieNameIsInvalid(string invalidCookieName) { var cookieName = new CookieName(invalidCookieName); var builder = new CookieSettingsBuilder().Name(cookieName); Assert.Throws <InvalidOperationException>(() => { var unusedResult = builder.Build(); }); }
internal CookieSettings( CookieName name, bool httpOnly, CookieSecurePreference securePreference, CookieSameSiteMode sameSiteMode) { Name = name; HttpOnly = httpOnly; SecurePreference = securePreference; SameSiteMode = sameSiteMode; }
public static void Set <T>(CookieName name, T data, int day = 30) { HttpCookie cookie = new HttpCookie(name.ToString()); var json = _Json.ModelToJson(data); cookie.Value = HttpContext.Current.Server.UrlEncode(json); cookie.Expires = DateTime.Now.AddDays(day); HttpContext.Current.Request.Cookies.Add(cookie); }
public static T Get <T>(CookieName name) { var cookie = HttpContext.Current.Request.Cookies[name.ToString()]; var value = HttpContext.Current.Server.UrlDecode(cookie?.Value); if (!string.IsNullOrEmpty(value)) { var data = _Json.JsonToModel <T>(value); return(data); } return(default(T)); }
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); }
internal void SetCookie() { if (!URI.IsNullOrEmpty() && Cookies != null && Cookies.Count > 0) { Cookies.ForDicEach((key, val) => { OptionBuilder.Cookies.Add(new Uri(URI), new Cookie(key, val)); }); } if (!URI.IsNullOrEmpty() && CookieColl != null && CookieColl.Count > 0) { OptionBuilder.Cookies.Add(new Uri(URI), CookieColl); } if (!CookieName.IsNullOrEmpty() && !CookieValue.IsNullOrEmpty() && !CookiePath.IsNullOrEmpty()) { OptionBuilder.Cookies.Add(new Cookie(CookieName, CookieValue, CookiePath, CookieDomain)); } }
/// <summary> /// Init event handler. /// </summary> protected override void OnInit(EventArgs e) { combinationSelector.UniSelector.UseUniSelectorAutocomplete = false; currentUser = MembershipContext.AuthenticatedUser; // Set the selected combination (from cookie by default) MVTestInfo mvTestInfo = MVTestInfoProvider.GetRunningTest(DocumentContext.CurrentAliasPath, SiteContext.CurrentSiteID, DocumentContext.CurrentDocumentCulture.CultureCode); // Get the cookie name if (mvTestInfo != null) { // Get a cookie name for the mvt test cookieTestName = CookieName.GetMVTCookieName(mvTestInfo.MVTestName); } else { // Get a template cookie name (used just in CMSDesk when no test is running) cookieTestName = CookieName.GetNoMVTCookieName(DocumentContext.CurrentDocument.GetUsedPageTemplateId()); } // Move cookies expiration to next 30 days HttpCookie cookieMVTTest = CookieHelper.GetExistingCookie(cookieTestName); if (cookieMVTTest != null) { CookieHelper.SetValue(cookieMVTTest.Name, cookieMVTTest.Value, cookieMVTTest.Path, DateTime.Now.AddDays(30), false); } base.OnInit(e); viewMode = PortalContext.ViewMode; // Check permissions if ((currentUser == null) || (!currentUser.IsAuthorizedPerResource("CMS.Design", "Design") && PortalContext.IsDesignMode(viewMode)) || (!currentUser.IsAuthorizedPerResource("CMS.MVTest", "Read"))) { stopProcessing = true; } }
internal CookieContainer SetCookie(CookieContainer Container) { return(SyncStatic.TryCatch(() => { if (Container == null) { Container = new CookieContainer(); } if (InstanceCookie) { return Container; } else { if (!URI.IsNullOrEmpty() && Cookies != null && Cookies.Count > 0) { Cookies.ForDicEach((key, val) => { Container.Add(new Uri(URI), new Cookie(key, val)); }); return Container; } else if (!URI.IsNullOrEmpty() && CookieColl != null && CookieColl.Count > 0) { Container.Add(new Uri(URI), CookieColl); return Container; } else if (!CookieName.IsNullOrEmpty() && !CookieValue.IsNullOrEmpty() && !CookiePath.IsNullOrEmpty()) { Container.Add(new Cookie(CookieName, CookieValue, CookiePath, CookieDomain)); return Container; } else { throw new Exception("Cookie配置不满足!"); } } }, ex => throw ex)); }
/// <summary> /// Returns true if ComAdobeGraniteFragsImplRandomFeatureProperties instances are equal /// </summary> /// <param name="other">Instance of ComAdobeGraniteFragsImplRandomFeatureProperties to be compared</param> /// <returns>Boolean</returns> public bool Equals(ComAdobeGraniteFragsImplRandomFeatureProperties other) { if (other is null) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return (( FeatureName == other.FeatureName || FeatureName != null && FeatureName.Equals(other.FeatureName) ) && ( FeatureDescription == other.FeatureDescription || FeatureDescription != null && FeatureDescription.Equals(other.FeatureDescription) ) && ( ActivePercentage == other.ActivePercentage || ActivePercentage != null && ActivePercentage.Equals(other.ActivePercentage) ) && ( CookieName == other.CookieName || CookieName != null && CookieName.Equals(other.CookieName) ) && ( CookieMaxAge == other.CookieMaxAge || CookieMaxAge != null && CookieMaxAge.Equals(other.CookieMaxAge) )); }
public UserInfo(CookieName cookieName) { userCookieName = HttpUtility.UrlEncode(cookieName.ToString()); }
public static void Remove(CookieName name) { HttpCookie cookie = new HttpCookie(name.ToString()); cookie.Expires = DateTime.Now.AddDays(-1); }
public Boolean AuthenticatedThisWay(IPrincipal p) { return(CookieName.Equals(p.Identity.AuthenticationType)); }
public string?GetCookie(CookieName name) { _httpContext.Request.Cookies.TryGetValue(name.Value, out var value); return(value); }
public bool HasCookie(CookieName name) { return(_httpContext.Request.Cookies.ContainsKey(name.Value)); }