public IEnumerable <PermissionGrant> GetByPrincipalAndSchema(CPN principal, CSN schema)
        {
            var principalStr   = principal?.ToString();
            var schemaStr      = schema?.ToString();
            var foundPrincipal = this.context.Principals.FirstOrDefault(p => p.CanonicalName == principalStr);
            var foundSchema    = this.context.Schemas.FirstOrDefault(s => s.CanonicalName == schemaStr);

            if (foundPrincipal == null)
            {
                return(new List <PermissionGrant>());
            }
            var query = GetQuery();
            Func <Persistance.Models.PermissionGrant, bool> filter;

            if (foundSchema != null)
            {
                filter = (g) => g.PrincipalId == foundPrincipal.PrincipalId && g.SchemaId == foundSchema.SchemaId;
            }
            else
            {
                filter = g => g.PrincipalId == foundPrincipal.PrincipalId;
            }

            return(query.Where(filter).ToList().Select(ToModel));
        }
Exemplo n.º 2
0
        public void Remove(CSN schema)
        {
            if (schema == null)
            {
                return;
            }

            var found = this.context.Schemas.FirstOrDefault(s => s.CanonicalName == schema.ToString());

            if (found == null)
            {
                return;
            }

            this.context.Remove(found);
            this.context.SaveChanges();
        }
 public IEnumerable <DataProviderPolicy> GetPoliciesForSchema(CSN schema)
 {
     return(this.context.DataProviderPolicies
            .Include(p => p.Provider)
            .Include(p => p.Schema)
            .Include(p => p.PolicyItems)
            .ThenInclude(i => i.Principal)
            .Where(p => p.Schema.CanonicalName == schema.ToString())
            .ToList()
            .Select(p => new DataProviderPolicy()
     {
         Provider = CRN.FromValue(p.Provider.CanonicalName),
         Schema = CSN.FromValue(p.Schema.CanonicalName),
         Rule = p.PolicyItems.Select(i => new DataProviderPolicyRule()
         {
             Principal = CPN.FromValue(i.Principal.CanonicalName),
             Allow = i.Allow,
             Deny = i.Deny
         }).ToList()
     }));
 }
        public void RemovePolicy(CRN identifier, CSN schema)
        {
            var provider    = this.context.DataProviders.FirstOrDefault(p => p.CanonicalName == identifier.ToString());
            var foundSchema = this.context.Schemas.FirstOrDefault(s => s.CanonicalName == schema.ToString());

            if (provider == null || foundSchema == null)
            {
                return;
            }

            var found = this.context.DataProviderPolicies.FirstOrDefault(p =>
                                                                         p.DataProviderId == provider.DataProviderId && p.SchemaId == foundSchema.SchemaId);

            if (found == null)
            {
                return;
            }
            this.context.Remove(found);
            this.context.SaveChanges();
        }