public async Task UpdateIdentityResourceAsync() { using (var context = new ConfigurationDbContext(_dbContextOptions, _storeOptions, _operationalStore)) { IIdentityResourceRepository identityResourceRepository = new IdentityResourceRepository(context); //Generate random new identity resource var identityResource = IdentityResourceMock.GenerateRandomIdentityResource(0); //Add new identity resource await identityResourceRepository.AddIdentityResourceAsync(identityResource); //Get new identity resource var newIdentityResource = await context.IdentityResources.Where(x => x.Id == identityResource.Id).SingleOrDefaultAsync(); //Assert new identity resource newIdentityResource.ShouldBeEquivalentTo(identityResource, options => options.Excluding(o => o.Id)); //Detached the added item context.Entry(newIdentityResource).State = EntityState.Detached; //Generete new identity resource with added item id var updatedIdentityResource = IdentityResourceMock.GenerateRandomIdentityResource(newIdentityResource.Id); //Update identity resource await identityResourceRepository.UpdateIdentityResourceAsync(updatedIdentityResource); //Get updated identity resource var updatedIdentityResourceEntity = await context.IdentityResources.Where(x => x.Id == updatedIdentityResource.Id).SingleAsync(); //Assert updated identity resource updatedIdentityResource.ShouldBeEquivalentTo(updatedIdentityResourceEntity); } }
public IdentityResourceUoW(ISessionManager sessionManager, IdentityResourceRepository identityResourceRepository, ClaimTypeRepository claimTypeRepository) : base(sessionManager) { m_identityResourceRepository = identityResourceRepository; m_claimTypeRepository = claimTypeRepository; }
public async Task RemoveIdentityResourceAsync() { using (var context = new AdminDbContext(_dbContextOptions, _storeOptions, _operationalStore)) { IIdentityResourceRepository identityResourceRepository = new IdentityResourceRepository(context); var localizerIdentityResourceMock = new Mock <IIdentityResourceServiceResources>(); var localizerIdentityResource = localizerIdentityResourceMock.Object; IIdentityResourceService identityResourceService = new IdentityResourceService(identityResourceRepository, localizerIdentityResource); //Generate random new identity resource var identityResourceDto = IdentityResourceDtoMock.GenerateRandomIdentityResource(0); await identityResourceService.AddIdentityResourceAsync(identityResourceDto); //Get new identity resource var identityResource = await context.IdentityResources.Where(x => x.Name == identityResourceDto.Name).SingleOrDefaultAsync(); var newIdentityResourceDto = await identityResourceService.GetIdentityResourceAsync(identityResource.Id); //Assert new identity resource identityResourceDto.ShouldBeEquivalentTo(newIdentityResourceDto, options => options.Excluding(o => o.Id)); //Remove identity resource await identityResourceService.DeleteIdentityResourceAsync(newIdentityResourceDto); //Try Get Removed identity resource var removeIdentityResource = await context.IdentityResources.Where(x => x.Id == identityResource.Id) .SingleOrDefaultAsync(); //Assert removed identity resource removeIdentityResource.Should().BeNull(); } }
public async Task DeleteIdentityResourceAsync() { using (var context = new ConfigurationDbContext(_dbContextOptions, _storeOptions, _operationalStore)) { IIdentityResourceRepository identityResourceRepository = new IdentityResourceRepository(context); //Generate random new identity resource var identityResource = IdentityResourceMock.GenerateRandomIdentityResource(0); //Add new identity resource await identityResourceRepository.AddIdentityResourceAsync(identityResource); //Get new identity resource var newIdentityResource = await context.IdentityResources.Where(x => x.Id == identityResource.Id).SingleAsync(); //Assert new identity resource newIdentityResource.ShouldBeEquivalentTo(identityResource, options => options.Excluding(o => o.Id)); //Delete identity resource await identityResourceRepository.DeleteIdentityResourceAsync(newIdentityResource); //Get deleted identity resource var deletedIdentityResource = await context.IdentityResources.Where(x => x.Id == identityResource.Id).SingleOrDefaultAsync(); //Assert if it not exist deletedIdentityResource.Should().BeNull(); } }
public ClientUoW(ISessionManager sessionManager, ClientRepository clientRepository, GrantTypeRepository grantTypeRepository, IdentityResourceRepository identityResourceRepository, ApiResourceRepository apiResourceRepository, ScopeRepository scopeRepository) : base(sessionManager) { m_clientRepository = clientRepository; m_grantTypeRepository = grantTypeRepository; m_identityResourceRepository = identityResourceRepository; m_apiResourceRepository = apiResourceRepository; m_scopeRepository = scopeRepository; }
/// <summary> /// Gets identity resources by scope name. /// </summary> public virtual async Task <IEnumerable <IdentityServer4.Models.IdentityResource> > FindIdentityResourcesByScopeNameAsync(IEnumerable <string> scopeNames) { return(await GetCacheItemsAsync( IdentityResourceCache, scopeNames, async keys => await IdentityResourceRepository.GetListByScopeNameAsync(keys, includeDetails: true), (models, cacheKeyPrefix) => new List <IEnumerable <KeyValuePair <string, IdentityServer4.Models.IdentityResource> > > { models.Select(x => new KeyValuePair <string, IdentityServer4.Models.IdentityResource>(AddCachePrefix(x.Name, cacheKeyPrefix), x)) })); }
public virtual async Task <Resources> GetAllResourcesAsync() { var identityResources = await IdentityResourceRepository.GetListAsync(includeDetails : true); var apiResources = await ApiResourceRepository.GetListAsync(includeDetails : true); return(new Resources( ObjectMapper.Map <List <IdentityResource>, IdentityServer4.Models.IdentityResource[]>(identityResources), ObjectMapper.Map <List <ApiResources.ApiResource>, ApiResource[]>(apiResources) )); }
protected virtual async Task AddIdentityResourceIfNotExistsAsync(IdentityServer4.Models.IdentityResource resource) { if (await IdentityResourceRepository.CheckNameExistAsync(resource.Name)) { return; } await IdentityResourceRepository.InsertAsync( new IdentityResource( GuidGenerator.Create(), resource ) ); }
public async Task GetScopesIdentityResourceAsync() { using (var context = new AdminDbContext(_dbContextOptions, _storeOptions, _operationalStore)) { IClientRepository clientRepository = new ClientRepository(context); IIdentityResourceRepository identityResourceRepository = new IdentityResourceRepository(context); var identityResource = IdentityResourceMock.GenerateRandomIdentityResource(0); await identityResourceRepository.AddIdentityResourceAsync(identityResource); var identityScopes = await clientRepository.GetScopesAsync(identityResource.Name); identityScopes[0].Should().Be(identityResource.Name); } }
public async void ShouldAddAndSaveTheIdentityResourceInTheContext() { var identityResource = new Models.IdentityResource(); var context = A.Fake <IConfigurationDbContext>(); var identityResourceRepository = new IdentityResourceRepository(context); await identityResourceRepository.AddAsync(identityResource); A.CallTo(() => context.SaveChangesAsync()) .MustHaveHappened(); A.CallTo(() => context.IdentityResources.AddAsync( A <Entities.IdentityResource> .Ignored, A <CancellationToken> .Ignored)) .MustHaveHappened(); }
/// <summary> /// 获取作用域 /// </summary> public async Task <List <Item> > GetScopes() { var result = new List <Item>(); var identityResources = await IdentityResourceRepository.GetEnabledResources(); if (identityResources != null) { result.AddRange(identityResources.Select(t => new Item(t.Name, t.Uri))); } var apiResources = await ApiResourceRepository.GetEnabledResources(); if (apiResources != null) { result.AddRange(apiResources.Select(t => new Item(t.Name, t.Uri))); } return(result); }
/// <summary> /// Gets all resources. /// </summary> public virtual async Task <IdentityServer4.Models.Resources> GetAllResourcesAsync() { return(await ResourcesCache.GetOrAddAsync(AllResourcesKey, async() => { var identityResources = await IdentityResourceRepository.GetListAsync(includeDetails: true); var apiResources = await ApiResourceRepository.GetListAsync(includeDetails: true); var apiScopes = await ApiScopeRepository.GetListAsync(includeDetails: true); return new Resources( ObjectMapper.Map <List <Volo.Abp.IdentityServer.IdentityResources.IdentityResource>, List <IdentityServer4.Models.IdentityResource> >(identityResources), ObjectMapper.Map <List <Volo.Abp.IdentityServer.ApiResources.ApiResource>, List <IdentityServer4.Models.ApiResource> >(apiResources), ObjectMapper.Map <List <Volo.Abp.IdentityServer.ApiScopes.ApiScope>, List <IdentityServer4.Models.ApiScope> >(apiScopes)); }, () => new DistributedCacheEntryOptions { AbsoluteExpirationRelativeToNow = Options.Caching.ClientStoreExpiration })); }
public async Task GetIdentityResourceAsync() { using (var context = new ConfigurationDbContext(_dbContextOptions, _storeOptions, _operationalStore)) { IIdentityResourceRepository identityResourceRepository = new IdentityResourceRepository(context); //Generate random new identity resource var identityResource = IdentityResourceMock.GenerateRandomIdentityResource(0); //Add new identity resource await identityResourceRepository.AddIdentityResourceAsync(identityResource); //Get new identity resource var newIdentityResource = await identityResourceRepository.GetIdentityResourceAsync(identityResource.Id); //Assert new identity resource newIdentityResource.ShouldBeEquivalentTo(identityResource, options => options.Excluding(o => o.Id)); } }
public async Task UpdateIdentityResourceAsync() { using (var context = new AdminDbContext(_dbContextOptions, _storeOptions, _operationalStore)) { IIdentityResourceRepository identityResourceRepository = new IdentityResourceRepository(context); var localizerIdentityResourceMock = new Mock <IIdentityResourceServiceResources>(); var localizerIdentityResource = localizerIdentityResourceMock.Object; IIdentityResourceService identityResourceService = new IdentityResourceService(identityResourceRepository, localizerIdentityResource); //Generate random new identity resource var identityResourceDto = IdentityResourceDtoMock.GenerateRandomIdentityResource(0); await identityResourceService.AddIdentityResourceAsync(identityResourceDto); //Get new identity resource var identityResource = await context.IdentityResources.Where(x => x.Name == identityResourceDto.Name).SingleOrDefaultAsync(); var newIdentityResourceDto = await identityResourceService.GetIdentityResourceAsync(identityResource.Id); //Assert new identity resource identityResourceDto.ShouldBeEquivalentTo(newIdentityResourceDto, options => options.Excluding(o => o.Id)); //Detached the added item context.Entry(identityResource).State = EntityState.Detached; //Generete new identity resuorce with added item id var updatedIdentityResource = IdentityResourceDtoMock.GenerateRandomIdentityResource(identityResource.Id); //Update identity resuorce await identityResourceService.UpdateIdentityResourceAsync(updatedIdentityResource); var updatedIdentityResourceDto = await identityResourceService.GetIdentityResourceAsync(identityResource.Id); //Assert updated identity resuorce updatedIdentityResource.ShouldBeEquivalentTo(updatedIdentityResourceDto, options => options.Excluding(o => o.Id)); } }
private IIdentityResourceRepository GetIdentityResourceRepository(IdentityServerConfigurationDbContext context) { IIdentityResourceRepository identityResourceRepository = new IdentityResourceRepository <IdentityServerConfigurationDbContext>(context); return(identityResourceRepository); }
public virtual async Task <IEnumerable <IdentityServer4.Models.IdentityResource> > FindIdentityResourcesByScopeAsync(IEnumerable <string> scopeNames) { var resource = await IdentityResourceRepository.GetListByScopesAsync(scopeNames.ToArray(), includeDetails : true); return(ObjectMapper.Map <List <IdentityResource>, List <IdentityServer4.Models.IdentityResource> >(resource)); }
private IIdentityResourceRepository <AdminDbContext> GetIdentityResourceRepository(AdminDbContext context) { IIdentityResourceRepository <AdminDbContext> identityResourceRepository = new IdentityResourceRepository <AdminDbContext>(context); return(identityResourceRepository); }
public IdentityResourceController(IdentityResourceRepository apiResourceRepository, IMapper mapper, IIdentityServerDbContext mateupDbContext) { _identityResourceRepository = apiResourceRepository; _mapper = mapper; _mateupDbContext = mateupDbContext; }