Exemplo n.º 1
0
        public async Task Create(
            AuthorizationPolicyInfo policy,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            if (policy == null)
            {
                throw new ArgumentException("policy cannot be null");
            }

            using (var db = _contextFactory.CreateContext())
            {
                var entity = new AuthorizationPolicyEntity();
                policy.CopyTo(entity);
                SyncRoles(db, policy.AllowedRoles, entity);
                SyncSchemes(db, policy.AuthenticationSchemes, entity);
                SyncClaimRequirements(db, policy.RequiredClaims, entity);

                db.Policies.Add(entity);

                int rowsAffected = await db.SaveChangesAsync(cancellationToken)
                                   .ConfigureAwait(false);

                _cache.ClearListCache(policy.TenantId);
            }
        }
Exemplo n.º 2
0
        public async Task Create(
            AuthorizationPolicyInfo policy,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            if (policy == null)
            {
                throw new ArgumentException("policy cannot be null");
            }

            await _policyCommands.CreateAsync(
                policy.TenantId,
                policy.Id.ToString(),
                policy,
                cancellationToken).ConfigureAwait(false);

            _cache.ClearListCache(policy.TenantId);
        }