public static void VerifyUserPermission(Fiasm.Data.EntityModels.User user, ClaimTypes claimType) { if (user == null) { throw new ArgumentNullException(nameof(user)); } if (!user.UserClaims.Any(c => c.Claim.ClaimType == claimType.ToString())) { throw new InvalidCredentialException("You do not have permission."); } }
public virtual void RemoveClaim(Claim claim) { if (claim == null) { throw new ArgumentNullException(nameof(claim)); } var index = ClaimTypes.IndexOf(claim.Type); ClaimTypes.Remove(claim.Type); ClaimValues.RemoveAt(index); }
private void SeedClaim(IDatabaseContext context) { var existingClaims = context.Set <ClaimType>().ToList(); var claimTypes = ClaimTypes.GetClaimTypes(); foreach (var claimType in claimTypes) { if (!existingClaims.Any(x => x.Name == claimType.Key)) { var claimTypeEntity = new ClaimType(1, claimType.Key, claimType.Value); context.Attach(claimTypeEntity).State = EntityState.Added; } } context.SaveChanges(); }
public IEnumerable <Claim> GetClaimset() { string[] types = ClaimTypes.Split(";", StringSplitOptions.RemoveEmptyEntries); string[] values = ClaimValues.Split(";", StringSplitOptions.RemoveEmptyEntries); if (types.Length != values.Length) { throw new IndexOutOfRangeException("Claim types and values length mismatch."); } List <Claim> claims = new List <Claim>(); for (int i = 0; i < types.Length; i++) { claims.Add(new Claim(types[i], values[i])); } return(claims); }
/// <summary> /// Creates a shallow copy of 'other'. /// </summary> /// <param name="other">The WSTrustTokenParameters to copy.</param> protected WSTrustTokenParameters(WSTrustTokenParameters other) : base(other) { foreach (var parameter in other.AdditionalRequestParameters) { AdditionalRequestParameters.Add(parameter); } CacheIssuedTokens = other.CacheIssuedTokens; foreach (var claimType in ClaimTypes) { ClaimTypes.Add(claimType); } _issuedTokenRenewalThresholdPercentage = other.IssuedTokenRenewalThresholdPercentage; KeySize = other.KeySize; _maxIssuedTokenCachingTime = other.MaxIssuedTokenCachingTime; _messageSecurityVersion = other.MessageSecurityVersion; }
public IActionResult GetToken([FromBody] AuthenticationViewModel authentication) { if (!ModelState.IsValid) { return(BadRequest("Invalid credentials.")); } if (authentication.User != "joe" || authentication.Password != "blow") { return(NotFound("Invalid credentials.")); } var user = new User() { Id = 1, Role = "Administrator" }; return(Ok(new { token_type = "bearer", access_token = TokenServices.CreateToken(ClaimTypes.CreateClaims(user)), expiration_date = DateTime.UtcNow.AddMinutes(TokenServices._expirationInMinute), })); }
public void ModifyClaim() { Console.Clear(); Console.Write("Please enter the Claim ID Number of the claim you wish to modify: "); int originalClaimID = GetSafeNumber(); ClaimTypes claimType = GetClaimType(); Console.Write("Description: "); string desc = Console.ReadLine(); Console.Write("Amount: $"); decimal amount = GetSafeDecimal(); Console.Write("Date of Incident (yyyy/mm/dd): "); DateTime dateOfIncident = GetSafeDate(); Console.Write("Date of Claim (yyyy/mm/dd): "); DateTime dateOfClaim = GetSafeDate(); Claim updatedClaim = new Claim(originalClaimID, claimType, desc, amount, dateOfIncident, dateOfClaim); Console.WriteLine(_repo.UpdateClaim(updatedClaim, originalClaimID) == true ? "Success" : "Failed, claim ID doesn't exist"); Console.ReadLine(); }
public HasAccess(ClaimTypes claimType) : base() { _claimType = claimType; }
public RestrictAttribute(ClaimTypes ct, ClaimValues cv) { _claimType = ct; _claimValues = cv; }
public async Task <IEnumerable <AssignmentGridModel> > GetAssignmentsGridInfo(int userId, ClaimTypes clientType) { List <Assignment> assignments; if (clientType == ClaimTypes.Student) { assignments = await _assignmentRepository.GetStudentAssignments(userId); } else { assignments = await _assignmentRepository.GetInstructorAssignments(userId); } return(assignments.Select(a => new AssignmentGridModel { AssignmentId = a.Id, CourseTitle = a.Course.Title, Description = a.Description, StartDate = a.StartDate, EndDate = a.EndDate, InstructorName = a.Instructor.FirstName + " " + a.Instructor.LastName + " " + a.Instructor.SecondName }).ToList()); }
public BypassAttribute(ClaimTypes ct, ClaimValues cv, bool any) { ClaimType = ct; ClaimValues = cv; Any = any; }
public BypassAttribute(ClaimTypes ct, ClaimValues cv) : this(ct, cv, false) { }
public virtual IList <Claim> GetClaims() { return(ClaimTypes.Select((t, i) => new Claim(t, ClaimValues[i])).ToList()); }