コード例 #1
0
ファイル: User.cs プロジェクト: Elders/Pandora.Server.Api
        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)));
        }
コード例 #2
0
ファイル: User.cs プロジェクト: Elders/Pandora.Server.Api
        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)));
        }
コード例 #3
0
ファイル: User.cs プロジェクト: Elders/Pandora.Server.Api
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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;
        }