ABAP CDS Views With Authorization Based On Access Control
ABAP CDS Views With Authorization Based On Access Control
Part III. Access control for analytical CDS views with CUBE data category
________________________________________________________________________________
First of all I recommend to begin with standard demo CDS views in SABAPDEMOS package based
on Flight Model.
DDL:
@AbapCatalog.sqlViewName: 'DEMO_CDS_FULLACC'
@AccessControl.authorizationCheck: #CHECK
define view demo_cds_auth_fullaccess
as select from
scarr
{
key carrid,
carrname,
currcode,
url
};
DCL:
@MappingRole: true
define role demo_cds_role_fullaccess {
grant select on demo_cds_auth_fullaccess; }
DDL:
@AbapCatalog.sqlViewName: 'DEMO_CDS_LITERAL'
@AccessControl.authorizationCheck: #CHECK
define view demo_cds_auth_literal
as select from
scarr
{
key carrid,
carrname,
currcode,
url
};
DCL:
@MappingRole: true
define role demo_cds_role_literal {
grant select on demo_cds_auth_literal
where carrid = 'LH'; }
DDL:
@AbapCatalog.sqlViewName: 'DEMO_CDS_PFCG'
@AccessControl.authorizationCheck: #CHECK
define view demo_cds_auth_pfcg
as select from
scarr
{
key carrid,
carrname,
currcode,
url
};
DCL:
@MappingRole: true
define role demo_cds_role_pfcg {
grant select on demo_cds_auth_pfcg
where (carrid) =
aspect pfcg_auth (s_carrid, carrid, actvt='03'); }
DDL:
@AbapCatalog.sqlViewName: 'DEMO_CDS_LITPFCG'
@AccessControl.authorizationCheck: #CHECK
define view demo_cds_auth_lit_pfcg
as select from
scarr
{
key carrid,
carrname,
currcode,
url
};
DCL:
@MappingRole: true
define role demo_cds_role_lit_pfcg {
grant select on demo_cds_auth_lit_pfcg
where (carrid) =
aspect pfcg_auth (s_carrid, carrid, actvt='03') and
currcode = 'EUR'; }
DDL:
@AbapCatalog.sqlViewName: 'DEMO_CDS_INH'
@AccessControl.authorizationCheck: #CHECK
define view demo_cds_auth_inherited
as select from
demo_cds_auth_lit_pfcg
{
key carrid,
carrname,
currcode,
url
};
DCL:
@MappingRole: true
define role demo_cds_role_inherited {
grant select on demo_cds_auth_inherited
inherit demo_cds_role_lit_pfcg or currcode = 'USD'; }
DDL:
@AbapCatalog.sqlViewName: 'DEMO_CDS_USR'
@AccessControl.authorizationCheck: #CHECK
define view demo_cds_auth_user
as select from
abdocmode
{
key uname,
key langu,
flag
};
DCL:
@MappingRole: true
define role demo_cds_role_user {
grant select on demo_cds_auth_user
where
uname ?= aspect user; }
In this example data records will be filtered based on user name accessing CDS view.
Conclusion of Part 1: we considered standard demo examples with different options, let’s try to
create our own CDS view with access control.
________________________________________________________________________________
@AbapCatalog.sqlViewName: 'ZDEMO_CDS_PFCG'
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Demo access pfcg'
define view Zdemo_Access_Pfcg as select from scarr
{
key carrid,
carrname,
currcode,
url
};
Now if we open data preview in HANA Studio we will see all records. Access control doesn’t exist
yet.
For each object define authorization field(s) and Activity field, include in permitted activities 03
Display. In our case we include CARRID field in ZS_CARRID and CONNID in ZS_CONNID.
3. Create access control for ZS_CARRID authorization object.
@MappingRole: true
define role zdemo_access_pfcg {
grant select on Zdemo_Access_Pfcg
where (carrid) =
aspect pfcg_auth (zs_carrid, carrid, actvt='03'); }
4. Create a new role in PFCG and include authorization objects here. Define what data based on
selected fields users should see. Don’t forget to generate profile. Assign role to our user.
In first case we will use only ZS_CARRID. We will use another object later in this post.
5. Go back to HANA studio to test authorization. Open data preview for our CDS.
Now we see only records with defined for Airline Company (CARRID) field.
Note: If we open a view in ABAP Dictionary (SE11) the result is all data records.
Note: if we change annotation in DDL, activate CDS view for changes to be applied, we will see all
records in data preview once again. This means that a check is off.
@AccessControl.authorizationCheck: #NOT_ALLOWED
Conclusion of Part 2: We see how access control is working in simple case of selection from a
table, let’s move to analytic CDS views.
_____________________________________________________________________________
Part III. Access control for analytical CDS views with CUBE data category
1. Create a our own CDS view by coping existing one. This is CDS view with CUBE data category.
/* Associations */
Z00_I_Flight._AircraftType, // The fields from the
association _AircraftType
Z00_I_Flight._Airline, // The fields from the
association _Airline
Z00_I_Flight._FlightConnection, // The fields from the
association _FlightConnection
Z00_I_Flight._FlightConnection._AirportFrom, // This needs to be added
because airportFrom is not available for analytics, because we used it only as a
foreignkey
Z00_I_Flight._FlightConnection._AirportTo // This needs to be added
because airportTo is not available for analytics, because we used it only as a foreignkey
}
Data preview for this CDS view in HANA Studio. Number of rows is 4894.
3. In part II of this post we included ZS_CARRID authorization object to our user. Check result in
data preview in HANA Studio. Number of rows is 530.
4. Check result in RSRT t-code. Number of rows is 530. The same result.
5. Check result in BO Analysis for Excel. The result is the same, only selected Airlines are available
for our user.
Note. There is no transnational data for AF Airline, that’s why it is not shown at the screen above.
________________________________________________________________________________
1. Create an analytical query CDS view in CUBE CDS from Part III.
2. Data preview for this CDS view in HANA Studio. Number of rows is 4894. It seem that CDS view
analytical query is not use Cube CDS view authorization, but it is not true. You don’t need to create
additional access control for analytical query CDS view.
3. Check result in RSRT or BO Analysis for Excel. The results demonstrate that authorizations of
Cube CDS view are used in analytical query.
Note: It is not required to create any variables in analytical query definition, like we did in BEx query
with authorization characteristics.
4. Modify access control for Cube CDS view. Add field authorization object ZS_CONNID instead of
ZS_CARRID.
The analytical query result is more strict (look at ZS_CONNID definition in Part II Step 4). Now
number of rows is 212 in my case.
________________________________________________________________________________
1. Intersection of authorizations with “AND”. New authorization ZS_FLDAT was defined for 3
days range only (04.02.2015 – 06.02.2015). DCL modification for intersection:
}
2. Union of authorizations with “OR”:
Notes: Don’t forget to define authorizations at Cube CDS view level, not analytical query level. If
you define the same authorizations from Part V at analytical query level:
Notes: For analytical query for results in HANA Studio data preview showed all data, to correct this
create access control for analytical query:
@MappingRole: true
define role Z05_ROLE_2 {
grant select on Z05_C_FlightByAirportQuery
inherit Z05_ROLE; }
Conclusion for Part V: You can define intersection or union of authorizations for Analytical CDS
views.