There are many ways to secure your portlet. This article describes how to build a portlet that displays two types of information based on the logged-in user.
You have already installed the samples downloaded with the JPDK and understand the steps required to display a web portlet on a portal page. For more information on installing the sample, please review the Installing the PDK-Java Framework and Samples article.
You have read and followed the instructions from the article How to Build a Java Portlet article. You have successfully built My First Portlet.
You are using the Oracle HTTP Server to execute and display your servlets used by the JPDK. If you are using a 3rd party listener, please modify the article accordingly. Note: Your Oracle HTTP Server does not need to the same listener that serves your Portal pages.
Write a JSP that displays certain information based upon whether the user has been authenticated. If a public user is accessing the portal page, the JSP displays a generic message. If the user is authenticated with Oracle9iAS Portal, then displays a message with more information.
|
<%@page import = "oracle.portal.provider.v1.*, oracle.portal.provider.v1.http.*" %> <% PortletRenderRequest portletRequest = (PortletRenderRequest) PortletSecurityManager portletSecurity = (PortletSecurityManager) request.getAttribute(HttpProvider.PORTLET_RENDER_REQUEST); %> <center> <h2> <% String user = portletRequest.getUser().getName(); if (portletSecurity.hasAccess(user) { out.println("Hello " + portletRequest.getUser().getName() + ", we have verified that you are authenticated and you are viewing Administrative content"); } else { out.println("Hello " + portletRequest.getUser().getName() + " you are viewing general content"); } %> </h2> </center> |
Close and Save this file as mysecurityportlet.jsp.
This section explains how to create a provider.xml to describe and list your new portlet. It then explains how to update the Oracle HTTP Server to view the new provider.xml.
In this section you will create a new provider.xml. Creating a new provider.xml will allow you add new portlets without affecting Web Providers already registered with Oracle9iAS Portal.
Open a text editor.
Add the following entry to the file. Note: If you plan to add additional portlets in the future, verify that your portlet ID is unique for this provider.
|
<provider class="oracle.portal.provider.v1.http.DefaultProvider" session="true"> <portlet class="oracle.portal.provider.v1.http.DefaultPortlet" version="1" > <id>1</id> <name>MySecurityPortlet</name> <title>My Security Portlet</title> <description>This portlet displays information based on whether the user has authenticated.</description> <timeout>5</timeout> <timeoutMsg>My Security Portlet timed out</timeoutMsg> <showEdit>false</showEdit> <showEditDefault>false</showEditDefault> <showPreview>false</showPreview> <showDetails>false</showDetails> <hasHelp>false</hasHelp> <hasAbout>false</hasAbout>
<acceptContentTypes> <item>text/html</item> </acceptContentTypes>
<renderer class="oracle.portal.provider.v1.http.PageRenderer" > <appPath>/myfirstportlet</appPath> <appRoot>C:\9iAS\Apache\Apache\htdocs\myfirstportlet</appRoot> <showPage>mysecurityportlet.jsp</showPage> </renderer> </portlet> </provider>
|
- Save and close the file. Make sure to name the file "provider.xml".
Currently the zone.properties has an argument called provider_root that points the Adapter to the directory where the provider.xml for the jpdk resides. We will add a new entry to point to our new provider.xml in addition to the previous one.
Stop the Oracle HTTP Server.
Open zone.properties.
servlet.secure.code=oracle.portal.provider.v1.http.HttpProvider
servlet.secure.initArgs=provider_root=C:\mysecurityportletjsp,sessiontimeout=1800000
Save and close the file.
Start the Oracle HTTP Server.
http://host.domain:port/servlet/secure
Now that you have successfully tested your new alias. You will need to register a new provider that calls this alias.
Register your new Provider.
Name: MySecurityPortlet
Display Name: My Security Portlet
Timeout: 100
Timeout Message: My Seucrity Portlet Timed Out
Implementation Style: Web
Provider Login Frequency: Once per User Session
URL: http://host.domain:port/servlet/secure
Click on OK.
Now that you have successfully built a secured portlet, please the following articles for more information on portlet security.
Revision History:
April 16, 2001.