Exercise Objectives
After completing this exercise, you will be able to:
Create an analytic privilege
Secure a view with an analytic privilege
Business Example
You have finished creating a number of calculation views, and you need to secure the data access for these views before they are moved to the QA environment for testing.
Overview of Exercise Tasks
- Import a Calculation View
- Preview the Data with your User
- Create an Analytic Privilege
- Modify a Calculation View to Enable Analytic Privileges Check
- Preview the Calculation View Data
Prerequisites
Prerequisites
You should have created a development space into SAP Business Application Studio, imported and deployed the existing HC300 project (HC300_A####), and created the analytic privilege AP_COUNTRY_US.
Task 1: Import a Calculation View
You will first import a Calculation View and check that you can display its data.
Steps
In SAP Business Application Studio, import the CVCS_PO2.hdbcalculationview file from your course files folder HC300 into your HC300_A#### project, in the view tree folder src→models→exercises.
Expand your HC300_A#### project to open the db→src→models folder.
In the Explorer view, right-click your exercises folder and choose Upload.
In the dialog box, select the HC300→Calculation Views Templates→CVCS_PO2.hdbcalculationview file and choose Open.
Result
The new Calculation View CVCS_PO2 is created in your project.
Deploy the CVCS_PO2 view.
In the SAP Hana Projects sub-pane, expand the foldersrc→models→exercises.
Hover your mouse on the new (imported) view and choose
Deploy.In the terminal, check that the build was successful.
Preview the calculation view data.
It should retrieve data for several countries.
In the Explorer view tree, right-click the new (imported) view and choose Data Preview.
Check that the view retrieves data.
Task 2: Preview the Data with your User A####
From now on, and during the remainder of the exercise, you will preview the data with your A#### user, using the Data Preview with Other Database User, so that you can correctly test the behavior of the view while you’re defining data access security for this view.
Note
Indeed, due to the containerization, the standard data preview from the Explorer view is executed by a technical user, NOT your connected user A####.
An alternative could be to execute a SQL query on top of the Calculation View in the Database Explorer, but this time with the connection to the HC300_DB (A####) (SSO enabled), not to the HDI Container.
Steps
If needed, open the calculation view CVCS_PO2.
In the Explorer view, double-click the view CVCS_PO2.hdbcalculationview.
Execute the data preview from the calculation view editor, with your A#### user.
You actually choose a connection (HC300_DB) and the associated user (A####) or (SSO enabled) from the connections list of Database Explorer.
Right-click the Star Join node and choose Data Preview with Other Database User.
In the Select Database With User, choose the connection HC300_DB (A####) (SSO enabled).
Result
The calculation view opens in data preview mode in a new tab.In the Analysis tab, assign the column COUNTRY_NAME to the Label axis and the column GROSS_AMOUNT to the Value axis.
Leave the data preview ta open. This will allow you to refresh the data preview while setting up your analytic privileges.
Task 3: Create an Analytic Privilege
You want to limit the visibility of data for this calculation view to the purchase orders from customers located in the US.
Steps
Create a new analytic privilege in the src/models/exercises folder, with the following properties:
Analytic Privilege Properties
Field Value Name AP_COUNTRY_US Label US Partners Right-click your exercises folder and choose New File.
Enter the name AP_COUNTRY_US.hdbanalyticprivilege.
Result
The analytic privilege opens in a new tab.To rename the description, top-right of the analytic privilege editor, choose Rename.
Enter the Label as per the table and choose OK.
Reference the view CVCS_PO2 so that it is secured by this analytic privilege.
In the Secured Models area, choose the +(add) icon.
In the Find Data Sources field, enter PO2.
Select the HC::CVCS_PO2 view and choose Finish.
Define the analytic privilege restriction.
Add a restriction to limit the data for business partners located in the US.
In the Associated Attribute Restrictions area, choose +(add).
In the Attribute window, choose the COUNTRY attribute from the shared dimension view HC::CVD_BP2 and choose OK.
In the Restriction Type column, click the + icon.
In the Operator field, choose =.
In the Value, select US and choose OK.
Save and deploy the new analytic privilege.
Check the build status.
Choose Save if needed.
In the SAP HANA Projects window, click the AP_COUNTRY_US analytic privilege and choose Deploy.
Result
The build fails.
Task 4: Modify a Calculation View to Enable Analytic Privileges Check
You must modify the calculation view secured by the AP_COUNTRY_US privilege before you include this view in the list of models this analytic privilege secures.
Steps
Modify the calculation view CVCS_PO2 so that it triggers an analytic privilege check when it is queried.
Hint
This is done in the View Properties tab of Semantics.If needed, open the exercises→CVCS_PO2 calculation view.
In Semantics, display the View Properties tab.
In the Apply Privileges drop-down list, choose SQL Analytic Privileges.
Save and deploy the CVCS_PO2 calculation view.
Check the build status.
Choose Save if needed.
In the SAP HANA Projects window, click the CVCS_PO2 calculation view and choose Deploy.
Deploy again the AP_COUNTRY_US analytic privilege.
In the SAP HANA Projects window, click the AP_COUNTRY_US analytic privilege and choose Deploy..
Check the build status.
Result
This time, the build is successful. As a conclusion, all the views that an analytic privilege secures must have the analytic privilege check enabled, and they must be built (runtime object must exist) before you can actually build this analytic privilege.
Task 5: Preview the Calculation View Data
You will now refresh the data preview tab to see if your analytic privilege definition has been applied.
Steps
Refresh the data preview and analyze the results.
In the former data preview tab, to refresh the data, choose Execute.
Get ready for the next exercise where you create and assign a new role, including the new analytic privilege, to your user, so that he can access the authorized data of the calculation view CVCS_PO2.