28.01.2013 Views

SAP HANA Developer Guide - Get a Free Blog

SAP HANA Developer Guide - Get a Free Blog

SAP HANA Developer Guide - Get a Free Blog

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

1. Create the table type for the output parameter of the procedure:<br />

CREATE TYPE "AUTHORIZATION"."PRODUCT_OUTPUT" AS TABLE("PRODUCT" int);<br />

2. Create the table that the procedure will use to check authorization:<br />

CREATE TABLE "AUTHORIZATION","PRODUCT_AUTHORIZATION_TABLE" ("USER_NAME"<br />

NVARCHAR(128), "PRODUCT" int);<br />

3. Create the procedure that will determine which products the database user executing the query is authorized<br />

to see based on information contained in the product authorization table:<br />

CREATE PROCEDURE "AUTHORIZATION"."DETERMINE_AUTHORIZED_PRODUCT_FOR_USER"<br />

(OUT VAL "AUTHORIZATION"."PRODUCT_OUTPUT")<br />

LANGUAGE SQLSCRIPT SQL SECURITY DEFINER READS SQL DATA AS<br />

BEGIN<br />

VAL = SELECT PRODUCT FROM<br />

"AUTHORIZATION"."PRODUCT_AUTHORIZATION_TABLE” WHERE USER_NAME =<br />

SESSION_USER;<br />

END;<br />

Note: The session user is the database user who is executing the query to access a secured view. This<br />

is therefore the user whose privileges must be checked. For this reason, the table or view used in the<br />

procedure should contain a column to store the user name so that the procedure can filter on this<br />

column using the SQL function SESSION_USER.<br />

4. Create the analytic privilege:<br />

340<br />

CREATE STRUCTURED PRIVILEGE '<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

';<br />

P U B L I C<br />

© 2012 <strong>SAP</strong> AG. All rights reserved.<br />

<strong>SAP</strong> <strong>HANA</strong> <strong>Developer</strong> <strong>Guide</strong><br />

Setting Up Roles and Authorizations

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!