Filtering ADF pgaes based on loggon on User  Using Groovy  Jdev 11g

Write your View Object Query with Bind variable as shown below

 

    SELECT * from EMP

    where ENAME = upper(:ammar)

Create a bind variable called ammar and set it default value to

adf.context.securityContext.userName  (this is a groovy expression)

Note:  If do do not properly define your security provider (Jazn or Ldap) to establish logon name, then you will probably get NULL for the userName or Anonymous.

This will cause no data to be shown on the page.

Please note that your JDBC connection username is not the logon username

A second approach would be to write an Application Module method to filter the View Object, then expose the method and add it to the invoke action component in the Page definition.

You can for example write something along the following lines in the AM

    public void filterRows(){
    String usr = this.getUserPrincipalName();
    ViewObject vo = this.getEmpView1();
    vo.setNamedWhereClauseParam("ammar", usr);
    vo.executeQuery();
}

Once this method is written, you can expose it so that you can see in the data control. Add it to the invoke action of the page iterator.

A third and a completely different approach would be to use the Oracle Row Level Security (RLS) concept (a database feature in Oracle RDBMS Enterprise Edition). A concept that you need to be familiar with and is implemented for any Database Access with it is Jdeveloper related or not.

However, from Jdeveloper you need to set the user context and you can do that by overriding the PrepareSession method to make the user_context equal to the getUserPrinciple

Ammar Sajdi

Oracle Expert and CEO or REALSOFT