public override async Task <IdentityResult> UpdateAsync(Role role) { //TODO: Unstable method work, sometimes throws EF already being tracked exception //https://github.com/aspnet/Identity/issues/1807 var result = await base.UpdateAsync(role); if (result.Succeeded && role.Permissions != null) { var sourcePermissionClaims = role.Permissions.Select(x => new Claim(PlatformConstants.Security.Claims.PermissionClaimType, x.Name)).ToList(); var targetPermissionClaims = (await GetClaimsAsync(role)).Where(x => x.Type == PlatformConstants.Security.Claims.PermissionClaimType).ToList(); var comparer = AnonymousComparer.Create((Claim x) => x.Value); //Add foreach (var sourceClaim in sourcePermissionClaims.Except(targetPermissionClaims, comparer)) { await base.AddClaimAsync(role, sourceClaim); } //Remove foreach (var targetClaim in targetPermissionClaims.Except(sourcePermissionClaims, comparer).ToArray()) { await base.RemoveClaimAsync(role, targetClaim); } SecurityCacheRegion.ExpireRegion(); } return(result); }
public override async Task <IdentityResult> DeleteAsync(Role role) { var result = await base.DeleteAsync(role); if (result.Succeeded) { SecurityCacheRegion.ExpireRegion(); } return(result); }
public override async Task <IdentityResult> CreateAsync(Role role) { var result = await base.CreateAsync(role); if (result.Succeeded && !role.Permissions.IsNullOrEmpty()) { var permissionRoleClaims = role.Permissions.Select(x => new Claim(PlatformConstants.Security.Claims.PermissionClaimType, x.Name)); foreach (var claim in permissionRoleClaims) { await base.AddClaimAsync(role, claim); } SecurityCacheRegion.ExpireRegion(); } return(result); }
public override async Task <IdentityResult> CreateAsync(Role role) { var result = await base.CreateAsync(role); if (result.Succeeded && !role.Permissions.IsNullOrEmpty()) { var existRole = string.IsNullOrEmpty(role.Id) ? await base.FindByNameAsync(role.Name) : await base.FindByIdAsync(role.Id); var permissionRoleClaims = role.Permissions.Select(x => new Claim(PlatformConstants.Security.Claims.PermissionClaimType, x.Name)); foreach (var claim in permissionRoleClaims) { //Need to use an existing tracked by EF entity in order to add permissions for role await base.AddClaimAsync(existRole, claim); } SecurityCacheRegion.ExpireRegion(); } return(result); }
public override async Task <IdentityResult> UpdateAsync(Role updateRole) { if (updateRole == null) { throw new ArgumentNullException(nameof(updateRole)); } Role existRole = null; if (!string.IsNullOrEmpty(updateRole.Id)) { existRole = await base.FindByIdAsync(updateRole.Id); } if (existRole == null) { existRole = await base.FindByNameAsync(updateRole.Name); } if (existRole != null) { //Need to path exists tracked by EF entity due to already being tracked exception //https://github.com/aspnet/Identity/issues/1807 updateRole.Patch(existRole); } var result = await base.UpdateAsync(existRole); if (result.Succeeded && updateRole.Permissions != null) { var sourcePermissionClaims = updateRole.Permissions.Select(x => x.ToClaim(_jsonOptions.SerializerSettings)).ToList(); var targetPermissionClaims = (await GetClaimsAsync(existRole)).Where(x => x.Type == PlatformConstants.Security.Claims.PermissionClaimType).ToList(); var comparer = AnonymousComparer.Create((Claim x) => x.Value); //Add foreach (var sourceClaim in sourcePermissionClaims.Except(targetPermissionClaims, comparer)) { await base.AddClaimAsync(existRole, sourceClaim); } //Remove foreach (var targetClaim in targetPermissionClaims.Except(sourcePermissionClaims, comparer).ToArray()) { await base.RemoveClaimAsync(existRole, targetClaim); } SecurityCacheRegion.ExpireRegion(); } return(result); }
public ActionResult ResetCache() { //TODO: Replace to some other (maybe with using reflection) ThemeEngineCacheRegion.ExpireRegion(); CartCacheRegion.ExpireRegion(); CatalogCacheRegion.ExpireRegion(); ContentBlobCacheRegion.ExpireRegion(); CustomerCacheRegion.ExpireRegion(); MarketingCacheRegion.ExpireRegion(); PricingCacheRegion.ExpireRegion(); QuoteCacheRegion.ExpireRegion(); RecommendationsCacheRegion.ExpireRegion(); StaticContentCacheRegion.ExpireRegion(); StoreCacheRegion.ExpireRegion(); TaxCacheRegion.ExpireRegion(); SubscriptionCacheRegion.ExpireRegion(); SecurityCacheRegion.ExpireRegion(); return(StoreFrontRedirect("~/")); }