对每叁个CDS视图

Hi!

对每一个CDS视图,大家都能够通过DCL(Data Control
Language)定义访问调整。在那篇小说中,笔者会介绍ABAP
CDS视图中相当重大的单向:权限管理。

正文的阐释基于自个儿正在使用的S4/HANA 1610 on NW 7.51.

剧情分为多个部分:

  1. 行业内部示例的访谈调节。
  2. 依附PFCG权限成立八个简约的例证。
  3. 包罗CUBE数据类其余CDS深入分析视图。
  4. CDS深入分析查询视图的访谈调节。
  5. 权力对象的并集(UNION)或许夹杂(INTEPRADOSECTION)。

 

正文链接:http://www.cnblogs.com/hhelibeb/p/7427753.html

1. 规范示例的访问调节例子

1) 全访谈示例(Full access

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; }

2) 字面条件示例(Literal conditions

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'; }

3) PFCG权限示例

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'); }

万博manbetx客户端, 权限对象s_carrid可以在作业代码SU21中的BC_C object类下查到。

4) 字面条件和PFCG权限结合示例

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'; }

5) 承接权限示例

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'; }

在那几个例子会突显USD和EU陆风X8类型货币的记录。

6) 依据当下用户的权位调控示范

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; }

2. 基于PFCG权限创制几个粗略的例证

复制以下代码,创造我们和睦的CDS视图:

@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
 };   

3,以往,假如在HANA
Studio中打开数据预览,大家将得以看来具有记录。访问调控近日还不设有。

万博manbetx客户端 1

2,在SU21创立我们团结的自定义权限对象:

万博manbetx客户端 2

对此每一个对象定义权限字段和运动字段,出席允许活动“03
显示”。在本示例中,大家要在ZS_CONNID中加多字段CAHighlander奥迪Q7ID和CONNID。

万博manbetx客户端 3

万博manbetx客户端 4

3,为ZS_CA凯雷德EvoqueID创设数量调控。

@MappingRole: true
define role zdemo_access_pfcg {
  grant select on Zdemo_Access_Pfcg
  where (carrid) =
  aspect pfcg_auth (zs_carrid, carrid, actvt='03'); }

4,在PFCG中开创一个新的剧中人物,在此地充分刚刚创造的权位对象,定义用户应当看到的依据选用字段的多寡。不要忘记生成配置。为我们的用户分配剧中人物。

在第贰个示范中,大家只使用ZS_CA奔驰M级卡宴ID。在篇章的背后,大家会用到其余的对象。

万博manbetx客户端 5

万博manbetx客户端 6

5,回到HANA Studio来测量试验权限。张开大家的CDS视图的数额预览:

万博manbetx客户端 7

前几日大家只看到了概念好的宇宙航行公司(CA摩尔根Plus 4CRUISERID)字段的记录。

注意:

  1. 若果在ABAP字典(SE11)中展开视图,结果会是全部数量记录。
  2. 设若在DDL中期维修改注明为如下内容,并激活CDS视图,大家将能够重新在数据预览中看看任何数据。那意味检查已经倒闭。

    @AccessControl.authorizationCheck: #NOT_ALLOWED

结论:在二个从数据库表中查询数据的简便例子中,大家看看了访谈调节是什么行事的。上面讲讲CDS深入分析视图。

3. 涵盖CUBE数据类其他CDS深入分析视图

1,通过复制已部分内容创建大家和好的CDS视图。那是一个富含CUBE数据分类的CDS视图(译注:代码框出了点难点,我们聚拢看下..):

 

@AbapCatalog.sqlViewName: 'Z05_CFLIGHTAQ'                       // Name of the CDS database view in the ABAP Repository
@AccessControl.authorizationCheck: #CHECK              // CDS authorizations, controls the authorization check. In S4H410 not required
@EndUserText.label: 'Available Flights'                         // Translatable short text. Max 60characters. Text label is exposed to Analytica tools and the OData service
@VDM.viewType: #CONSUMPTION                                     // This is a CONSUMPTION view
@Analytics.query: true                                          // By tagging the CDS view as an analytical query it will be exposed to the analytic manager
@OData.publish: true                                            // Generates a suitable OData service, that will use the analytical query, when the CDS entity is activated

