Esempio n. 1
0
        public async Task <IActionResult> AddClaimAsync(string subject, [FromBody] ClaimValue model)
        {
            var meta = await GetMetadataAsync();

            if (!meta.UserMetadata.SupportsClaims)
            {
                return(MethodNotAllowed());
            }

            if (IsNullOrWhiteSpace(subject))
            {
                ModelState["subject.String"].Errors.Clear();
                ModelState.AddModelError("", Messages.SubjectRequired);
            }

            if (model == null)
            {
                ModelState.AddModelError("", Messages.ClaimDataRequired);
            }

            if (ModelState.IsValid)
            {
                // ReSharper disable once PossibleNullReferenceException
                var result = await service.AddUserClaimAsync(subject, model.Type, model.Value);

                if (result.IsSuccess)
                {
                    return(NoContent());
                }

                ModelState.AddErrors(result);
            }

            return(BadRequest(ModelState.ToError()));
        }
Esempio n. 2
0
        public async Task <IHttpActionResult> AddClaimAsync(string subject, ClaimValue model)
        {
            var meta = await GetMetadataAsync();

            if (!meta.UserMetadata.SupportsClaims)
            {
                return(MethodNotAllowed());
            }

            if (String.IsNullOrWhiteSpace(subject))
            {
                ModelState["subject.String"].Errors.Clear();
                ModelState.AddModelError("", Messages.SubjectRequired);
            }

            if (model == null)
            {
                ModelState.AddModelError("", Messages.ClaimDataRequired);
            }

            if (ModelState.IsValid)
            {
                var result = await this.idmService.AddUserClaimAsync(subject, model.Type, model.Value);

                if (result.IsSuccess)
                {
                    return(NoContent());
                }

                ModelState.AddErrors(result);
            }

            return(BadRequest(ModelState.ToError()));
        }
Esempio n. 3
0
        public async Task <IActionResult> Edit(Guid id, [Bind("Id,Name")] ClaimValue claimValue)
        {
            if (id != claimValue.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(claimValue);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ClaimValueExists(claimValue.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(claimValue));
        }
 /// <summary>
 /// Add a global claim to send to client
 /// </summary>
 /// <param name="claim">Claim to send</param>
 public void AddGlobalClaim(ClaimValue claim)
 {
     if (claim == null)
     {
         return;
     }
     _globalClaimValues.AddOrUpdate(claim.Uri, claim, (s, value) => value);
 }
Esempio n. 5
0
 public QueryBuilder WithContextClaim(ClaimValue claim)
 {
     if (_contextData == null)
     {
         _contextData = new ContextData();
     }
     _contextData.ClaimValues.Add(claim);
     return(this);
 }
        /// <summary>
        /// Remove global claim from client
        /// </summary>
        /// <param name="claim">Claim to remove</param>
        public void RemoveGlobalClaim(ClaimValue claim)
        {
            if (claim == null)
            {
                return;
            }
            ClaimValue removed;

            _globalClaimValues.TryRemove(claim.Uri, out removed);
        }
Esempio n. 7
0
        public async Task <IActionResult> Create([Bind("Id,Name")] ClaimValue claimValue)
        {
            if (ModelState.IsValid)
            {
                claimValue.Id = Guid.NewGuid();
                _context.Add(claimValue);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(claimValue));
        }
        public virtual int _GetUniqueIdentifier()
        {
            var hashCode = 399326290;

            hashCode = hashCode * -1521134295 + (Id?.GetHashCode() ?? 0);
            hashCode = hashCode * -1521134295 + (ClaimType?.GetHashCode() ?? 0);
            hashCode = hashCode * -1521134295 + (ClaimValue?.GetHashCode() ?? 0);
            hashCode = hashCode * -1521134295 + (ClaimValueType?.GetHashCode() ?? 0);
            hashCode = hashCode * -1521134295 + (Issuer?.GetHashCode() ?? 0);
            hashCode = hashCode * -1521134295 + (OriginalIssuer?.GetHashCode() ?? 0);
            return(hashCode);
        }
Esempio n. 9
0
        public override bool Equals(object obj)
        {
            if (obj == null || !(obj is ApplicationRoleClaim))
            {
                return(false);
            }
            if (string.IsNullOrEmpty(ClaimType) || string.IsNullOrEmpty(ClaimValue))
            {
                return(false);
            }

            return(ClaimType.Equals((obj as ApplicationRoleClaim).ClaimType) &&
                   ClaimValue.Equals((obj as ApplicationRoleClaim).ClaimValue));
        }
Esempio n. 10
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);
        }
 public void AddClaim(ClaimValue claim)
 {
     _claims.Add(claim);
     ApiClientFactory.Instance.AddGlobalClaim(claim);
 }
