Example #1
0
        /// <summary>
        /// Grants access to a table.
        /// </summary>
        private async Task <IResponse> Grant(IRequestContext request, Route route)
        {
            string tableName = GetAndValidateTableName(route);

            if (!this.Database.TableExists(tableName))
            {
                return(ArribaResponse.NotFound("Table not found to grant permission on."));
            }

            var identity = await request.Request.ReadBodyAsync <SecurityIdentity>();

            if (String.IsNullOrEmpty(identity.Name))
            {
                return(ArribaResponse.BadRequest("Identity name must not be empty"));
            }

            PermissionScope scope;

            if (!Enum.TryParse <PermissionScope>(route["scope"], true, out scope))
            {
                return(ArribaResponse.BadRequest("Unknown permission scope {0}", route["scope"]));
            }

            using (request.Monitor(MonitorEventLevel.Information, "GrantPermission", type: "Table", identity: tableName, detail: new { Scope = scope, Identity = identity }))
            {
                SecurityPermissions security = this.Database.Security(tableName);
                security.Grant(identity.Scope, identity.Name, scope);

                // Save permissions
                this.Database.SaveSecurity(tableName);
            }

            return(ArribaResponse.Ok("Granted"));
        }
        public SecurityPermissions LoadPermissions()
        {
            SecurityPermissions result = new SecurityPermissions();

            foreach (SecurityIdentity identity in ParseIdentities(this.Owners))
            {
                result.Grant(identity, PermissionScope.Owner);
            }

            foreach (SecurityIdentity identity in ParseIdentities(this.Writers))
            {
                result.Grant(identity, PermissionScope.Writer);
            }

            foreach (SecurityIdentity identity in ParseIdentities(this.Readers))
            {
                result.Grant(identity, PermissionScope.Reader);
            }

            return(result);
        }
Example #3
0
        private static void SetTableCreators(string creators)
        {
            Console.WriteLine("Setting table creators...");

            SecurityPermissions createPermissions = new SecurityPermissions();

            foreach (string creator in creators.Split(';'))
            {
                string[]      parts = creator.Split(':');
                IdentityScope scope = parts[0].Equals("u", StringComparison.OrdinalIgnoreCase) ? IdentityScope.User : IdentityScope.Group;
                createPermissions.Grant(new SecurityIdentity(scope, parts[1]), PermissionScope.Owner);

                Console.WriteLine($" - {scope} {parts[1]}");
            }

            // Create table, if required
            SecureDatabase db = new SecureDatabase();

            db.SetSecurity("", createPermissions);
            db.SaveSecurity("");
        }