コード例 #1
0
        async public Task RemoveIdentityResourceAsync(IdentityResourceModel identityResource)
        {
            var collection = GetIdentityResourceCollection();

            string id = identityResource.Name.IdentityNameToHexId(_cryptoService);

            await collection
            .DeleteOneAsync <IdentityResourceDocument>(d => d.Id == id);
        }
コード例 #2
0
        public void identity_resource_model()
        {
            var model  = NewIdentityResourceModel;
            var model2 = new IdentityResourceModel(model.ToIdentityResource());

            var model3 = NewIdentityResourceModel;

            model.ShouldBe(model2);
            model.ShouldNotBe(model3);
        }
        public IActionResult Delete(IdentityResourceModel model)
        {
            var identity = _configurationDbContext.IdentityResources
                           .FirstOrDefault(x => x.Id == model.Id);

            _configurationDbContext.IdentityResources.Remove(identity);
            _configurationDbContext.SaveChanges();

            return(RedirectToAction(nameof(Index)));
        }
コード例 #4
0
        public Task RemoveIdentityResourceAsync(IdentityResourceModel identityResource)
        {
            FileInfo fi = new FileInfo($"{ _rootPath }/{ identityResource.Name.NameToHexId(_cryptoService) }.identity");

            if (fi.Exists)
            {
                fi.Delete();
            }

            return(Task.CompletedTask);
        }
コード例 #5
0
        public Task AddIdentityResourceAsync(IdentityResourceModel identityResource)
        {
            if (_identityResources.ContainsKey(identityResource.Name))
            {
                throw new Exception($"Identity resource { identityResource.Name } already exists");
            }

            _identityResources[identityResource.Name] = identityResource;

            return(Task.CompletedTask);
        }
コード例 #6
0
        public Task UpdateIdentityResourceAsync(IdentityResourceModel identityResource, IEnumerable <string> propertyNames)
        {
            if (!_identityResources.ContainsKey(identityResource.Name))
            {
                throw new Exception($"Api with clientId { identityResource.Name } not exists");
            }

            _identityResources[identityResource.Name] = identityResource;

            return(Task.CompletedTask);
        }
コード例 #7
0
        async public Task UpdateIdentityResourceAsync(IdentityResourceModel identityResource, IEnumerable <string> propertyNames)
        {
            FileInfo fi = new FileInfo($"{ _rootPath }/{ identityResource.Name.NameToHexId(_cryptoService) }.identity");

            if (fi.Exists)
            {
                fi.Delete();
            }

            await AddIdentityResourceAsync(identityResource);
        }
コード例 #8
0
        async public Task UpdateIdentityResourceAsync(IdentityResourceModel identityResource, IEnumerable <string> propertyNames = null)
        {
            var collection = GetIdentityResourceCollection();

            string id = identityResource.Name.IdentityNameToHexId(_cryptoService);

            UpdateDefinition <IdentityResourceDocument> update = Builders <IdentityResourceDocument>
                                                                 .Update
                                                                 .Set("BlobData", _cryptoService.EncryptText(_blobSerializer.SerializeObject(identityResource)));

            await collection
            .UpdateOneAsync <IdentityResourceDocument>(d => d.Id == id, update);
        }
コード例 #9
0
        public static IdentityResourceInputModel ToInputModel(this IdentityResourceModel model)
        {
            var inputModel = new IdentityResourceInputModel()
            {
                Id          = model.Id,
                Name        = model.Name,
                DisplayName = model.DisplayName,
                Description = model.Description,
                UserClaims  = model.UserClaims
            } ?? new IdentityResourceInputModel();

            return(inputModel);
        }
コード例 #10
0
        async public Task UpdateIdentityResourceAsync(IdentityResourceModel identityResource, IEnumerable <string> propertyNames = null)
        {
            if (_tableStorage == null || identityResource == null)
            {
                return;
            }

            await _tableStorage.MergeEntity(_tablename,
                                            new BlobTableEntity(TableStorageBlobResourceDb.IdentityResourcePartitionKey,
                                                                identityResource.RowKey(),
                                                                identityResource,
                                                                _cryptoService,
                                                                _blobSerializer));
        }
