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)); }
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); }
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() })); }
public string TypeOfClaim() { switch (ClaimType.ToString().ToLower()[0]) { case 'c': return("Car"); case 'h': return("Home"); case 't': return("Theft"); default: return("ERROR"); } }
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); }
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); } } }
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); }
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)); }
public RequiresPermissionsAttribute(ClaimType claimType, string claimValue = "") : base(typeof(ClaimRequirementFilter)) { Arguments = new object[] { new Claim(claimType.ToString(), claimValue) }; }
public AuthorizeUserAttribute(string permission, ClaimType type) : base(typeof(AuthorizeRoleFilter)) { var typeStr = type.ToString(); Arguments = new object[] { new Claim(typeStr, permission) }; }