In this article, we will be covering how to implement data security (hiding or allowing access) to certain table/column/row level data from any organization/roles/users/profiles.
In order to implement metadata security, you need to open metadata security tab. To know more, Click Here.
Now. let us understand with an example. Suppose we have different users belonging to the same organization as shown in below image. Image shows the users information such as his / her role, department, region and country.
Following are the steps :
- Create a Metadata. In this case, User 1 creates a metadata.
- Share the metadata with the intended users with the required permission level. In this case, User 1 shares metadata with User A, User B, User C and User D. Similarly, you can share a metadata based on Users, Roles and Profile.
(Note: If a metadata is saved in a folder then you have share its folder, sub-folder ) - On successful sharing of metadata, all users can access the metadata for reports creation.
- Here, all users have access to all tables, columns, data-set present in the metadata.
- Now, let’s say User1 (owner of metadata) wants to control the access of metadata with the users.
- User1 can provide access/restrict specific table data or column data or row level data from a users role, profile, name or organization conditions. A single metadata can have multiple security conditions.
Execution Type : ConditionIf
Table Level Condition
-
- Restrict a Table data from a User : Here we will learn how you can restrict certain table from user.
Expression Name : Hiding table from a user //can be any name Entity Name : Table1 //this is selected table. 1 or more tables can be added Expression Type: table //since we are selecting table Access Type: deny //restricting the data Execution Type: conditionIf Condition : ${user}.name eq 'User A' //this condition to be used for single user. User name is Case sensitive
- Restrict a Table data from a User : Here we will learn how you can restrict certain table from user.
-
- Restrict a Table from a Role : Here we will learn how you can restrict certain table from Roles.
Expression Name : Hiding table from a Role //can be any name Entity Name : Table1 //this is selected table. 1 or more tables can be added Expression Type: table //since we are selecting table Access Type: deny //restricting the data Execution Type: conditionIf Condition : check("${role}.name" , "ROLE_USER") //this condition to be used for single role. Role name is case sensitive check("${role}.name" , "ROLE_USER1, ROLE_USER2,....") //this condition to be used for multiple roles. Role name is case sensitive
- Restrict a Table from a Role : Here we will learn how you can restrict certain table from Roles.
- Hiding a Table from a Profile : Here we will learn how you can restrict certain table from profile.
Expression Name : Hiding table from a Profile //can be any name Entity Name : Table1 //this is selected table. 1 or more tables can be added Expression Type: table //since we are selecting table Access Type: deny //restricting the data Execution Type: conditionIf Condition : check("${profile['ProfileName']}" , "ProfileValue") //this condition to be used for single profile. Profile name is Case sensitive check("${profile['ProfileName']}" , "ProfileValue1, ProfileValue2,....") //this condition to be used for multiple profiles. Profile name is Case sensitive
Column Level Condition
-
- Restrict a column data from a User : Here we will learn how you can restrict certain column from user.
Expression Name : Hiding column from a user //can be any name Entity Name : Column1 //this is selected column. 1 or more tables can be added Expression Type: column //since we are selecting column Access Type: deny //restricting the data Execution Type: conditionIf Condition : ${user}.name eq 'User A' //this condition to be used for single user. User name is Case sensitive
- Restrict a column data from a User : Here we will learn how you can restrict certain column from user.
-
- Restrict a column from a Role : Here we will learn how you can restrict certain column from Roles.
Expression Name : Hiding column from a Role //can be any name Entity Name : Column1 //this is selected column. 1 or more tables can be added Expression Type: column //since we are selecting column Access Type: deny //restricting the data Execution Type: conditionIf Condition : check("${role}.name" , "ROLE_USER") //this condition to be used for single role. Role name is case sensitive check("${role}.name" , "ROLE_USER1, ROLE_USER2,......") //this condition to be used for multiple roles. Role name is case sensitive
- Restrict a column from a Role : Here we will learn how you can restrict certain column from Roles.
- Hiding a column from a Profile : Here we will learn how you can restrict certain column from profile.
Expression Name : Hiding column from a Profile //can be any name Entity Name : Column1 //this is selected column. 1 or more tables can be added Expression Type: column //since we are selecting column Access Type: deny //restricting the data Execution Type: conditionIf Condition : check("${profile['ProfileName']}" , "ProfileValue") //this condition to be used for single profile. Profile name is Case sensitive check("${profile['ProfileName']}" , "ProfileValue1, ProfileValue2,....") //this condition to be used for multiple profiles. Profile name is Case sensitive
Data Level / Row Level Condition
-
- Limiting Data from a User : Here we will learn how to show user specific data to a user.
Expression Name : Limit Data Display from User //can be any name Entity Name : Column1 //this is selected column. 1 or more tables can be added Expression Type: column //since we are selecting column Access Type: grant // granting specified column mentioned in the entity name Execution Type: conditionIf Condition : ${user}.name eq 'User A' //this condition to be used for single user. User name is Case sensitive Filter : Table_Name.column_name = filtercondition meeting_details.meeting_impact = 'Finalized' //it filters the meeting_impact data only having value 'Finalized' which is visible by User A
- Limiting Data from a User : Here we will learn how to show user specific data to a user.
NOTE: Above in filter we have specified a simple filtering condition wherein the value is hardcoded i.e. meeting_details.meeting_impact = ‘Finalized’. Instead of that it is also possible to use a SQLstatement as well (which can futher contian filters, joins, subqueries etc) to fetch the result and then pass it to the filtering condition. In a similar way it can be used in any condition for any kind of filtering (row level, table levle, column level, userwise security, row wise security, column wise security etc)
For example :
meeting_details.meeting_impact = select meeting_impact from meeting_details where emp_id=1;
-
- Limiting Data from a Role : Here we will learn how to show specific data based on the roles assigned to a user.
Expression Name : Limit Data Display from a Role //can be any name Entity Name : Column1 //this is selected column. 1 or more tables can be added Expression Type: column //since we are selecting column Access Type: grant // granting specified column mentioned in the entity name Execution Type: conditionIf Condition : check("${role}.name" , "ROLE_USER") //this condition to be used for single role. Role name is case sensitive check("${role}.name" , "ROLE_USER1, ROLE_USER2,......") //this condition to be used for multiple roles. Role name is case sensitive Filter : Table_Name.column_name = filtercondition employee_details.employee_id between 1 and 12 //it filters employee_id having value 1 to 12 which is visible to a Role specified in the condition.
- Limiting Data from a Role : Here we will learn how to show specific data based on the roles assigned to a user.
-
- Limiting Data from a Profile : Here we will learn how to show specific data to a user based on the profile it is assigned.
Expression Name : Limit Data Display from a Profile //can be any name Entity Name : Column1 //this is selected column. 1 or more tables can be added Expression Type: column //since we are selecting column Access Type: grant // granting specified column mentioned in the entity name Execution Type: conditionIf Condition : not check("${profile['ProfileName']}", "ALL") //this condition to be used for single and also same for multiple profiles. Profile name is Case sensitive Filter : Table_Name.column_name = filtercondition traveldetails.destination = ${profile['Destination']} //it filters destination having value similar to value of profile attribute. traveldetails.destination in (${profile['Destination']}) //it filters destination having multiple values of profile attribute.
- Limiting Data from a Profile : Here we will learn how to show specific data to a user based on the profile it is assigned.
- Limiting Data from Organization : Here we will learn how to show specific data to a user based on the Organization it belongs.
Expression Name : Organization Name Expression //can be any name Entity Name : Column1 //this is selected column. 1 or more tables can be added Expression Type: column //since we are selecting column Access Type: grant // granting specified column mentioned in the entity name Execution Type: conditionIf Condition : ${org}.name != 'Null' //this condition will check if user belongs to any organization or not Filter : Table_Name.column_name = filtercondition meeting_details.client_name = ${org}.name //it filters client_name having value similar to the logged in organization.
Execution Type : Groovy
Table Level Condition
-
- Restrict a Table data from a User : Here we will learn how you can restrict certain table from user.
Expression Name : Hiding table from a user //can be any name Entity Name : Table1 //this is selected table. 1 or more tables can be added Expression Type: table //since we are selecting table Access Type: deny //restricting the data Execution Type: groovy Condition : import com.helicalinsight.adhoc.metadata.GroovyUsersSession; def evalCondition() { String userName = GroovyUsersSession.getValue('${user}.name'); if (userName.equalsIgnoreCase("'User A'")) { return true } else { return false } }
- Restrict a Table data from a User : Here we will learn how you can restrict certain table from user.
-
- Restrict a Table data from an organization : Here we will learn how you can restrict certain table from organization.
Expression Name : Hiding table from an organization //can be any name Entity Name : Table1 //this is selected table. 1 or more tables can be added Expression Type: table //since we are selecting table Access Type: deny //restricting the data Execution Type: groovy Condition : import com.helicalinsight.adhoc.metadata.GroovyUsersSession; def evalCondition() { String orgName = GroovyUsersSession.getValue('${org}.name'); if (!orgName.equals("'Null'")) { return true } else { return false } }
- Restrict a Table data from an organization : Here we will learn how you can restrict certain table from organization.
- Restrict a Table data from Email Expression : Here we will learn how you can restrict certain table using Email.
Expression Name : Hiding table from using Email Expression //can be any name Entity Name : Table1 //this is selected table. 1 or more tables can be added Expression Type: table //since we are selecting table Access Type: deny //restricting the data Execution Type: groovy Condition : import com.helicalinsight.adhoc.metadata.GroovyUsersSession; def evalCondition() { String userEmail = GroovyUsersSession.getValue('${user}.email'); if (userEmail.equals("'bitach@helicaltech.com'")) { return true } else { return false } }
Column Level Condition
-
- Restrict a column data from a User : Here we will learn how you can restrict certain column from user.
Expression Name : Hiding column from a user //can be any name Entity Name : Column1 //this is selected column. 1 or more tables can be added Expression Type: column //since we are selecting column Access Type: deny //restricting the data Execution Type: groovy Condition : import com.helicalinsight.adhoc.metadata.GroovyUsersSession; def evalCondition() { String userName = GroovyUsersSession.getValue('${user}.name'); if (userName.equalsIgnoreCase("'User A'")) { return true } else { return false } }
- Restrict a column data from a User : Here we will learn how you can restrict certain column from user.
-
- Restrict a column from a Role : Here we will learn how you can restrict certain column from Roles.
Expression Name : Hiding column from a Role //can be any name Entity Name : Column1 //this is selected column. 1 or more tables can be added Expression Type: column //since we are selecting column Access Type: deny //restricting the data Execution Type: groovy Condition : import com.helicalinsight.adhoc.metadata.GroovyUsersSession; def evalCondition() { String userName = GroovyUsersSession.getValue('${role}.name'); if (userName. contains( 'ROLE_USER')) { return true } else { return false } }
- Restrict a column from a Role : Here we will learn how you can restrict certain column from Roles.
- Hiding a column from a Profile : Here we will learn how you can restrict certain column from profile.
Expression Name : Hiding column from a Profile //can be any name Entity Name : Column1 //this is selected column. 1 or more tables can be added Expression Type: column //since we are selecting column Access Type: deny //restricting the data Execution Type: groovy Condition : import com.helicalinsight.adhoc.metadata.GroovyUsersSession; def evalCondition() { String profileName = GroovyUsersSession.getValue('${profile[\'ProfileName\']}'); if (profileName.equalsIgnoreCase("'ProfileValue'")) { return true } else { return false } }
Data Level / Row Level Condition
-
- Limiting Data from a User : Here we will learn how to show user specific data to a user.
Expression Name : Limit Data Display from User //can be any name Entity Name : Column1 //this is selected column. 1 or more tables can be added Expression Type: column //since we are selecting column Access Type: grant // granting specified column mentioned in the entity name Execution Type: groovy Condition : import com.helicalinsight.adhoc.metadata.GroovyUsersSession; def evalCondition() { String userName = GroovyUsersSession.getValue('${user}.name'); if (userName.equalsIgnoreCase("'User A'")) { return true } else { return false } } Filter : def evalFilter() { return "meeting_details.meeting_impact = 'Finalized'" }
- Limiting Data from a User : Here we will learn how to show user specific data to a user.
-
- Limiting Data from a Role : Here we will learn how to show specific data based on the roles assigned to a user.
Expression Name : Limit Data Display from a Role //can be any name Entity Name : Column1 //this is selected column. 1 or more tables can be added Expression Type: column //since we are selecting column Access Type: grant // granting specified column mentioned in the entity name Execution Type: groovy Condition : import com.helicalinsight.adhoc.metadata.GroovyUsersSession; def evalCondition() { String userName = GroovyUsersSession.getValue('${role}.name'); if (userName. contains( 'ROLE_USER')) { return true } else { return false } } Filter : def evalFilter() { return "employee_details.address = 'Bhubaneshwar'" }
- Limiting Data from a Role : Here we will learn how to show specific data based on the roles assigned to a user.
-
- Limiting Data from a Profile : Here we will learn how to show specific data to a user based on the profile it is assigned.
Expression Name : Limit Data Display from a Profile //can be any name Entity Name : Column1 //this is selected column. 1 or more tables can be added Expression Type: column //since we are selecting column Access Type: grant // granting specified column mentioned in the entity name Execution Type: groovy Condition : import com.helicalinsight.adhoc.metadata.GroovyUsersSession; def evalCondition() { String profileName = GroovyUsersSession.getValue('${profile[\'ProfileName\']}'); if (profileName.equalsIgnoreCase("'ProfileValue'")) { return true } else { return false } } Filter : def evalFilter(){ return "employee_details.employee_id between 1 and 12"; }
- Limiting Data from a Profile : Here we will learn how to show specific data to a user based on the profile it is assigned.
- Limiting Data from Organization : Here we will learn how to show specific data to a user based on the Organization it belongs.
Expression Name : Organization Name Expression //can be any name Entity Name : Column1 //this is selected column. 1 or more tables can be added Expression Type: column //since we are selecting column Access Type: grant // granting specified column mentioned in the entity name Execution Type: groovy Condition : import com.helicalinsight.adhoc.metadata.GroovyUsersSession; def evalCondition() { String orgName = GroovyUsersSession.getValue('${org}.name'); if (!orgName.equals("'Null'")) { return true } else { return false } } Filter : import com.helicalinsight.adhoc.metadata.GroovyUsersSession; def evalFilter() { String orgName = GroovyUsersSession.getValue('${org}.name'); return "meeting_details.client_name=" + orgName; }
You can refer to the various kind of expressions which we can use while defining the metadata security expressions in this blog. Metadata Security Expressions
Note: Applying metadata security provides DATA Security. However, to make the reports, dashboards, and the metadata itself available to other users for viewing or editing purposes, the said resource needs to be shared with designated users. For more information on how to share resources (reports, dashboards, metadata and datasource) Refer this blog
Post your related queries on our Forum