Пример #1
0
        public virtual void CanAddAndGetClientScope()
        {
            using (var uow = DataService.StartUnitOfWork())
            {
                var client = new ClientEntity
                {
                    ClientId           = "fluitec.appfx.lkjsadlkjsalkjaslkjdasd",
                    Name               = "TestClient",
                    Secret             = "MySecret",
                    AllowOfflineAccess = false,
                    GrantTypes         = "client_credentials"
                };
                uow.ClientRepository.Add(client);

                var scope = new ScopeEntity
                {
                    Name                    = "openid",
                    Description             = "OpenId-Scope",
                    DisplayName             = "OpenId",
                    Emphasize               = true,
                    Required                = true,
                    ShowInDiscoveryDocument = true
                };
                uow.ScopeRepository.Add(scope);

                var clientScope = new ClientScopeEntity
                {
                    ClientId = client.Id,
                    ScopeId  = scope.Id
                };
                uow.ClientScopeRepository.Add(clientScope);

                Assert.AreEqual(clientScope.ScopeId, uow.ClientScopeRepository.Get(clientScope.Id).ScopeId);
            }
        }
Пример #2
0
        public virtual void CanGetGetByScopeNamesCompound()
        {
            using (var uow = DataService.StartUnitOfWork())
            {
                var resource = new ApiResourceEntity
                {
                    Name        = "openid",
                    Description = "OpenId-Scope",
                    DisplayName = "OpenId",
                    Enabled     = true
                };
                uow.ApiResourceRepository.Add(resource);

                var scope = new ScopeEntity
                {
                    Name                    = "openid",
                    Description             = "OpenId-Scope",
                    DisplayName             = "OpenId",
                    Emphasize               = true,
                    Required                = true,
                    ShowInDiscoveryDocument = true
                };
                uow.ScopeRepository.Add(scope);

                var resScope = new ApiResourceScopeEntity
                {
                    ApiResourceId = resource.Id,
                    ScopeId       = scope.Id
                };
                uow.ApiResourceScopeRepository.Add(resScope);


                Assert.IsNotNull(uow.ApiResourceRepository.GetByScopeNamesCompound(new[] { scope.Name }).First());
            }
        }
        public virtual void CanAddAndGetApiResourceScope()
        {
            using (var uow = DataService.StartUnitOfWork())
            {
                var resource = new ApiResourceEntity
                {
                    Name        = "openid",
                    Description = "OpenId-Scope",
                    DisplayName = "OpenId",
                    Enabled     = true
                };
                uow.ApiResourceRepository.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 ApiResourceScopeEntity
                {
                    ApiResourceId = resource.Id,
                    ScopeId       = scope.Id
                };
                uow.ApiResourceScopeRepository.Add(resourceScope);

                Assert.AreEqual(resourceScope.ApiResourceId,
                                uow.ApiResourceScopeRepository.Get(resourceScope.Id).ApiResourceId);
            }
        }
Пример #4
0
        public DataResult <int> AddScopeToApiResource(int apiResourceId, ScopeModel scope, IEnumerable <int> claimsIds)
        {
            var newScope = new ScopeEntity
            {
                Name                    = scope.Name,
                Description             = scope.Description,
                Required                = scope.Required,
                ShowInDiscoveryDocument = scope.ShowInDiscoveryDocument
            };

            try
            {
                var result = m_scopeUoW.AddScopeToApiResource(apiResourceId, newScope, claimsIds);
                return(Success(result));
            }
            catch (NoResultException <ApiResourceEntity> e)
            {
                m_logger.LogWarning(e);
                return(Error <int>(m_translator.Translate("invalid-api-resource-id"), DataResultErrorCode.ApiResourceNotExistId));
            }
            catch (DatabaseException e)
            {
                m_logger.LogWarning(e);
                return(Error <int>(e.Message));
            }
        }
Пример #5
0
        public DataResult <int> CreateApiResource(ApiResourceModel apiResourceModel, IEnumerable <int> claimsIds)
        {
            var defaultScope = new ScopeEntity
            {
                Name                    = apiResourceModel.Name,
                Description             = apiResourceModel.Description,
                Required                = apiResourceModel.Required,
                ShowInDiscoveryDocument = apiResourceModel.ShowInDiscoveryDocument
            };

            var apiResourceEntity = new ApiResourceEntity
            {
                Name                    = apiResourceModel.Name,
                Description             = apiResourceModel.Description,
                Required                = apiResourceModel.Required,
                ShowInDiscoveryDocument = apiResourceModel.ShowInDiscoveryDocument,
            };

            try
            {
                var result = m_apiResourceUoW.CreateApiResource(apiResourceEntity, claimsIds, defaultScope);
                return(Success(result));
            }
            catch (DatabaseException e)
            {
                m_logger.LogWarning(e);
                return(Error <int>(e.Message));
            }
        }