Esempio n. 12
0
        public List <string> ImportClaimsData(string claimsFilename, string postcodesFilename)
        {
            var errors = new List <string>();

            try
            {
                var claims        = new List <Claim>();
                var values        = new List <ClaimValue>();
                var claimsPath    = Path.Combine(_environment.ContentRootPath, "ImportData", claimsFilename);
                var postcodesPath = Path.Combine(_environment.ContentRootPath, "ImportData", postcodesFilename);
                using (TextReader claimsReader = File.OpenText(claimsPath))
                    using (TextReader postcodeReader = File.OpenText(postcodesPath))
                    {
                        var claimsCsv       = new CsvReader(claimsReader);
                        var postcodeCsv     = new CsvReader(postcodeReader);
                        var claimRecords    = claimsCsv.GetRecords <ImportClaim>().ToList();
                        var postcodeRecords = postcodeCsv.GetRecords <ImportPostcode>().ToList();

                        //now we go through and add the claims into the database
                        foreach (var rec in claimRecords)
                        {
                            if (!IsClaimValid(rec))
                            {
                                errors.Add($"ERROR: claim is not a valid row {claimRecords.IndexOf(rec)}");
                                continue;
                            }
                            var cl = new Claim
                            {
                                SourceId  = GetOrAddSource(rec.Source),
                                Heading   = rec.Heading,
                                ClaimText = rec.Text,
                                Industry  = (Industry)rec.Industry,
                                Type      = (Dto.Models.Type)rec.Type,
                                ImagePath = rec.Imagepath
                            };

                            if (string.IsNullOrEmpty(cl.ClaimText))
                            {
                                cl.ClaimText = null;
                            }

                            if (string.IsNullOrEmpty(cl.ImagePath))
                            {
                                cl.ImagePath = null;
                            }

                            claims.Add(cl);
                        }

                        _repository.SaveClaims(claims);

                        // NOTE: This is different in the other versions!!!
                        foreach (var rec in postcodeRecords)
                        {
                            var threshold = 0;
                            var headings  = typeof(ImportPostcode).GetTypeInfo();
                            foreach (var heading in headings.DeclaredProperties)
                            {
                                try
                                {
                                    var loweredHeading = heading.Name.ToLower();
                                    if (loweredHeading.Contains("threshold"))
                                    {
                                        PropertyInfo pinfo = rec.GetType().GetProperty(heading.Name);
                                        var          val   = (string)pinfo.GetValue(rec, null);
                                        if (val == "x")
                                        {
                                            switch (loweredHeading)
                                            {
                                            case "threshold1":
                                                threshold = 1;
                                                break;

                                            case "threshold2":
                                                threshold = 2;
                                                break;

                                            case "threshold3":
                                                threshold = 3;
                                                break;

                                            case "threshold4":
                                                threshold = 4;
                                                break;
                                            }
                                        }
                                    }
                                    else if (loweredHeading.Contains("cardsinforce"))
                                    {
                                        var claim =
                                            claims.FirstOrDefault(
                                                x => x.Heading.Replace(" ", "").ToLower() == "cardsinforce");
                                        if (claim != null)
                                        {
                                            var order =
                                                Convert.ToInt32(
                                                    loweredHeading.Substring(loweredHeading.ToCharArray().Length - 1));

                                            var claimValue = new ClaimValue()
                                            {
                                                Postcode  = rec.Postcode,
                                                Value     = GetClaimValue(rec, heading.Name),
                                                ClaimId   = claim.Id,
                                                Order     = order,
                                                Threshold = threshold
                                            };

                                            values.Add(claimValue);
                                        }
                                    }
                                    else
                                    {
                                        var claim =
                                            claims.FirstOrDefault(
                                                x => x.Heading.Replace(" ", "").ToLower() == loweredHeading);
                                        if (claim != null)
                                        {
                                            var claimValue = new ClaimValue()
                                            {
                                                Postcode  = rec.Postcode,
                                                Value     = GetClaimValue(rec, heading.Name),
                                                ClaimId   = claim.Id,
                                                Order     = 0,
                                                Threshold = threshold
                                            };

                                            values.Add(claimValue);
                                        }
                                    }
                                }
                                catch (Exception ex)
                                {
                                    errors.Add(
                                        $"Error trying to import heading {heading.Name} for postcode {rec.Postcode}: {ex.Message}");
                                }
                            }
                        }
                        // hopefully there is still enough memory left ;)
                        _repository.SaveClaimValues(values);
                    }
            }
            catch (Exception ex)
            {
                errors.Add("FATAL ERROR:" + ex.Message);
            }
            return(errors);
        }