Exemplo n.º 1
0
        /// <summary>
        /// Creates a user pool
        /// </summary>
        public async Task UpdateAsync(SecurityPool entity)
        {
            Ensure.Argument.NotNull(entity);

            var pool = await _db.SecurityPools.FirstOrDefaultAsync(x => x.PoolId == entity.PoolId);

            if (pool == null)
            {
                throw new Exception($"Pool not found (poolId:{entity.PoolId})");
            }

            pool.Name = entity.Name;

            await _db.SaveChangesAsync();
        }
Exemplo n.º 2
0
        private async Task <SecurityPool> GetPoolIdFromRequest(HttpContext httpContext)
        {
            var          acrValues    = httpContext.Request.Query["acr_values"].ToString();
            SecurityPool securityPool = null;

            if (!String.IsNullOrEmpty(acrValues))
            {
                var poolId = Regex.Match(acrValues, @"[tenant:][^\s]+").Value.Replace("tenant:", "");

                if (!String.IsNullOrEmpty(poolId))
                {
                    securityPool = await _poolManager.GetByIdAsync(poolId);
                }
            }

            return(securityPool);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates a child security pool for a tenant
        /// </summary>
        public async Task <SecurityPool> CreateChildPoolAsync(string parentPoolId, string name, IEnumerable <Directory> directoriesToMap)
        {
            Ensure.Argument.NotNullOrEmpty(name);
            Ensure.Argument.NotNullOrEmpty(parentPoolId);

            var parentPool = await _db.SecurityPools.FirstOrDefaultAsync(x => x.PoolId == parentPoolId);

            if (parentPool == null)
            {
                throw new NullReferenceException($"Could not create child pool. Parent pool {parentPoolId} does not exist.");
            }

            var childPool = new SecurityPool
            {
                PoolId       = KeyGen.NewGuid(),
                TenantId     = parentPool.TenantId,
                ParentPoolId = parentPool.PoolId,
                PoolType     = PoolType.Site,
                Name         = name
            };

            if (directoriesToMap != null)
            {
                childPool.DirectoryMap = directoriesToMap
                                         .Select(
                    d => new DirectoryMap
                {
                    DirectoryId = d.Id,
                    PoolId      = childPool.PoolId
                }
                    ).ToList();
            }

            _db.SecurityPools.Add(childPool);
            await _db.SaveChangesAsync();

            return(childPool);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates a top level security pool for a tenant
        /// </summary>
        public async Task <SecurityPool> CreateTenantPoolAsync(string tenantKey, string name, IEnumerable <Directory> directoriesToMap)
        {
            Ensure.Argument.NotNullOrEmpty(name);
            Ensure.Argument.NotNullOrEmpty(tenantKey);

            var tenant = await _db.Tenants.FirstOrDefaultAsync(x => x.Key == tenantKey);

            if (tenant == null)
            {
                throw new NullReferenceException($"Tenant {tenantKey} does not exist.");
            }


            var pool = new SecurityPool
            {
                PoolType = PoolType.Client,
                PoolId   = KeyGen.NewGuid(),
                TenantId = tenant.Id,
                Name     = name
            };

            if (directoriesToMap != null)
            {
                pool.DirectoryMap = directoriesToMap.Select(
                    d => new DirectoryMap
                {
                    DirectoryId = d.Id,
                    PoolId      = pool.PoolId
                }
                    ).ToList();
            }

            _db.SecurityPools.Add(pool);
            await _db.SaveChangesAsync();

            return(pool);
        }