In high-security environments, standard PFCG roles often aren't granular enough. Today, we’ll look at a sophisticated way to implement Row-Level Security using User-Defined Aspects. We'll walk through a real-world scenario: restricting Purchase Requisition items so users only see data for their authorized cost centers.
Now there's no such authorization object exists in SAP.
zp2p_cc_user) in a CDS view.@AccessControl.auditing annotations.@AbapCatalog.viewEnhancementCategory: [#NONE]
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Cost Center and Authorized Users'
@Metadata.ignorePropagatedAnnotations: true
@AccessControl.auditing.type: #CUSTOM
@AccessControl.auditing.specification: 'Custom cost center authorization table audited via logging'
define view entity ZI_CostCenterUser
as select from zp2p_cc_user
{
key kostl as CostCenter,
key uname as UserName
}C_PurReqnItemMntr might not expose the CostCenter field by default. We use a CDS Extension to inject this field without modifying the standard SAP object.@AbapCatalog.sqlViewAppendName: 'ZIEXTPRMNTR'
@EndUserText.label: 'Extension for Cost Center'
extend view C_PurReqnItemMntr with zi_ext_c_purreqnitemmntr
association [0..1] to ZI_PRCostCenter as _PRCostCenter on _PRCostCenter.PurchaseRequisition = $projection.purchaserequisition
{
_PRCostCenter.CostCenter as CostCenterAcc
}WITH USER ELEMENT to bind the current system user to your table's username field.@EndUserText.label: 'Aspect for User Cost Center'
define accesspolicy ZV_UserCostCenter {
define aspect ZV_UserCostCenter as select from
ZI_CostCenterUser with user element UserName
{
CostCenter
}
}ASPECT keyword to dynamically pull values from our Access Policy.@MappingRole: true
define role ZI_PURCHASEREQUISITIONITEM {
grant select on C_PurReqnItemMntr
combination mode AND
where ( CostCenterAcc ) = ASPECT ZV_UserCostCenter;
}ST05 Trace will show that the Aspect is being used while fetching the data.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 14 | |
| 13 | |
| 12 | |
| 10 | |
| 10 | |
| 9 | |
| 8 | |
| 8 | |
| 7 | |
| 6 |