예제 #1
0
        private static void ClaimDemand(ClaimType claim, SecureResource resource)
        {
            AuthorizationContext authContext = ServiceSecurityContext.Current.AuthorizationContext;

            ClaimSet issuerClaimSet = null;

            foreach (ClaimSet cs in authContext.ClaimSets)
            {
                if (cs.Issuer == _issuer)
                {
                    issuerClaimSet = cs;
                    break;
                }
            }

            if (issuerClaimSet == null)
            {
                throw new PermissionException(string.Format("No claims for issuer {0} were provided.",
                                                            _issuer[0].Resource));
            }

            var c = new Claim(ClaimType.All.ToString(), SecureResource.All, Rights.PossessProperty);

            if (issuerClaimSet.ContainsClaim(c)) // if administrator
            {
                return;
            }

            if (claim != ClaimType.All)
            {
                c = new Claim(ClaimType.All.ToString(), resource, Rights.PossessProperty);
                if (issuerClaimSet.ContainsClaim(c))
                {
                    return;
                }
            }

            if (resource != SecureResource.All)
            {
                c = new Claim(claim.ToString(), SecureResource.All, Rights.PossessProperty);
                if (issuerClaimSet.ContainsClaim(c))
                {
                    return;
                }
            }

            c = new Claim(claim.ToString(), resource, Rights.PossessProperty);
            if (issuerClaimSet.ContainsClaim(c))
            {
                return;
            }

            throw new PermissionException(string.Format("Claim {0} for resource {1} is not satisfied.",
                                                        claim, resource));
        }
예제 #2
0
        private static Claim GetClaim(ClaimType claimType, IPrincipal user)
        {
            var identity = (ClaimsIdentity)user.Identity;
            IEnumerable <Claim> claims = identity.Claims;
            var identityClaim          = claims.FirstOrDefault(n => n.Type == claimType.ToString());

            return(identityClaim);
        }
예제 #3
0
 public string ToConsoleString()
 {
     return(string.Join("\t",
                        new string[]
     {
         ClaimID.ToString(),
         ClaimType.ToString(),
         Description.PadRight(30),
         ClaimAmount.ToString("C").PadLeft(10),
         DateOfIncident.ToShortDateString(),
         DateOfClaim.ToShortDateString(),
         IsValid.ToString()
     }));
 }
예제 #4
0
        public string TypeOfClaim()
        {
            switch (ClaimType.ToString().ToLower()[0])
            {
            case 'c':
                return("Car");

            case 'h':
                return("Home");

            case 't':
                return("Theft");

            default:
                return("ERROR");
            }
        }
예제 #5
0
        private static string GetClaimValue(JsonWebSecurityToken token, ClaimType claimType)
        {
            if (token == null)
            {
                throw new ArgumentNullException("token");
            }

            foreach (JsonWebTokenClaim claim in token.Claims)
            {
                if (StringComparer.Ordinal.Equals(claim.ClaimType, claimType.ToString()))
                {
                    return(claim.Value);
                }
            }

            return(null);
        }
예제 #6
0
        private async Task SetClaim(IList <Claim> claims, User user, bool isEnabled, ClaimType claimtype)
        {
            var claimsIdentity = GetCurrentClaimsIdentity();
            var claimType      = claimtype.ToString();
            var claim          = claimsIdentity.Claims.FirstOrDefault(x => x.Type == claimType);


            if (isEnabled && claim == null)
            {
                claims.Add(new Claim(claimType, "Enabled"));
            }
            else
            {
                if (claim != null && !isEnabled)
                {
                    await _userManager.RemoveClaimAsync(user, claim);

                    claimsIdentity.RemoveClaim(claim);
                }
            }
        }
예제 #7
0
        public Dictionary <string, FieldInfo> getModelInfo()
        {
            Dictionary <string, FieldInfo> dic = new Dictionary <string, FieldInfo>();

            // id 自动增长
            //if (Id != 0)
            //dic.Add("Id", new FieldInfo(SqlDbType.Int, Id.ToString(), true));
            if (UserId != null)
            {
                dic.Add("UserId", new FieldInfo(SqlDbType.NVarChar, UserId.ToString()));
            }
            if (ClaimType != null)
            {
                dic.Add("ClaimType", new FieldInfo(SqlDbType.NVarChar, ClaimType.ToString()));
            }
            if (ClaimValue != null)
            {
                dic.Add("ClaimValue", new FieldInfo(SqlDbType.NVarChar, ClaimValue.ToString()));
            }

            return(dic);
        }
예제 #8
0
파일: ClaimsPolicy.cs 프로젝트: jcde/WCF
        private static void ClaimDemand(ClaimType claim, SecureResource resource)
        {
            AuthorizationContext authContext = ServiceSecurityContext.Current.AuthorizationContext;

            ClaimSet issuerClaimSet = null;
            foreach (ClaimSet cs in authContext.ClaimSets)
            {
                if (cs.Issuer == _issuer)
                {
                    issuerClaimSet = cs;
                    break;
                }
            }

            if (issuerClaimSet == null)
                throw new PermissionException(string.Format("No claims for issuer {0} were provided.",
                                                            _issuer[0].Resource));

            var c = new Claim(ClaimType.All.ToString(), SecureResource.All, Rights.PossessProperty);
            if (issuerClaimSet.ContainsClaim(c)) // if administrator
                return;

            if (claim != ClaimType.All)
            {
                c = new Claim(ClaimType.All.ToString(), resource, Rights.PossessProperty);
                if (issuerClaimSet.ContainsClaim(c))
                    return;
            }

            if (resource != SecureResource.All)
            {
                c = new Claim(claim.ToString(), SecureResource.All, Rights.PossessProperty);
                if (issuerClaimSet.ContainsClaim(c))
                    return;
            }

            c = new Claim(claim.ToString(), resource, Rights.PossessProperty);
            if (issuerClaimSet.ContainsClaim(c))
                return;

            throw new PermissionException(string.Format("Claim {0} for resource {1} is not satisfied.",
                                                        claim, resource));
        }
예제 #9
0
 public RequiresPermissionsAttribute(ClaimType claimType, string claimValue = "") : base(typeof(ClaimRequirementFilter))
 {
     Arguments = new object[] { new Claim(claimType.ToString(), claimValue) };
 }
예제 #10
0
        public AuthorizeUserAttribute(string permission, ClaimType type) : base(typeof(AuthorizeRoleFilter))
        {
            var typeStr = type.ToString();

            Arguments = new object[] { new Claim(typeStr, permission) };
        }