コード例 #11
0
        public static IdentityResourceModel ToModel(this IdentityResourceData data)
        {
            var model = new IdentityResourceModel()
            {
                Id          = data.Id,
                Name        = data.Name,
                DisplayName = data.DisplayName,
                Description = data.Description,
                Enabled     = data.Enabled,
                UserClaims  = data.UserClaims
            } ?? new IdentityResourceModel();

            return(model);
        }
コード例 #12
0
        async public Task RemoveIdentityResourceAsync(IdentityResourceModel identityResource)
        {
            if (_tableStorage == null || identityResource == null)
            {
                return;
            }

            await _tableStorage.DeleteEntityAsync(_tablename,
                                                  new BlobTableEntity(TableStorageBlobResourceDb.IdentityResourcePartitionKey,
                                                                      identityResource.RowKey(),
                                                                      identityResource,
                                                                      _cryptoService,
                                                                      _blobSerializer));
        }
コード例 #13
0
        public Task RemoveIdentityResourceAsync(IdentityResourceModel identityResource)
        {
            if (!_identityResources.ContainsKey(identityResource.Name))
            {
                throw new Exception($"Identity { identityResource.Name } not exists");
            }

            if (!_identityResources.TryRemove(identityResource.Name, out identityResource))
            {
                throw new Exception($"Can't remove identity");
            }

            return(Task.CompletedTask);
        }
コード例 #14
0
        public async Task <IActionResult> Delete(IdentityResourceModel model)
        {
            if (model.Id == 0)
            {
                return(RedirectToAction(nameof(Index)));
            }

            var result = await _identityResourceService.DeleteIdentityResourceAsync(CommonMappers.Mapper.Map <IdentityResource>(model));

            if (result)
            {
                SuccessNotification(await _localizationService.GetResourceAsync("IdentityResource.Deleted"));
                return(RedirectToAction(nameof(Index)));
            }

            return(View(model));
        }
コード例 #15
0
        async public Task AddIdentityResourceAsync(IdentityResourceModel identityResource)
        {
            string   id = identityResource.Name.NameToHexId(_cryptoService);
            FileInfo fi = new FileInfo($"{ _rootPath }/{ id }.identity");

            if (fi.Exists)
            {
                throw new Exception("Identity resource already exists");
            }

            byte[] buffer = Encoding.UTF8.GetBytes(
                _cryptoService.EncryptText(_blobSerializer.SerializeObject(identityResource)));

            using (var fs = new FileStream(fi.FullName, FileMode.OpenOrCreate,
                                           FileAccess.Write, FileShare.None, buffer.Length, true))
            {
                await fs.WriteAsync(buffer, 0, buffer.Length);
            }
        }
コード例 #16
0
 private bool CheckDataAndIdentityModel(IdentityResourceData data, IdentityResourceModel model)
 {
     return
         (data != null
          &&
          model != null
          &&
          data.Name == model.Name
          &&
          data.DisplayName == model.DisplayName
          &&
          data.Description == model.Description
          &&
          data.Enabled == model.Enabled
          &&
          data.Id == model.Id
          &&
          data.UserClaims.All(dataUserClaim => model.UserClaims.Contains(dataUserClaim)));
 }
コード例 #17
0
        public ActionResult CreatIdentityResources(IdentityResourceModel model)
        {
            string sql = "INSERT INTO \"IdentityResources\" (\"Name\",\"DisplayName\",\"Enabled\",\"Description\",\"Required\",\"Emphasize\",\"ShowInDiscoveryDocument\") VALUES ( @name,@displayname,cast(@enabled as bool),@description,false,false,true);";

            var paramList = new List <KeyValuePair <string, string> >()
            {
                new KeyValuePair <string, string>("name", model.ResourceName),
                new KeyValuePair <string, string>("displayname", model.DisplayName),
                new KeyValuePair <string, string>("enabled", model.Enabled.ToString()),
                new KeyValuePair <string, string>("description", model.Description)
            };

            try
            {
                DataServices.executeSQLStatement(sql, paramList, "connectionString_SynapseIdentityStore");
            }
            catch (Exception ex)
            {
            }
            return(RedirectToAction("IdentityResourceManager"));
        }
