diff --git a/src/adapter/auth-oso-rebac/tests/tests/test_oso_dataset_authorizer.rs b/src/adapter/auth-oso-rebac/tests/tests/test_oso_dataset_authorizer.rs index 9aa54ae72d..9675e14bfe 100644 --- a/src/adapter/auth-oso-rebac/tests/tests/test_oso_dataset_authorizer.rs +++ b/src/adapter/auth-oso-rebac/tests/tests/test_oso_dataset_authorizer.rs @@ -144,6 +144,11 @@ impl DatasetAuthorizerHarness { .add_value(predefined_accounts_config) .add::() .add::() + .add_value(kamu_auth_rebac_services::DefaultAccountProperties { is_admin: false }) + .add_value(kamu_auth_rebac_services::DefaultDatasetProperties { + allows_anonymous_read: false, + allows_public_read: false, + }) .add::() .add::() .add_builder( diff --git a/src/adapter/graphql/tests/tests/test_gql_datasets.rs b/src/adapter/graphql/tests/tests/test_gql_datasets.rs index 6b4c6fbb4d..298a5f1657 100644 --- a/src/adapter/graphql/tests/tests/test_gql_datasets.rs +++ b/src/adapter/graphql/tests/tests/test_gql_datasets.rs @@ -825,6 +825,11 @@ impl GraphQLDatasetsHarness { .bind::() .add::() .add::() + .add_value(kamu_auth_rebac_services::DefaultAccountProperties { is_admin: false }) + .add_value(kamu_auth_rebac_services::DefaultDatasetProperties { + allows_anonymous_read: false, + allows_public_read: false, + }) .add::(); if tenancy_config == TenancyConfig::MultiTenant { diff --git a/src/app/cli/src/app.rs b/src/app/cli/src/app.rs index 54a2aed33b..28cdfdad80 100644 --- a/src/app/cli/src/app.rs +++ b/src/app/cli/src/app.rs @@ -496,6 +496,11 @@ pub fn configure_base_catalog( b.add::(); b.add::(); + b.add_value(kamu_auth_rebac_services::DefaultAccountProperties { is_admin: false }); + b.add_value(kamu_auth_rebac_services::DefaultDatasetProperties { + allows_anonymous_read: false, + allows_public_read: false, + }); b.add::(); b.add::(); diff --git a/src/domain/auth-rebac/domain/src/services/rebac_service.rs b/src/domain/auth-rebac/domain/src/services/rebac_service.rs index f6b3a4adec..77c42154ba 100644 --- a/src/domain/auth-rebac/domain/src/services/rebac_service.rs +++ b/src/domain/auth-rebac/domain/src/services/rebac_service.rs @@ -103,7 +103,7 @@ pub trait RebacService: Send + Sync { //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -#[derive(Debug, Default)] +#[derive(Debug, Clone)] pub struct AccountProperties { pub is_admin: bool, } @@ -120,7 +120,7 @@ impl AccountProperties { //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -#[derive(Debug, Default)] +#[derive(Debug, Clone)] pub struct DatasetProperties { pub allows_anonymous_read: bool, pub allows_public_read: bool, diff --git a/src/domain/auth-rebac/services/src/rebac_service_impl.rs b/src/domain/auth-rebac/services/src/rebac_service_impl.rs index cbe39232bd..d2962709e8 100644 --- a/src/domain/auth-rebac/services/src/rebac_service_impl.rs +++ b/src/domain/auth-rebac/services/src/rebac_service_impl.rs @@ -42,15 +42,30 @@ use opendatafabric as odf; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +pub type DefaultAccountProperties = AccountProperties; +pub type DefaultDatasetProperties = DatasetProperties; + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + pub struct RebacServiceImpl { rebac_repo: Arc, + default_account_properties: Arc, + default_dataset_properties: Arc, } #[component(pub)] #[interface(dyn RebacService)] impl RebacServiceImpl { - pub fn new(rebac_repo: Arc) -> Self { - Self { rebac_repo } + pub fn new( + rebac_repo: Arc, + default_account_properties: Arc, + default_dataset_properties: Arc, + ) -> Self { + Self { + rebac_repo, + default_account_properties, + default_dataset_properties, + } } } @@ -103,13 +118,14 @@ impl RebacService for RebacServiceImpl { .await .int_err()?; + let default_account_properties = (*self.default_account_properties).clone(); let account_properties = entity_properties .into_iter() .map(|(name, value)| match name { PropertyName::Dataset(_) => unreachable!(), PropertyName::Account(account_property_name) => (account_property_name, value), }) - .fold(AccountProperties::default(), |mut acc, (name, value)| { + .fold(default_account_properties, |mut acc, (name, value)| { acc.apply(name, &value); acc }); @@ -180,13 +196,14 @@ impl RebacService for RebacServiceImpl { .await .int_err()?; + let default_dataset_properties = (*self.default_dataset_properties).clone(); let dataset_properties = entity_properties .into_iter() .map(|(name, value)| match name { PropertyName::Dataset(dataset_property_name) => (dataset_property_name, value), PropertyName::Account(_) => unreachable!(), }) - .fold(DatasetProperties::default(), |mut acc, (name, value)| { + .fold(default_dataset_properties, |mut acc, (name, value)| { acc.apply(name, &value); acc }); @@ -210,9 +227,10 @@ impl RebacService for RebacServiceImpl { .int_err()?; let mut dataset_properties_map = HashMap::new(); + let default_dataset_properties = (*self.default_dataset_properties).clone(); for dataset_id in dataset_ids { - dataset_properties_map.insert(dataset_id.clone(), DatasetProperties::default()); + dataset_properties_map.insert(dataset_id.clone(), default_dataset_properties.clone()); } let entity_properties_it = diff --git a/src/domain/auth-rebac/services/tests/tests/test_multi_tenant_rebac_dataset_lifecycle_message_consumer.rs b/src/domain/auth-rebac/services/tests/tests/test_multi_tenant_rebac_dataset_lifecycle_message_consumer.rs index 1dcdbaaefe..87487959c6 100644 --- a/src/domain/auth-rebac/services/tests/tests/test_multi_tenant_rebac_dataset_lifecycle_message_consumer.rs +++ b/src/domain/auth-rebac/services/tests/tests/test_multi_tenant_rebac_dataset_lifecycle_message_consumer.rs @@ -191,6 +191,11 @@ impl MultiTenantRebacDatasetLifecycleMessageConsumerHarness { catalog_builder .add::() .add::() + .add_value(kamu_auth_rebac_services::DefaultAccountProperties { is_admin: false }) + .add_value(kamu_auth_rebac_services::DefaultDatasetProperties { + allows_anonymous_read: false, + allows_public_read: false, + }) .add::(); let catalog = catalog_builder.build();