private static void UpdateClaimsPrincipal(SecurityAccess access) { var accessClaim = ClaimsPrincipal.Current.Identities.First().Claims.SingleOrDefault(x => x.Type == "SecurityAccess"); if (accessClaim != null) ClaimsPrincipal.Current.Identities.First().RemoveClaim(accessClaim); ClaimsPrincipal.Current.Identities.First().AddClaim(new Claim("SecurityAccess", JsonConvert.SerializeObject(access))); }
private static void UpdateClaimsPrincipal(SecurityAccess access) { var accessClaim = ClaimsPrincipal.Current.Identities.First().Claims.SingleOrDefault(x => x.Type == "SecurityAccess"); if (accessClaim != null) { ClaimsPrincipal.Current.Identities.First().RemoveClaim(accessClaim); } ClaimsPrincipal.Current.Identities.First().AddClaim(new Claim("SecurityAccess", JsonConvert.SerializeObject(access))); }
public static bool HasAccess(this SecurityAccess self, string project, string application, string cluster, Access access) { if (self.Projects.Select(x => x.Name).Contains(project)) { if (self.Projects.SingleOrDefault(x => x.Name == project).Applications.Select(x => x.Name).Contains(application)) { if (cluster == "Defaults") { return(self.Projects.SingleOrDefault(x => x.Name == project).Applications.SingleOrDefault(x => x.Name == application).Access.HasAccess(access)); } else if (self.Projects.SingleOrDefault(x => x.Name == project).Applications.SingleOrDefault(x => x.Name == application).Clusters.Select(x => x.Name).Contains(cluster)) { var cl = self.Projects.SingleOrDefault(x => x.Name == project).Applications.SingleOrDefault(x => x.Name == application).Clusters.SingleOrDefault(x => x.Name == cluster); return(cl.Access.HasAccess(access)); } } } return(false); }
private SecurityAccess GetSecurityAccess() { var securityAccessClaim = user.Claims.SingleOrDefault(x => x.Type == "SecurityAccess"); SecurityAccess security; if (securityAccessClaim == null || string.IsNullOrWhiteSpace(securityAccessClaim.Value)) { security = new SecurityAccess(); } else { security = JsonConvert.DeserializeObject <SecurityAccess>(securityAccessClaim.Value); } if (security == null) { security = new SecurityAccess(); } return(security); }
private SecurityAccess GetSecurityAccess() { var securityAccessClaim = user.Claims.SingleOrDefault(x => x.Type == "SecurityAccess"); SecurityAccess security; if (securityAccessClaim == null || string.IsNullOrWhiteSpace(securityAccessClaim.Value)) security = new SecurityAccess(); else security = JsonConvert.DeserializeObject<SecurityAccess>(securityAccessClaim.Value); if (security == null) security = new SecurityAccess(); return security; }