Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
fix(authentication): fix connector and profile CRUD authentication and authorization (#10002)
Sandeep Kumar76928bc0bfe6
diff --git a/crates/router/src/core/admin.rs b/crates/router/src/core/admin.rsindex 123967f870..e30cbaec9b 100644--- a/crates/router/src/core/admin.rs+++ b/crates/router/src/core/admin.rs@@ -2823,7 +2823,7 @@ pub async fn list_payment_connectors(pub async fn update_connector(state: SessionState,- merchant_id: &id_type::MerchantId,+ merchant_id: id_type::MerchantId,profile_id: Option<id_type::ProfileId>,merchant_connector_id: &id_type::MerchantConnectorAccountId,req: api_models::admin::MerchantConnectorUpdate,@@ -2833,14 +2833,14 @@ pub async fn update_connector(let key_store = db.get_merchant_key_store_by_merchant_id(key_manager_state,- merchant_id,+ &merchant_id,&db.get_master_key().to_vec().into(),).await.to_not_found_response(errors::ApiErrorResponse::MerchantAccountNotFound)?;let merchant_account = db- .find_merchant_account_by_merchant_id(key_manager_state, merchant_id, &key_store)+ .find_merchant_account_by_merchant_id(key_manager_state, &merchant_id, &key_store).await.to_not_found_response(errors::ApiErrorResponse::MerchantAccountNotFound)?;@@ -2848,7 +2848,7 @@ pub async fn update_connector(.clone().get_merchant_connector_account_from_id(db,- merchant_id,+ &merchant_id,merchant_connector_id,&key_store,key_manager_state,@@ -2892,7 +2892,7 @@ pub async fn update_connector(})?;// redact cgraph cache on connector updation- redact_cgraph_cache(&state, merchant_id, &profile_id).await?;+ redact_cgraph_cache(&state, &merchant_id, &profile_id).await?;// redact routing cache on connector updation#[cfg(feature = "v1")]@@ -2906,7 +2906,7 @@ pub async fn update_connector(),merchant_connector_id: &mca.get_id(),store: db,- merchant_id,+ merchant_id: &merchant_id,profile_id: &mca.profile_id,transaction_type: &mca.connector_type.into(),};@@ -3779,12 +3779,18 @@ pub async fn list_profile(pub async fn retrieve_profile(state: SessionState,profile_id: id_type::ProfileId,+ merchant_id: id_type::MerchantId,key_store: domain::MerchantKeyStore,) -> RouterResponse<api_models::admin::ProfileResponse> {let db = state.store.as_ref();let business_profile = db- .find_business_profile_by_profile_id(&(&state).into(), &key_store, &profile_id)+ .find_business_profile_by_merchant_id_profile_id(+ &(&state).into(),+ &key_store,+ &merchant_id,+ &profile_id,+ ).await.to_not_found_response(errors::ApiErrorResponse::ProfileNotFound {id: profile_id.get_string_repr().to_owned(),@@ -4197,6 +4203,7 @@ impl ProfileUpdateBridge for api::ProfileUpdate {pub async fn update_profile(state: SessionState,profile_id: &id_type::ProfileId,+ merchant_id: id_type::MerchantId,key_store: domain::MerchantKeyStore,request: api::ProfileUpdate,) -> RouterResponse<api::ProfileResponse> {@@ -4204,7 +4211,12 @@ pub async fn update_profile(let key_manager_state = &(&state).into();let business_profile = db- .find_business_profile_by_profile_id(key_manager_state, &key_store, profile_id)+ .find_business_profile_by_merchant_id_profile_id(+ key_manager_state,+ &key_store,+ &merchant_id,+ profile_id,+ ).await.to_not_found_response(errors::ApiErrorResponse::ProfileNotFound {id: profile_id.get_string_repr().to_owned(),diff --git a/crates/router/src/core/connector_onboarding/paypal.rs b/crates/router/src/core/connector_onboarding/paypal.rsindex 407f62f1ec..1181a11660 100644--- a/crates/router/src/core/connector_onboarding/paypal.rs+++ b/crates/router/src/core/connector_onboarding/paypal.rs@@ -185,7 +185,7 @@ pub async fn update_mca(feature_metadata: None,};let mca_response =- admin::update_connector(state.clone(), &merchant_id, None, &connector_id, request).await?;+ admin::update_connector(state.clone(), merchant_id, None, &connector_id, request).await?;match mca_response {ApplicationResponse::Json(mca_data) => Ok(mca_data),diff --git a/crates/router/src/routes/admin.rs b/crates/router/src/routes/admin.rsindex 6b88db236f..45fef06821 100644--- a/crates/router/src/routes/admin.rs+++ b/crates/router/src/routes/admin.rs@@ -528,7 +528,7 @@ pub async fn connector_create(create_connector(state, req, merchant_context, auth_data.profile_id)},auth::auth_type(- &auth::HeaderAuth(auth::ApiKeyAuthWithMerchantIdFromRoute(merchant_id.clone())),+ &auth::ApiKeyAuthWithMerchantIdFromRoute(merchant_id.clone()),&auth::JWTAuthMerchantFromRoute {merchant_id: merchant_id.clone(),required_permission: Permission::ProfileConnectorWrite,@@ -602,13 +602,13 @@ pub async fn connector_retrieve(|state, auth, req, _| {retrieve_connector(state,- req.merchant_id,+ auth.merchant_account.get_id().clone(),auth.profile_id,req.merchant_connector_id,)},auth::auth_type(- &auth::HeaderAuth(auth::ApiKeyAuthWithMerchantIdFromRoute(merchant_id.clone())),+ &auth::ApiKeyAuthWithMerchantIdFromRoute(merchant_id.clone()),&auth::JWTAuthMerchantFromRoute {merchant_id,// This should ideally be ProfileConnectorRead, but since this API responds with@@ -714,9 +714,11 @@ pub async fn connector_list(state,&req,merchant_id.to_owned(),- |state, _auth, merchant_id, _| list_payment_connectors(state, merchant_id, None),+ |state, auth, _, _| {+ list_payment_connectors(state, auth.merchant_account.get_id().clone(), None)+ },auth::auth_type(- &auth::HeaderAuth(auth::ApiKeyAuthWithMerchantIdFromRoute(merchant_id.clone())),+ &auth::ApiKeyAuthWithMerchantIdFromRoute(merchant_id.clone()),&auth::JWTAuthMerchantFromRoute {merchant_id,required_permission: Permission::MerchantConnectorRead,@@ -746,15 +748,15 @@ pub async fn connector_list_profile(state,&req,merchant_id.to_owned(),- |state, auth, merchant_id, _| {+ |state, auth, _, _| {list_payment_connectors(state,- merchant_id,+ auth.merchant_account.get_id().clone(),auth.profile_id.map(|profile_id| vec![profile_id]),)},auth::auth_type(- &auth::HeaderAuth(auth::ApiKeyAuthWithMerchantIdFromRoute(merchant_id.clone())),+ &auth::ApiKeyAuthWithMerchantIdFromRoute(merchant_id.clone()),&auth::JWTAuthMerchantFromRoute {merchant_id,required_permission: Permission::ProfileConnectorRead,@@ -791,14 +793,14 @@ pub async fn connector_update(|state, auth, req, _| {update_connector(state,- &merchant_id,+ auth.merchant_account.get_id().clone(),auth.profile_id,&merchant_connector_id,req,)},auth::auth_type(- &auth::HeaderAuth(auth::ApiKeyAuthWithMerchantIdFromRoute(merchant_id.clone())),+ &auth::ApiKeyAuthWithMerchantIdFromRoute(merchant_id.clone()),&auth::JWTAuthMerchantFromRoute {merchant_id: merchant_id.clone(),required_permission: Permission::ProfileConnectorWrite,@@ -831,7 +833,7 @@ pub async fn connector_update(state,&req,payload,- |state, _, req, _| update_connector(state, &merchant_id, None, &id, req),+ |state, _, req, _| update_connector(state, merchant_id.clone(), None, &id, req),auth::auth_type(&auth::V2AdminApiAuth,&auth::JWTAuthMerchantFromRoute {diff --git a/crates/router/src/routes/profiles.rs b/crates/router/src/routes/profiles.rsindex a854a68a2a..4e98172dd2 100644--- a/crates/router/src/routes/profiles.rs+++ b/crates/router/src/routes/profiles.rs@@ -44,7 +44,7 @@ pub async fn profile_create(create_profile(state, req, merchant_context)},auth::auth_type(- &auth::HeaderAuth(auth::ApiKeyAuthWithMerchantIdFromRoute(merchant_id.clone())),+ &auth::ApiKeyAuthWithMerchantIdFromRoute(merchant_id.clone()),&auth::JWTAuthMerchantFromRoute {merchant_id,required_permission: permissions::Permission::MerchantAccountWrite,@@ -125,9 +125,16 @@ pub async fn profile_retrieve(state,&req,profile_id,- |state, auth_data, profile_id, _| retrieve_profile(state, profile_id, auth_data.key_store),+ |state, auth_data, profile_id, _| {+ retrieve_profile(+ state,+ profile_id,+ auth_data.merchant_account.get_id().clone(),+ auth_data.key_store,+ )+ },auth::auth_type(- &auth::HeaderAuth(auth::ApiKeyAuthWithMerchantIdFromRoute(merchant_id.clone())),+ &auth::ApiKeyAuthWithMerchantIdFromRoute(merchant_id.clone()),&auth::JWTAuthMerchantFromRoute {merchant_id: merchant_id.clone(),required_permission: permissions::Permission::ProfileAccountRead,@@ -154,8 +161,19 @@ pub async fn profile_retrieve(state,&req,profile_id,- |state, auth::AuthenticationDataWithoutProfile { key_store, .. }, profile_id, _| {- retrieve_profile(state, profile_id, key_store)+ |state,+ auth::AuthenticationDataWithoutProfile {+ merchant_account,+ key_store,+ },+ profile_id,+ _| {+ retrieve_profile(+ state,+ profile_id,+ merchant_account.get_id().clone(),+ key_store,+ )},auth::auth_type(&auth::AdminApiAuthWithMerchantIdFromHeader,@@ -201,9 +219,17 @@ pub async fn profile_update(state,&req,payload,- |state, auth_data, req, _| update_profile(state, &profile_id, auth_data.key_store, req),+ |state, auth_data, req, _| {+ update_profile(+ state,+ &profile_id,+ auth_data.merchant_account.get_id().clone(),+ auth_data.key_store,+ req,+ )+ },auth::auth_type(- &auth::HeaderAuth(auth::ApiKeyAuthWithMerchantIdFromRoute(merchant_id.clone())),+ &auth::ApiKeyAuthWithMerchantIdFromRoute(merchant_id.clone()),&auth::JWTAuthMerchantAndProfileFromRoute {merchant_id: merchant_id.clone(),profile_id: profile_id.clone(),@@ -245,8 +271,20 @@ pub async fn profile_update(state,&req,payload,- |state, auth::AuthenticationDataWithoutProfile { key_store, .. }, req, _| {- update_profile(state, &profile_id, key_store, req)+ |state,+ auth::AuthenticationDataWithoutProfile {+ merchant_account,+ key_store,+ },+ req,+ _| {+ update_profile(+ state,+ &profile_id,+ merchant_account.get_id().clone(),+ key_store,+ req,+ )},auth::auth_type(&auth::AdminApiAuthWithMerchantIdFromHeader,@@ -299,9 +337,9 @@ pub async fn profiles_list(state,&req,merchant_id.clone(),- |state, _auth, merchant_id, _| list_profile(state, merchant_id, None),+ |state, auth, _, _| list_profile(state, auth.merchant_account.get_id().clone(), None),auth::auth_type(- &auth::HeaderAuth(auth::ApiKeyAuthWithMerchantIdFromRoute(merchant_id.clone())),+ &auth::ApiKeyAuthWithMerchantIdFromRoute(merchant_id.clone()),&auth::JWTAuthMerchantFromRoute {merchant_id,required_permission: permissions::Permission::MerchantAccountRead,@@ -359,15 +397,15 @@ pub async fn profiles_list_at_profile_level(state,&req,merchant_id.clone(),- |state, auth, merchant_id, _| {+ |state, auth, _, _| {list_profile(state,- merchant_id,+ auth.merchant_account.get_id().clone(),auth.profile_id.map(|profile_id| vec![profile_id]),)},auth::auth_type(- &auth::HeaderAuth(auth::ApiKeyAuthWithMerchantIdFromRoute(merchant_id.clone())),+ &auth::ApiKeyAuthWithMerchantIdFromRoute(merchant_id.clone()),&auth::JWTAuthMerchantFromRoute {merchant_id,required_permission: permissions::Permission::ProfileAccountRead,@@ -455,15 +493,15 @@ pub async fn payment_connector_list_profile(state,&req,merchant_id.to_owned(),- |state, auth, merchant_id, _| {+ |state, auth, _, _| {list_payment_connectors(state,- merchant_id,+ auth.merchant_account.get_id().clone(),auth.profile_id.map(|profile_id| vec![profile_id]),)},auth::auth_type(- &auth::HeaderAuth(auth::ApiKeyAuthWithMerchantIdFromRoute(merchant_id.clone())),+ &auth::ApiKeyAuthWithMerchantIdFromRoute(merchant_id.clone()),&auth::JWTAuthMerchantFromRoute {merchant_id,required_permission: permissions::Permission::ProfileConnectorRead,