示例#1
0
        public string UpdateClaim(string identity, IIdentityClaim claim)
        {
            using (var context = _contextFactory.Create(_configuration.PriusRepositoryName))
            {
                IdentityClaimRecord existingClaim;
                using (var command = _commandFactory.CreateStoredProcedure("sp_GetIdentityClaims"))
                {
                    command.AddParameter("identity", identity);
                    using (var claims = context.ExecuteEnumerable <IdentityClaimRecord>(command))
                    {
                        existingClaim = claims.FirstOrDefault(c => string.Equals(c.Name, claim.Name, StringComparison.OrdinalIgnoreCase));
                    }
                }

                if (existingClaim != null)
                {
                    try
                    {
                        using (var command = _commandFactory.CreateStoredProcedure("sp_DeleteClaim"))
                        {
                            command.AddParameter("who_identity", identity);
                            command.AddParameter("reason", "Update claim");
                            command.AddParameter("claim_id", existingClaim.ClaimId);
                            context.ExecuteNonQuery(command);
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new IdentityStoreException("Failed to delete '" + existingClaim.Name + "' claim from identity " + existingClaim.Identity, ex);
                    }
                }

                try
                {
                    using (var command = _commandFactory.CreateStoredProcedure("sp_AddClaim"))
                    {
                        command.AddParameter("who_identity", identity);
                        command.AddParameter("reason", "Update claim");
                        command.AddParameter("identity", identity);
                        command.AddParameter("name", claim.Name);
                        command.AddParameter("value", claim.Value);
                        command.AddParameter("status", (int)claim.Status);
                        context.ExecuteNonQuery(command);
                    }
                }
                catch (Exception ex)
                {
                    throw new IdentityStoreException("Failed to add '" + claim.Name + "' claim to identity " + identity, ex);
                }
            }
            return(identity);
        }
        public string UpdateClaim(string identity, IIdentityClaim claim)
        {
            TestIdentity testIdentity;

            if (!_identities.TryGetValue(identity, out testIdentity))
            {
                return(identity);
            }

            var existingClaim = testIdentity.Claims.FirstOrDefault(c => c.Name == claim.Name);

            if (existingClaim == null)
            {
                testIdentity.Claims.Add(new IdentityClaim(claim));
            }
            else
            {
                existingClaim.Value  = claim.Value;
                existingClaim.Status = claim.Status;
            }

            return(identity);
        }
示例#3
0
 /// <summary>
 /// Copy constructor
 /// </summary>
 public IdentityClaim(IIdentityClaim other)
 {
     Name   = other.Name;
     Value  = other.Value;
     Status = other.Status;
 }