### Applying RLS to a parameter

When a parameter is bound with another column, you can apply a RLS policy in the data source, which is defined on the bound column, to the parameter, then at runtime, end users will be prompted to enter the security ID, which refers to the user name, and only the records the SID allows to view will be displayed in the parameter value drop-down list.

The following example explains how to apply RLS to the value drop-down list of a parameter in detail.

1. Open the demo catalog SampleReports.cat and in the Catalog Browser, expand the data source where to create the parameter.
2. Right-click the Data Source Security node and then click Add Security.
3. Name the security policy CusCountry and in the Security dialog, check Valid RLS.
4. Click Add to add the user John, which has the permission to view the Canada records in the Country column only.

5. Add another user David which has the permission to view records in the United Kingdom only.

   For details about how to set up a RLS policy, refer to Setting up a connection-scope security policy.

6. In the same data source, right-click the Parameters node and then click Add Parameter.
7. In the Create Parameter dialog, enter pCountry in the Parameter Name field, select Bind with Single Column from the Value Setting drop-down list, and bind the parameter with the Country column. In the Options box, select CusCountry as value of Record Level Security, and then set the Distinct option to true.
8. Create a query CustomersInfo on the table Customers. Select all the fields contained in the table.
9. Create a standard banded report based on the query, and have the fields Customer ID, Customer Name, Country and Phone displayed in the report.
10. In the Resource View panel, right-click the node that represents the query, and then select Edit Query from the shortcut menu.
11. In the Query Editor, click Query > Filter.
12. In the Search Condition dialog, add a condition for the query as below (for details, see Filtering with the filter format):

13. Click OK to apply the changes to the query.
14. View the report, and in the Security Identifier dialog, enter John and click OK, the Enter Parameter Values dialog will then be displayed.
15. Click the parameter value drop-down list, and you can see that only Canada is displayed for the user SID.
16. View the report again and this time enter the user SID David. You will find that only the value United Kingdom is displayed in the parameter value drop-down list this time.

Notes:

- When applying a RLS policy to a parameter bound with a column, you must make sure the parameter bound column and the column used to set condition in the RLS policy are in the same table. In addition, if the RLS policy also contains conditions defined on other columns, all the columns must be in the same table, and the RLS policy cannot contain parameters/formulas; otherwise, when you apply the RLS to the parameter, the RLS would not work properly.
- When you have applied a RLS policy to a parameter and then you click the SQL button in the Create Parameter dialog to edit the SQL statement of the parameter, the parameter value drop-down list would be Null because the changed SQL statement maybe disagree with the permissions of the RLS.
- To have the RLS applied to a parameter work on JReport Enterprise Server, the users for the RLS must be imported from the server. If the users are created in JReport Designer, you need to first create these users on JReport Enterprise Server, and then in JReport Designer, synchronize the security information with JReport Enterprise Server by means of importing security information from the server with the Merge option checked.