Ejemplo n.º 1
0
        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.");
            }
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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();
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        /// <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;
        }
Ejemplo n.º 6
0
        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),
            }));
        }
Ejemplo n.º 7
0
        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();
        }
Ejemplo n.º 8
0
 public HasAccess(ClaimTypes claimType) : base()
 {
     _claimType = claimType;
 }
Ejemplo n.º 9
0
 public RestrictAttribute(ClaimTypes ct, ClaimValues cv)
 {
     _claimType   = ct;
     _claimValues = cv;
 }
Ejemplo n.º 10
0
        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());
        }
Ejemplo n.º 11
0
 public BypassAttribute(ClaimTypes ct, ClaimValues cv, bool any)
 {
     ClaimType   = ct;
     ClaimValues = cv;
     Any         = any;
 }
Ejemplo n.º 12
0
 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());
 }