public DataResult <bool> UpdateIdentityResource(int id, IdentityResourceModel identityResourceModel, IEnumerable <int> claimsIds) { var identityResource = new IdentityResourceEntity { Name = identityResourceModel.Name, Description = identityResourceModel.Description, Required = identityResourceModel.Required, ShowInDiscoveryDocument = identityResourceModel.ShowInDiscoveryDocument }; try { m_identityResourceUoW.UpdateIdentityResource(id, identityResource, claimsIds); return(Success(true)); } catch (NoResultException <IdentityResourceEntity> e) { m_logger.LogWarning(e); return(Error <bool>(m_translator.Translate("invalid-resource-id"), DataResultErrorCode.ResourceNotExistId)); } catch (DatabaseException e) { m_logger.LogWarning(e); return(Error <bool>(e.Message)); } }
public virtual void CanUpdateIdentityResource() { using (var uow = DataService.StartUnitOfWork()) { var resource = new IdentityResourceEntity { Name = "openid", Description = "OpenId-Scope", DisplayName = "OpenId", Emphasize = true, Required = true, ShowInDiscoveryDocument = true }; uow.IdentityResourceRepository.Add(resource); var claim = new IdentityResourceClaimEntity { IdentityResourceId = resource.Id, ClaimType = "ClaimType" }; uow.IdentityResourceClaimRepository.Add(claim); claim.ClaimType = "changed"; uow.IdentityResourceClaimRepository.Update(claim); Assert.AreEqual(claim.ClaimType, uow.IdentityResourceClaimRepository.Get(claim.Id).ClaimType); } }
public virtual void CanAddAndGetIdentityResourceClaims() { using (var uow = DataService.StartUnitOfWork()) { var resource = new IdentityResourceEntity { Name = "openid", Description = "OpenId-Scope", DisplayName = "OpenId", Emphasize = true, Required = true, ShowInDiscoveryDocument = true }; uow.IdentityResourceRepository.Add(resource); var claims = new[] { new IdentityResourceClaimEntity { IdentityResourceId = resource.Id, ClaimType = "ClaimType" }, new IdentityResourceClaimEntity { IdentityResourceId = resource.Id, ClaimType = "ClaimType2" } }; uow.IdentityResourceClaimRepository.AddRange(claims); Assert.AreEqual(claims.Length, uow.IdentityResourceClaimRepository.GetAll().Count()); } }
public async Task <bool> AddIdentityResourceAsync(IdentityResourceEntity identityResource) { var result = await _identityContex.IdentityResources.AddAsync(identityResource); await _identityContex.SaveChangesAsync(); return(result.State == EntityState.Added); }
public virtual int CreateIdentityResource(IdentityResourceEntity identityResourceEntity, IEnumerable <int> claimsIds) { identityResourceEntity.ClaimTypes = new HashSet <ClaimTypeEntity>(m_claimTypeRepository.GetClaimTypesById(claimsIds)); var result = (int)m_identityResourceRepository.Create(identityResourceEntity); return(result); }
public virtual void CanUpdateIdentityResourceScope() { using (var uow = DataService.StartUnitOfWork()) { var resource = new IdentityResourceEntity { Name = "openid", Description = "OpenId-Scope", DisplayName = "OpenId", Emphasize = true, Required = true, ShowInDiscoveryDocument = true }; uow.IdentityResourceRepository.Add(resource); var scope = new ScopeEntity { Name = "openid", Description = "OpenId-Scope", DisplayName = "OpenId", Emphasize = true, Required = true, ShowInDiscoveryDocument = true }; uow.ScopeRepository.Add(scope); var scope2 = new ScopeEntity { Name = "openid2", Description = "OpenId-Scope2", DisplayName = "OpenId2", Emphasize = true, Required = true, ShowInDiscoveryDocument = true }; uow.ScopeRepository.Add(scope2); var resourceScope = new IdentityResourceScopeEntity { IdentityResourceId = resource.Id, ScopeId = scope.Id }; uow.IdentityResourceScopeRepository.Add(resourceScope); resourceScope.ScopeId = scope2.Id; uow.IdentityResourceScopeRepository.Update(resourceScope); Assert.AreEqual(resourceScope.ScopeId, uow.IdentityResourceScopeRepository.Get(resourceScope.Id).ScopeId); } }
public static IEnumerable <IdentityResourceEntity> GetIdentityResources() { List <IdentityResourceEntity> identityResources = new List <IdentityResourceEntity>(); foreach (var identityResource in GetIdentityResourcesInternal()) { var identityResourceEntity = new IdentityResourceEntity(); identityResourceEntity.AddDataToEntity(identityResource); identityResources.Add(identityResourceEntity); } return(identityResources); }
public virtual void CanAddAndGetIdentityResource() { using (var uow = DataService.StartUnitOfWork()) { var resource = new IdentityResourceEntity { Name = "openid", Description = "OpenId-Scope", DisplayName = "OpenId", Emphasize = true, Required = true, ShowInDiscoveryDocument = true }; uow.IdentityResourceRepository.Add(resource); Assert.AreEqual(resource.Name, uow.IdentityResourceRepository.Get(resource.Id).Name); } }
public virtual void UpdateIdentityResource(int id, IdentityResourceEntity identityResource, IEnumerable <int> claimsIds) { var identityResourceEntity = m_identityResourceRepository.FindIdentityResourceById(id); if (identityResourceEntity == null) { throw new NoResultException <IdentityResourceEntity>(); } identityResourceEntity.Name = identityResource.Name; identityResourceEntity.Description = identityResource.Description; identityResourceEntity.Required = identityResource.Required; identityResourceEntity.ShowInDiscoveryDocument = identityResource.ShowInDiscoveryDocument; identityResourceEntity.ClaimTypes = new HashSet <ClaimTypeEntity>(m_claimTypeRepository.GetClaimTypesById(claimsIds)); m_identityResourceRepository.Update(identityResourceEntity); }
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 virtual void CanGetByScopeNamesCompound() { using (var uow = DataService.StartUnitOfWork()) { var resource = new IdentityResourceEntity { Name = "openid", Description = "OpenId-Scope", DisplayName = "OpenId", Emphasize = true, Required = true, ShowInDiscoveryDocument = true }; uow.IdentityResourceRepository.Add(resource); var scope = new ScopeEntity { Name = "openid", Description = "OpenId-Scope", DisplayName = "OpenId", Emphasize = true, Required = true, ShowInDiscoveryDocument = true }; uow.ScopeRepository.Add(scope); var resourceScope = new IdentityResourceScopeEntity { IdentityResourceId = resource.Id, ScopeId = scope.Id }; uow.IdentityResourceScopeRepository.Add(resourceScope); Assert.AreEqual(resource.Name, uow.IdentityResourceRepository.GetByScopeNamesCompound(new[] { scope.Name }).First().IdentityResource .Name); } }
public async Task <bool> AddIdentityResourceAsync(IdentityResourceEntity identityResource) { await _identityResourceCollection.InsertOneAsync(identityResource); return(true); }
public static IdentityResourceEntity AddDataToEntity(this IdentityResourceEntity identityResourceEntity, IdentityResource identityResource) { identityResourceEntity.IdentityResourceName = identityResource.Name; identityResourceEntity.IdentityResourceData = JsonConvert.SerializeObject(identityResource); return(identityResourceEntity); }
public static IdentityResource MapDataFromEntity(this IdentityResourceEntity identityResourceEntity) { return(JsonConvert.DeserializeObject <IdentityResource>(identityResourceEntity.IdentityResourceData)); }
private static void EnsureSeedData(MedParkContext context) { Console.WriteLine("Seeding database..."); Console.WriteLine("Clients being populated"); foreach (var client in IdentityConfig.GetClients()) { if (context.Clients.Where(x => x.ClientId == client.ClientId).FirstOrDefault() == null) { var newClient = new ClientEntity { ClientId = client.ClientId, Client = client }; newClient.AddDataToEntity(); context.Clients.Add(newClient); context.SaveChanges(); } else { var newClient = context.Clients.Where(x => x.ClientId == client.ClientId).FirstOrDefault(); newClient.Client = client; newClient.AddDataToEntity(); context.Clients.Update(newClient); context.SaveChanges(); } } Console.WriteLine("IdentityResources being populated"); foreach (var resource in IdentityConfig.GetIdentityResources()) { if (context.IdentityResources.Where(x => x.IdentityResourceName == resource.Name).FirstOrDefault() == null) { var res = new IdentityResourceEntity { IdentityResource = resource }; res.AddDataToEntity(); context.IdentityResources.Add(res); context.SaveChanges(); } else { var newres = context.IdentityResources.Where(x => x.IdentityResourceName == resource.Name).FirstOrDefault(); newres.IdentityResource = resource; newres.AddDataToEntity(); context.IdentityResources.Update(newres); context.SaveChanges(); } } if (!context.ApiResources.Any()) { Console.WriteLine("ApiResources being populated"); foreach (var resource in IdentityConfig.GetApiResources()) { var api = new ApiResourceEntity { ApiResource = resource }; api.AddDataToEntity(); context.ApiResources.Add(api); } context.SaveChanges(); } else { Console.WriteLine("ApiResources already populated"); } Console.WriteLine("Done seeding database."); Console.WriteLine(); }