2022-07-29 11:39:32 +02:00
|
|
|
--liquibase formatted sql
|
2024-03-11 12:30:43 +01:00
|
|
|
-- This code generated was by RbacViewPostgresGenerator at 2024-03-11T11:29:11.584886824.
|
2022-07-29 08:46:04 +02:00
|
|
|
|
2022-07-29 11:39:32 +02:00
|
|
|
-- ============================================================================
|
2022-09-16 15:25:58 +02:00
|
|
|
--changeset test-customer-rbac-OBJECT:1 endDelimiter:--//
|
2022-07-29 11:39:32 +02:00
|
|
|
-- ----------------------------------------------------------------------------
|
2022-09-16 15:25:58 +02:00
|
|
|
call generateRelatedRbacObject('test_customer');
|
2022-07-29 11:39:32 +02:00
|
|
|
--//
|
|
|
|
|
2022-09-16 15:25:58 +02:00
|
|
|
|
2022-07-29 11:39:32 +02:00
|
|
|
-- ============================================================================
|
2022-08-31 09:42:40 +02:00
|
|
|
--changeset test-customer-rbac-ROLE-DESCRIPTORS:1 endDelimiter:--//
|
2022-07-29 11:39:32 +02:00
|
|
|
-- ----------------------------------------------------------------------------
|
2022-09-16 15:25:58 +02:00
|
|
|
call generateRbacRoleDescriptors('testCustomer', 'test_customer');
|
2022-07-29 11:39:32 +02:00
|
|
|
--//
|
|
|
|
|
|
|
|
|
|
|
|
-- ============================================================================
|
2024-03-11 12:30:43 +01:00
|
|
|
--changeset test-customer-rbac-insert-trigger:1 endDelimiter:--//
|
2022-07-29 11:39:32 +02:00
|
|
|
-- ----------------------------------------------------------------------------
|
2022-07-29 08:46:04 +02:00
|
|
|
|
2022-07-29 11:39:32 +02:00
|
|
|
/*
|
2024-03-11 12:30:43 +01:00
|
|
|
Creates the roles, grants and permission for the AFTER INSERT TRIGGER.
|
2022-07-29 11:39:32 +02:00
|
|
|
*/
|
2022-07-29 08:46:04 +02:00
|
|
|
|
2024-03-11 12:30:43 +01:00
|
|
|
create or replace procedure buildRbacSystemForTestCustomer(
|
|
|
|
NEW test_customer
|
|
|
|
)
|
|
|
|
language plpgsql as $$
|
|
|
|
|
2022-07-29 08:46:04 +02:00
|
|
|
declare
|
|
|
|
|
2024-03-11 12:30:43 +01:00
|
|
|
begin
|
2024-02-24 09:04:07 +01:00
|
|
|
call enterTriggerForObjectUuid(NEW.uuid);
|
|
|
|
|
2024-03-11 12:30:43 +01:00
|
|
|
perform createRoleWithGrants(
|
2022-08-31 09:42:40 +02:00
|
|
|
testCustomerOwner(NEW),
|
2024-03-11 12:30:43 +01:00
|
|
|
permissions => array['DELETE'],
|
|
|
|
userUuids => array[currentUserUuid()],
|
|
|
|
incomingSuperRoles => array[globalAdmin(unassumed())]
|
|
|
|
);
|
2022-07-29 08:46:04 +02:00
|
|
|
|
2024-03-11 12:30:43 +01:00
|
|
|
perform createRoleWithGrants(
|
2022-08-31 09:42:40 +02:00
|
|
|
testCustomerAdmin(NEW),
|
2024-03-11 12:30:43 +01:00
|
|
|
permissions => array['UPDATE'],
|
|
|
|
incomingSuperRoles => array[testCustomerOwner(NEW)]
|
|
|
|
);
|
2022-07-29 08:46:04 +02:00
|
|
|
|
2022-10-12 15:48:56 +02:00
|
|
|
perform createRoleWithGrants(
|
2022-08-31 09:42:40 +02:00
|
|
|
testCustomerTenant(NEW),
|
2024-03-11 12:30:43 +01:00
|
|
|
permissions => array['SELECT'],
|
|
|
|
incomingSuperRoles => array[testCustomerAdmin(NEW)]
|
|
|
|
);
|
2022-07-29 08:46:04 +02:00
|
|
|
|
2024-02-24 09:04:07 +01:00
|
|
|
call leaveTriggerForObjectUuid(NEW.uuid);
|
2022-07-29 08:46:04 +02:00
|
|
|
end; $$;
|
|
|
|
|
2022-07-29 11:39:32 +02:00
|
|
|
/*
|
2024-03-11 12:30:43 +01:00
|
|
|
AFTER INSERT TRIGGER to create the role+grant structure for a new test_customer row.
|
2022-07-29 11:39:32 +02:00
|
|
|
*/
|
|
|
|
|
2024-03-11 12:30:43 +01:00
|
|
|
create or replace function insertTriggerForTestCustomer_tf()
|
|
|
|
returns trigger
|
|
|
|
language plpgsql
|
|
|
|
strict as $$
|
|
|
|
begin
|
|
|
|
call buildRbacSystemForTestCustomer(NEW);
|
|
|
|
return NEW;
|
|
|
|
end; $$;
|
|
|
|
|
|
|
|
create trigger insertTriggerForTestCustomer_tg
|
|
|
|
after insert on test_customer
|
2022-07-29 08:46:04 +02:00
|
|
|
for each row
|
2024-03-11 12:30:43 +01:00
|
|
|
execute procedure insertTriggerForTestCustomer_tf();
|
|
|
|
|
2022-07-29 11:39:32 +02:00
|
|
|
--//
|
|
|
|
|
2024-03-11 12:30:43 +01:00
|
|
|
-- ============================================================================
|
|
|
|
--changeset test-customer-rbac-INSERT:1 endDelimiter:--//
|
|
|
|
-- ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
Checks if the user or assumed roles are allowed to insert a row to test_customer.
|
|
|
|
*/
|
|
|
|
create or replace function test_customer_insert_permission_missing_tf()
|
|
|
|
returns trigger
|
|
|
|
language plpgsql as $$
|
|
|
|
begin
|
|
|
|
raise exception '[403] insert into test_customer not allowed for current subjects % (%)',
|
|
|
|
currentSubjects(), currentSubjectsUuids();
|
|
|
|
end; $$;
|
|
|
|
|
|
|
|
create trigger test_customer_insert_permission_check_tg
|
|
|
|
before insert on test_customer
|
|
|
|
for each row
|
|
|
|
-- As there is no explicit INSERT grant specified for this table,
|
|
|
|
-- only global admins are allowed to insert any rows.
|
|
|
|
when ( not isGlobalAdmin() )
|
|
|
|
execute procedure test_customer_insert_permission_missing_tf();
|
2022-07-29 12:14:22 +02:00
|
|
|
|
2024-03-11 12:30:43 +01:00
|
|
|
--//
|
2022-07-29 11:39:32 +02:00
|
|
|
-- ============================================================================
|
2022-08-31 09:42:40 +02:00
|
|
|
--changeset test-customer-rbac-IDENTITY-VIEW:1 endDelimiter:--//
|
2022-07-29 11:39:32 +02:00
|
|
|
-- ----------------------------------------------------------------------------
|
2022-07-29 08:46:04 +02:00
|
|
|
|
2024-03-11 12:30:43 +01:00
|
|
|
call generateRbacIdentityViewFromProjection('test_customer', $idName$
|
|
|
|
prefix
|
|
|
|
$idName$);
|
2022-07-29 11:39:32 +02:00
|
|
|
|
2024-03-11 12:30:43 +01:00
|
|
|
--//
|
2022-07-29 11:39:32 +02:00
|
|
|
-- ============================================================================
|
2022-08-31 09:42:40 +02:00
|
|
|
--changeset test-customer-rbac-RESTRICTED-VIEW:1 endDelimiter:--//
|
2022-07-29 11:39:32 +02:00
|
|
|
-- ----------------------------------------------------------------------------
|
2024-03-11 12:30:43 +01:00
|
|
|
call generateRbacRestrictedView('test_customer',
|
|
|
|
'reference',
|
2022-09-19 20:43:14 +02:00
|
|
|
$updates$
|
|
|
|
reference = new.reference,
|
|
|
|
prefix = new.prefix,
|
|
|
|
adminUserName = new.adminUserName
|
|
|
|
$updates$);
|
2022-07-29 11:39:32 +02:00
|
|
|
--//
|
2022-08-02 11:51:36 +02:00
|
|
|
|
|
|
|
|