3 Replies Latest reply: Sep 12, 2013 11:44 PM by Vibzz RSS

    How to fetch user specific data from View?




      I have a requirement in which I need to display table data specific to Session_user only. Scenario is if user belongs to a specific region he should be able to see data related to that specific region only.

      I am thinking of passing session_user name in view query but do not know whether it's possible or not.If possible how to do this.


      What is the best way to achieve it?




        • 1. Re: How to fetch user specific data from View?
          Frank Nimphius-Oracle



          if you use ADF Security for authentication then the user name is accessible from the ADF Context in ADF BC. You can then


          1. Create a View Criteria in ADF BC for a specific view

          2. Define the View Criteria to use a bind variable

          3. Use groovy to add the bind variable value

             - set value type to "Expression"

             - add adf.context.securityContext.userName

          4. Go to the Application Module --> Data Model

          5. Select the View Object instance

          6. Press "Edit"

          7. Select the View Criteria


          If you download the sample to this article: Oracle ADF: Security for Everyone then you see that users have a profile page containing data queried for the authenticated user. Its using the above approach


          If you don't use ADF Security still you can use that approach. Instead of providing the bind variable value using Groovy you could execute the view object useing executeWithParams operation in which case you can read the value of the authenticated user from the ADF view side. The bind variable would not be set to Expression in this case though.



          • 2. Re: How to fetch user specific data from View?
            Guru Tata



            First thing is that you need to implement security in your application, if you configured security then, Take a session scope bean in your un bounded task flow

            inside that session bean , you can get the information from security context, then write a static block inside your session bean and modify the fallowing code according to your requirement


            ADFContext adfc=ADFContext.getCurrent();// get the context instance
            SecurityContext securityContext=adfc.getSecurityContext();// instantiate the SecurityContext
            String username=securityContext.getUserName(); // returns the username from the security Context who are currently logged in


            Once you written this code just assign this username to session scope variable



                Map sessionScope =
                    (Map)ADFContext.getCurrent().getSessionScope().put("UserName", username);


            So that the username with the key UserName will be available throughout your session

            and Apply in where clause according to the user logged in, or else you may directly use

            adf.context.securityContext.userName at the bind variable what ever you used inside your view criteria.

            • 3. Re: How to fetch user specific data from View?

              Thanks Frank and GuruTara

              I have already implemented security long back, was just confused about how to pass username to query view object.I will try to do using view criteria.

              Thanks a lot for your help guys.