define view Z05_C_FlightByAirportQuery as select from Z05_I_FlightByAirport     // A analytical query CDS is implemented using a query select from CDS view Z00_I_FlightByAirport
                                                                                // Take care with OData publishing the max. lenght is 26 characters
{
    @AnalyticsDetails.query.axis: #ROWS                         // Defines the default row/colums apperance for the column Airline
    Z05_I_FlightByAirport.Airline,                              // Use the column Airline
    @AnalyticsDetails.query.axis: #ROWS                         // Defines the default row/colums apperance for the column FlightConnection
    Z05_I_FlightByAirport.FlightConnection,                     // Use the column FlightConnection
    @AnalyticsDetails.query.axis: #ROWS                         // Defines the default row/colums apperance for the column FlightDate
    Z05_I_FlightByAirport.FlightDate,                           // Use the column FlightDate
    @Consumption.filter: {selectionType: #SINGLE, multipleSelections: false, mandatory: false }  // Creates a mandatory filter on the values in the field AirportFrom
    @AnalyticsDetails.query.axis: #ROWS                         // Defines the default row/colums apperance for the column AirportFrom
    @EndUserText.label: 'Departure Airport'                     // Add an human readable enduser label to make sure that we can differentiate between AirportFrom and AirportTo
    Z05_I_FlightByAirport.AirportFrom,                          // Use the column AirportFrom
    @Consumption.filter: {selectionType: #SINGLE, multipleSelections: false, mandatory: false } //  Creates an optional filter on the values in the field AirportTo
    @AnalyticsDetails.query.axis: #ROWS                         // Defines the default row/colums apperance for the column AirportTo
    @EndUserText.label: 'Arrival Airport'                       // Add an human readable enduser label to make sure that we can differentiate between AirportFrom and AirportTo 
    Z05_I_FlightByAirport.AirportTo,                            // Use the column AirportTo                             
    Z05_I_FlightByAirport.Currency,                             // Use the column Currency  
    Z05_I_FlightByAirport.AircraftType,                         // Use the column AircraftType
    @AnalyticsDetails.query.axis: #COLUMNS                      // Defines the default row/colums apperance for the column FlightPrice
    Z05_I_FlightByAirport.FlightPrice,                          // Use the column FlightPrice
    Z05_I_FlightByAirport.MaximumNumberOfSeats,                 // Use the column MaximumNumberOfSeats
    Z05_I_FlightByAirport.NumberOfOccupiedSeats,                // Use the column NumberOfOccupiedSeats
    @DefaultAggregation: #FORMULA                               // Important to know for formular placement is evaluation time. Inside the final query, the evaluation is done after the flightbyairport
                                                                // view aggragation, so it's not on a very detailed level or even row level, but at the aggragate level. This is important for avarages 
                                                                // as they cannot be evaluated at the detail level 
    @EndUserText.label: 'Available Seats'
    @AnalyticsDetails.query.axis: #COLUMNS                      // Defines the default row/colums apperance for the column NumberOfAvailableSeats
    Z05_I_FlightByAirport.MaximumNumberOfSeats - Z05_I_FlightByAirport.NumberOfOccupiedSeats as NumberOfAvailableSeats  // this is a formular (calculated column) 
} 

2,在访谈调整中举行定义:

@EndUserText.label: 'Role for Z05_I_FLIGHTBYAIRPORT'
@MappingRole: true
define role Z05_ROLE {
    grant select on Z05_I_FlightByAirport
    where ( Airline ) = 
    aspect pfcg_auth (  ZS_CARRID,
                        CARRID,
                        actvt = '03' );

}

3,在文章的第2有个别,大家在权力对象中加多了ZS_CA中华V本田UR-VID。在HANA
Studio的数据预览中检查结果。行数是530.万博manbetx客户端 8

 

4,在作业代码ENVISIONSRT中检查结果,行数也是530。结果一律。

5,在BO Analysis for
Excel中检查结果。结果是同一的,对用户来讲,独有选中的航空集团得以被访谈。

 万博manbetx客户端 9

注意:没有AF航空集团的事体数据,那是地点的显示器未出示相关数据的缘故。

4. CDS解析查询视图的采访调节。

1,在首盘部的CUBE CDS中创建三个剖判查询视图。

@AbapCatalog.sqlViewName: 'Z05_CFLIGHTAQ'                       // Name of the CDS database view in the ABAP Repository
@AccessControl.authorizationCheck: #CHECK              // CDS authorizations, controls the authorization check. In S4H410 not required
@EndUserText.label: 'Available Flights'                         // Translatable short text. Max 60characters. Text label is exposed to Analytica tools and the OData service
@VDM.viewType: #CONSUMPTION                                     // This is a CONSUMPTION view
@Analytics.query: true                                          // By tagging the CDS view as an analytical query it will be exposed to the analytic manager
@OData.publish: true                                            // Generates a suitable OData service, that will use the analytical query, when the CDS entity is activated

define view Z05_C_FlightByAirportQuery as select from Z05_I_FlightByAirport     // A analytical query CDS is implemented using a query select from CDS view Z00_I_FlightByAirport
                                                                                // Take care with OData publishing the max. lenght is 26 characters
{
    @AnalyticsDetails.query.axis: #ROWS                         // Defines the default row/colums apperance for the column Airline
    Z05_I_FlightByAirport.Airline,                              // Use the column Airline
    @AnalyticsDetails.query.axis: #ROWS                         // Defines the default row/colums apperance for the column FlightConnection
    Z05_I_FlightByAirport.FlightConnection,                     // Use the column FlightConnection
    @AnalyticsDetails.query.axis: #ROWS                         // Defines the default row/colums apperance for the column FlightDate
    Z05_I_FlightByAirport.FlightDate,                           // Use the column FlightDate
    @Consumption.filter: {selectionType: #SINGLE, multipleSelections: false, mandatory: false }  // Creates a mandatory filter on the values in the field AirportFrom
    @AnalyticsDetails.query.axis: #ROWS                         // Defines the default row/colums apperance for the column AirportFrom
    @EndUserText.label: 'Departure Airport'                     // Add an human readable enduser label to make sure that we can differentiate between AirportFrom and AirportTo
    Z05_I_FlightByAirport.AirportFrom,                          // Use the column AirportFrom
    @Consumption.filter: {selectionType: #SINGLE, multipleSelections: false, mandatory: false } //  Creates an optional filter on the values in the field AirportTo
    @AnalyticsDetails.query.axis: #ROWS                         // Defines the default row/colums apperance for the column AirportTo
    @EndUserText.label: 'Arrival Airport'                       // Add an human readable enduser label to make sure that we can differentiate between AirportFrom and AirportTo 
    Z05_I_FlightByAirport.AirportTo,                            // Use the column AirportTo                             
    Z05_I_FlightByAirport.Currency,                             // Use the column Currency  
    Z05_I_FlightByAirport.AircraftType,                         // Use the column AircraftType
    @AnalyticsDetails.query.axis: #COLUMNS                      // Defines the default row/colums apperance for the column FlightPrice
    Z05_I_FlightByAirport.FlightPrice,                          // Use the column FlightPrice
    Z05_I_FlightByAirport.MaximumNumberOfSeats,                 // Use the column MaximumNumberOfSeats
    Z05_I_FlightByAirport.NumberOfOccupiedSeats,                // Use the column NumberOfOccupiedSeats
    @DefaultAggregation: #FORMULA                               // Important to know for formular placement is evaluation time. Inside the final query, the evaluation is done after the flightbyairport
                                                                // view aggragation, so it's not on a very detailed level or even row level, but at the aggragate level. This is important for avarages 
                                                                // as they cannot be evaluated at the detail level 
    @EndUserText.label: 'Available Seats'
    @AnalyticsDetails.query.axis: #COLUMNS                      // Defines the default row/colums apperance for the column NumberOfAvailableSeats
    Z05_I_FlightByAirport.MaximumNumberOfSeats - Z05_I_FlightByAirport.NumberOfOccupiedSeats as NumberOfAvailableSeats  // this is a formular (calculated column) 
} 

 

2,在HANA
Studio中展开数量预览,行数还是4894。看起来CDS剖析查询未有采取到Cube
CDS视图权限,但是事实并不是那样。你并没有要求为解析查询CDS视图创造额外的访谈调控。

3,在Excel中检查福特ExplorerSRT也许BO分析的结果。结果申明Cube
CDS视图的权柄在条分缕析查询中起到了职能。

万博manbetx客户端 10

瞩目:在剖析查询定义中不要求创立任何变量,就如大家在含有权限的BEx查询中那么。

4,修改Cube CDS视图,增添权力对象ZS_CONNID而非ZS_CARRID

@EndUserText.label: 'Role for Z05_I_FLIGHTBYAIRPORT'
@MappingRole: true
define role Z05_ROLE {
    grant select on Z05_I_FlightByAirport
     where ( FlightConnection) = aspect pfcg_auth (  ZS_CONNID,
                                                     CONNID,
                                                     actvt = '03' );

}

剖析查询结果变得严厉了(在第2有的的第4步能够观看ZS_CONNID的定义).

后天结果的行数是212.

万博manbetx客户端 11

5. 权力的并集(UNION)和混合(INTE昂科威SECTION)

1,通过“AND”取权限的搅拌。这里定义了三个新的权杖“ZS_FLDAT”,它只含有3天的界定(二〇一四.02.04

  • 二零一六.02.06)。修改DCL,扩大混合:

    @EndUserText.label: ‘Role for Z05_I_FLIGHTBYAIRPORT’
    @MappingRole: true
    define role Z05_ROLE {

      grant select on Z05_I_FlightByAirport
       where ( Airline) = 
              aspect pfcg_auth (  ZS_CARRID,
                                  CARRID,
                                  actvt = '03' ) AND
             (FlightDate ) = 
              aspect pfcg_auth (  ZS_FLDAT,
                                  FLTDATE,
                                  actvt = '03' );
    

    }

万博manbetx客户端 12

2,通过“OR”取并集:

@EndUserText.label: 'Role for Z05_I_FLIGHTBYAIRPORT'
@MappingRole: true
define role Z05_ROLE {
    grant select on Z05_I_FlightByAirport
     where ( Airline) = 
            aspect pfcg_auth (  ZS_CARRID,
                                CARRID,
                                actvt = '03' ) OR
           ( FlightDate ) = 
            aspect pfcg_auth (  ZS_FLDAT,
                                FLTDATE,
                                actvt = '03' );

}

万博manbetx客户端 13

 3,假设在几个权力对象中增多那五个字段,那结果就类似于交集:

万博manbetx客户端 14

@EndUserText.label: 'Role for Z05_I_FLIGHTBYAIRPORT'
@MappingRole: true
define role Z05_ROLE {
    grant select on Z05_I_FlightByAirport
     where ( Airline, FlightDate) = 
            aspect pfcg_auth (  ZS_NEW,
                                CARRID,
                                FLTDATE,
                                actvt = '03' );

万博manbetx客户端 15

注意:一遍遍地思念在Cube
CDS视图的层级定义权限,而非分析视图层级。
一经您在条分缕析查询层级定义了和第5片段一律的权杖,那么:

  • 在SAP HANA Studio的数码预览中,结果看起来是对的。
  • 在KugaSRT, BO Analysis for
    Excel和别的使用了OLAP引擎的工具中,使用的是Cube
    CDS视图的权力(如有定义)。

注意:在HANA
Studio的多少预览中,深入分析查询的结果会整整来得。为了纠正那一点,可以给深入分析查询创造以下访谈调节:

@MappingRole: true
define role Z05_ROLE_2 {
  grant select on Z05_C_FlightByAirportQuery 
               inherit Z05_ROLE; }

敲定:你可感到CDS解析视图定义权限的交集也许并集。

 

本文截至,感激关心!

 

英文原稿:ABAP CDS views with Authorization based on Access
Control