Пример #6
0
 protected ApiScope ScopeToApiScope(ScopeEntity scope)
 {
     return(new ApiScope()
     {
         Name = scope.Name,
         Enabled = true,
         Description = scope.Description,
         DisplayName = scope.Name
     });
 }
        public virtual void CanAddAndGetIdentityResourceScopes()
        {
            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 resourceScopes = new[]
                {
                    new IdentityResourceScopeEntity
                    {
                        IdentityResourceId = resource.Id,
                        ScopeId            = scope.Id
                    },
                    new IdentityResourceScopeEntity
                    {
                        IdentityResourceId = resource.Id,
                        ScopeId            = scope2.Id
                    }
                };
                uow.IdentityResourceScopeRepository.AddRange(resourceScopes);
                Assert.AreEqual(resourceScopes.Length, uow.IdentityResourceScopeRepository.GetAll().Count());
            }
        }
Пример #8
0
        public virtual int AddScopeToApiResource(int apiResourceId, ScopeEntity newScope, IEnumerable <int> claimsIds)
        {
            var apiResource = m_apiResourceRepository.FindById <ApiResourceEntity>(apiResourceId);

            newScope.ApiResource = apiResource ?? throw new NoResultException <ApiResourceEntity>();

            newScope.ClaimTypes = new HashSet <ClaimTypeEntity>(m_claimTypeRepository.GetClaimTypesById(claimsIds));

            var result = (int)m_scopeRepository.Create(newScope);

            return(result);
        }
Пример #9
0
 public virtual void CanGetByNames()
 {
     using (var uow = DataService.StartUnitOfWork())
     {
         var scope = new ScopeEntity
         {
             Name                    = "openid",
             Description             = "OpenId-Scope",
             DisplayName             = "OpenId",
             Emphasize               = true,
             Required                = true,
             ShowInDiscoveryDocument = true
         };
         uow.ScopeRepository.Add(scope);
         Assert.AreEqual(scope.Name, uow.ScopeRepository.GetByNames(new[] { scope.Name }).First().Name);
     }
 }
Пример #10
0
        public virtual void CanDeleteScope()
        {
            using (var uow = DataService.StartUnitOfWork())
            {
                var scope = new ScopeEntity
                {
                    Name                    = "openid",
                    Description             = "OpenId-Scope",
                    DisplayName             = "OpenId",
                    Emphasize               = true,
                    Required                = true,
                    ShowInDiscoveryDocument = true
                };
                uow.ScopeRepository.Add(scope);

                uow.ScopeRepository.Delete(scope);

                Assert.AreEqual(null, uow.ScopeRepository.Get(scope.Id));
            }
        }
        public ResourceScopeEntity Create(AddResourceScopeViewModel vm)
        {
            ValidationUtils.ValidateViewModel(vm);

            if (!_resourceRepository.Exists(vm.ResourceId))
            {
                throw new EntityValidationException("No resources with the given ID exists!");
            }

            var scope = _scopeRepository.Get(vm.Name);

            if (null == scope)
            {
                scope = new ScopeEntity()
                {
                    Name        = vm.Name,
                    Description = vm.Description,
                    Active      = true
                };
                scope = _scopeRepository.Create(scope);
            }
            else
            {
                if (_resourceScopeRepository.ExistsOnResource(vm.ResourceId, scope.ScopeId))
                {
                    throw new EntityValidationException("This scope already exists on this resource!");
                }
            }

            var resourceScope = new ResourceScopeEntity()
            {
                ResourceId  = vm.ResourceId,
                ScopeEntity = scope
            };

            return(_resourceScopeRepository.Create(resourceScope));
        }
Пример #12
0
        public virtual int CreateApiResource(ApiResourceEntity apiResourceEntity, IEnumerable <int> claimsIds, ScopeEntity defaultScope)
        {
            var claimTypes = m_claimTypeRepository.GetClaimTypesById(claimsIds);

            apiResourceEntity.ClaimTypes = new HashSet <ClaimTypeEntity>(claimTypes);

            var result = (int)m_apiResourceRepository.Create(apiResourceEntity);

            var apiResource = m_apiResourceRepository.Load <ApiResourceEntity>(result);

            defaultScope.ApiResource = apiResource;
            defaultScope.ClaimTypes  = new HashSet <ClaimTypeEntity>(claimTypes);

            var scopeResult = (int)m_scopeRepository.Create(defaultScope);

            return(result);
        }
Пример #13
0
 public ScopeEntity Create(ScopeEntity scopeEntity)
 {
     _db.Scopes.Add(scopeEntity);
     _db.SaveChanges();
     return(scopeEntity);
 }