コード例 #18
0
        public async Task <IActionResult> Create(IdentityResourceModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            model.UserClaims = model.UserClaimsItems.Deserialize <List <string> >()?.Select(x => new IdentityResourceClaimModel
            {
                Type = x
            }).ToList();
            var insertedResult = await _identityResourceService.InsertIdentityResourceAsync(CommonMappers.Mapper.Map <IdentityResource>(model));

            if (insertedResult > 0)
            {
                SuccessNotification(await _localizationService.GetResourceAsync("IdentityResource.Added"));

                return(RedirectToAction(nameof(Index)));
            }

            return(View(model));
        }
コード例 #19
0
        public DataResult <int> CreateIdentityResource(IdentityResourceModel identityResourceModel,
                                                       IEnumerable <int> claimsIds)
        {
            var identityResourceEntity = new IdentityResourceEntity
            {
                Name                    = identityResourceModel.Name,
                Description             = identityResourceModel.Description,
                Required                = identityResourceModel.Required,
                ShowInDiscoveryDocument = identityResourceModel.ShowInDiscoveryDocument
            };

            try
            {
                var result = m_identityResourceUoW.CreateIdentityResource(identityResourceEntity, claimsIds);
                return(Success(result));
            }
            catch (DatabaseException e)
            {
                m_logger.LogWarning(e);
                return(Error <int>(e.Message));
            }
        }
        public IActionResult Edit(IdentityResourceModel model)
        {
            IdentityResource identity;

            if (model.Id == 0)
            {
                identity = new IdentityResource
                {
                    UserClaims = new List <IdentityResourceClaim>(),
                };
                _configurationDbContext.IdentityResources.Add(identity);
            }
            else
            {
                identity = _configurationDbContext.IdentityResources
                           .Include(x => x.UserClaims)
                           .FirstOrDefault(x => x.Id == model.Id);
                identity.UserClaims.Clear();
            }

            model.UpdateEntity(identity);

            if (!string.IsNullOrEmpty(model.UserClaimsItems))
            {
                model.UserClaims = JsonConvert.DeserializeObject <List <string> >(model.UserClaimsItems);

                identity.UserClaims.AddRange(model.UserClaims.Select(x => new IdentityResourceClaim
                {
                    Type = x,
                }));
            }

            _configurationDbContext.SaveChanges();

            return(RedirectToAction(nameof(Edit), new { id = identity.Id }));
        }
コード例 #21
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            Id = id;

            if (!id.HasValue)
            {
                IdentityResource = new IdentityResourceModel();
            }
            else
            {
                var identityResource = await LoadIdentityResource(id);

                if (identityResource == null)
                {
                    return(NotFound());
                }

                IdentityResource = identityResource.ToModel();
            }

            LoadLookups();

            return(Page());
        }
コード例 #22
0
        async public Task AddIdentityResourceAsync(IdentityResourceModel identityResource)
        {
            if (identityResource == null)
            {
                return;
            }

            if (await FindApiResourceAsync(identityResource.Name) != null)
            {
                throw new Exception("Identity resource alread exists");
            }

            string id = identityResource.Name.IdentityNameToHexId(_cryptoService);

            var collection = GetIdentityResourceCollection();

            var document = new IdentityResourceDocument()
            {
                Id       = id,
                BlobData = _cryptoService.EncryptText(_blobSerializer.SerializeObject(identityResource))
            };

            await collection.InsertOneAsync(document);
        }
コード例 #23
0
 async public Task LoadCurrentIdentityResourceAsync(string id)
 {
     this.CurrentIdentityResource = await _resourceDb.FindIdentityResource(id);
 }
コード例 #24
0
        public IActionResult Create()
        {
            var model = new IdentityResourceModel();

            return(View(model));
        }
コード例 #25
0
 public static void ToEntity(this IdentityResourceModel model, IdentityResource identityResource)
 {
     Mapper.Map(model, identityResource);
 }
コード例 #26
0
 public static IdentityResource ToEntity(this IdentityResourceModel resource)
 {
     return(resource == null ? null : Mapper.Map <IdentityResource>(resource));
 }
コード例 #27
0
 static public string RowKey(this IdentityResourceModel identityResource)
 {
     return(identityResource.Name);
 }