Tuesday, January 15, 2013

Display username in wsrp portlet that integrated in webcenter portal


We need to display the security context logged in username in portlet , that is integrated with webcenter portal application. The portlet application does not have security context initialized, so it should pick it from the portal security.

We have two application for this exercise.

1. Create a portlet application.

We have multiple ways to create a WSRP portlet application.
Example :

1. Create Fusion middleware application, create adf taskflow and convert it to portlet entry
2. Create 'Webcenter Portal - Portlet producer application

Here I am following  second approach, since most of us know the first approach well.

After creating the webcenter portlet producer application, create a JSR286 portlet and select jspx for view.








Edit the view.jspx with the following entries,

<?xml version='1.0' encoding='windows-1252'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"
          xmlns:f="http://java.sun.com/jsf/core"
          xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
  <jsp:directive.page contentType="text/html;charset=windows-1252"/>

  <f:view>
    <af:document>
      <af:form>
      <af:panelGroupLayout id="pgl1" layout="vertical">
     
        <af:outputText value="username is" id="ot3"/>
        <af:outputText value="#{securityContext.userName}" id="ot4"/>
        </af:panelGroupLayout>
      </af:form>
    </af:document>
  </f:view>
</jsp:root>


Open portlet.xml, and add the container runtime options as 'com.oracle.portlet.useWsrpUserContextForUserAuthenticationInfo' and value is 'true'

Now we can deploy the application and will go to the second application.


If you want to know how to develop a portlet producer application step by step, click here

2. Create a Portal application

Create a webcenter portal framework application and create an authenticated page. Create a WSRP producer in application resources connection and register with the
abover portlets wsdl.

Run the application, and login with application server user and you can see that the portlet is displaying the logged in username.

Download the source projects from here 

No comments:

Post a Comment