import com.ibm.portal.portlet.service.impersonation.impersonationservice;

Similar documents
Developing JSR-168- Compliant Portlets for the SAS Information Delivery Portal 4.2

Advanced Software Engineering

Implementing JSR 168 inter-portlet communication using Rational Application Developer V6.0 and WebSphere Portal V5.1

Sang Shin. Java Portlets (JSR-168) Revision History. Disclaimer & Acknowledgments

PORTIONS (PORTlet actions) User Guide

USE OF EXPANDO API IN LIFERAYS

Portlet Standard JSR 168 / JSR 286

Tutorial: Developing a Simple Hello World Portlet

Administration Console Extension Developer's Guide

Introduction to JSR 168 The Java Portlet Specification

Portlet Development Guide Introduction to the Portlet API

Developing JSR-168- Compliant Portlets for the SAS Information Delivery Portal 4.3

文字エンコーディングフィルタ 1. 更新履歴 2003/07/07 新規作成(第 0.1 版) 版 数 第 0.1 版 ページ番号 1

Beyond the Portlet API

Content Server / Spark. Version: 6.3. Delivery Portlet Developer s Guide

Liferay 7 Portlet to Empower Your Custom Development

JSR 168 Portlet Spec

JSP. Common patterns

Portlets (JSR-168) Dave Landers. BEA Systems, Inc. Dave Landers Portlets (JSR-168)

EJB - INTERCEPTORS. Interceptor methods can be applied or bound at three levels

Ajax DWR dojo In WebSphere Portal

Development of the Security Framework based on OWASP ESAPI for JSF2.0

Building Blocks for a Simple TeraGrid Science Gateway

Standards and the Portals Project

IBM Realtests LOT-911 Exam Questions & Answers

2018/2/5 话费券企业客户接入文档 语雀

Java TM. JavaServer Faces. Jaroslav Porubän 2008

Liferay Customization Hints

directive attribute1= value1 attribute2= value2... attributen= valuen %>

Introduction to Portlet Programming with JSR-168

Portals allow users easy access to information

Web Applications and Database Connectivity using JDBC (Part II)

JavaServer Pages (JSP)

Portlet Development Guide Working with the Portlet API 1.1 Java Server Pages in Portlets Portlet Design Guidelines Security and Single Sign On

sessionx Desarrollo de Aplicaciones en Red EL (2) EL (1) Implicit objects in EL Literals José Rafael Rojano Cáceres

Advanced Web Systems 3- Portlet and JSP-JSTL. A. Venturini

Introduction to Session beans EJB 3.0

Common-Controls Guided Tour TreeControl

CIS 764 Tutorial: Log-in Application

EJB - DEPENDENCY INJECTION

Integrating NWDS with a Non-SAP Server (JBoss AS) to Develop and Deploy Java EE Applications

Common-Controls Guided Tour TabSetControl

JSR-286: Portlet Specification 2.0

A.1 JSP A.2 JSP JSP JSP. MyDate.jsp page contenttype="text/html; charset=windows-31j" import="java.util.calendar" %>

Session 11. Expression Language (EL) Reading

BEAWebLogic Server. Monitoring and Managing with the Java EE Management APIs

EJB - ACCESS DATABASE

Stateless Session Bean

SERVLET AND JSP FILTERS

Portlets and Ajax: Building More Dynamic Web Apps

Advanced Internet Technology Lab # 4 Servlets

Common-Controls Guided Tour ListControl

Java Technologies Web Filters

Three hours UNIVERSITY OF MANCHESTER SCHOOL OF COMPUTER SCIENCE. Date: Friday 21 st May Time:

Lab2: CMP Entity Bean working with Session Bean

Exploring EJB3 With JBoss Application Server Part 6.3

&' () - #-& -#-!& 2 - % (3" 3 !!! + #%!%,)& ! "# * +,

BEAWebLogic. Server. Monitoring and Managing with the J2EE Management APIs

Alternate Methods for Informatica Metadata Exchange SDK

1. Introduction. 2. Life Cycle Why JSP is preferred over Servlets? 2.1. Translation. Java Server Pages (JSP) THETOPPERSWAY.

Unit-4: Servlet Sessions:

JSR-286: Portlet Specification 2.0

jar command Java Archive inherits from tar : Tape Archive commands: jar cvf filename jar tvf filename jar xvf filename java jar filename.

Session 8. JavaBeans. Reading & Reference. Reading. Reference. Session 8 Java Beans. 2/27/2013 Robert Kelly, Head First Chapter 3 (MVC)

Session 21. Expression Languages. Reading. Java EE 7 Chapter 9 in the Tutorial. Session 21 Expression Languages 11/7/ Robert Kelly,

COURSE 9 DESIGN PATTERNS

Virus Scan with SAP Process Integration Using Custom EJB Adapter Module

CS506 Web Design & Development Final Term Solved MCQs with Reference

CreateServlet.java

Author - Ashfaque Ahmed

CMP relations between Enterprise Java Beans (EJB) eclipse, xdoclet, jboss

Data Service Patterns Jeff Zhuk

Lab1: Stateless Session Bean for Registration Fee Calculation

Kamnoetvidya Science Academy. Object Oriented Programming using Java. Ferdin Joe John Joseph. Java Session

1D/2D android secondary development

Principles and Techniques of DBMS 6 JSP & Servlet

Unit 4 Java Server Pages

Oracle 1z Java Enterprise Edition 5 Web Component Developer Certified Professional Exam. Practice Test. Version:

/* Copyright 2012 Robert C. Ilardi

CSC309: Introduction to Web Programming. Lecture 11

BEAWebLogic. Server. Monitoring and Managing with the J2EE Management APIs

Simple Stateless with Descriptor

Communication.java 1

Oracle Universal Content Management. Content Portlet Suite Developer Guide 10g Release 3 ( )

BEAWebLogic Server and WebLogic Express. Programming WebLogic JNDI

JSP Scripting Elements

PES INSTITUTE OF TECHNOLOGY, SOUTH CAMPUS DEPARTMENT OF MCA INTERNAL TEST (SCHEME AND SOLUTION) II

Customizing the WebSphere Portal login and logout commands

Using the JBoss IDE for Eclipse

Web Programming. Lecture 11. University of Toronto

JavaServer Pages. Juan Cruz Kevin Hessels Ian Moon

Exploring EJB3 With JBoss Application Server Part 6.2

Unit 5 JSP (Java Server Pages)

1 Introduction and Roadmap

Knox Manage manages the following application types: Internal applications: Applications for internal use

Sun Sun Certified Web Component Developer for J2EE 5 Version 4.0

JavaServer Pages. What is JavaServer Pages?

ANN exercise session

( A ) 8. If the address of an array is stored in $value, how do you get the values of this array? (B) \$value (C) &$value (D) $$value

Common-Controls Guided Tour TreeListControl

Transcription:

Filter Class: package com.ibm.impersonationwithfilter; import java.io.ioexception; import javax.naming.context; import javax.naming.initialcontext; import javax.naming.namingexception; import javax.portlet.portletexception; import javax.portlet.renderrequest; import javax.portlet.renderresponse; import javax.portlet.filter.filterchain; import javax.portlet.filter.filterconfig; import javax.portlet.filter.renderfilter; import com.ibm.portal.impersonation.exceptions.impersonationexception; import com.ibm.portal.portlet.service.portletservicehome; import com.ibm.portal.portlet.service.impersonation.impersonationservice; import com.ibm.portal.um.user; import com.ibm.portal.um.exceptions.pumaexception; import com.ibm.portal.um.portletservice.pumahome; public class ImpersonationFilter implements RenderFilter { private boolean userimpersonated = false;

private User actualuser; private User originaluser; private String auser; private String ouser; PortletServiceHome pshimpersonate; PumaHome pumahome; public void destroy() { public void init(filterconfig filterconfig) throws PortletException { public void dofilter(renderrequest request, RenderResponse response, FilterChain filterchain) throws IOException, PortletException { try { Context ctx = new InitialContext(); pshimpersonate = (PortletServiceHome) ctx.lookup(impersonationservice.jndi_name); PortletServiceHome pshome; pshome = (PortletServiceHome) ctx.lookup(pumahome.jndi_name); pumahome = (PumaHome) pshome.getportletservice(pumahome.class);

catch (NamingException e) { // TODO Auto-generated catch block e.printstacktrace(); try { actualuser = pumahome.getprofile(request).getcurrentuser(); int temp = actualuser.tostring().indexof(","); auser = actualuser.tostring().substring(4, temp); catch (PumaException e1) { // TODO Auto-generated catch block e1.printstacktrace(); com.ibm.portal.portlet.service.portletservicehome psh = null; ImpersonationService impersonationservice; javax.naming.context ctx = null; try { ctx = new javax.naming.initialcontext(); catch (NamingException e) { // TODO Auto-generated catch block e.printstacktrace();

try { psh = (com.ibm.portal.portlet.service.portletservicehome) ctx.lookup(impersonationservice.jndi_name); if (psh!= null) { impersonationservice = (ImpersonationService) psh.getportletservice(impersonationservice.class); if (impersonationservice!= null) { userimpersonated = impersonationservice.isuserimpersonated(); originaluser = impersonationservice.getoriginaluser(); int temp = actualuser.tostring().indexof(","); ouser = originaluser.tostring().substring(4, temp); catch (javax.naming.namingexception ne) { // impersonation is not present catch (com.ibm.portal.portlet.service.portletserviceunavailableexception psue) { // impersonation is not present catch (ImpersonationException e) { response.setcontenttype("text/html"); if (userimpersonated) { response.getwriter().print("<b>you are in impersonation mode! <br><br>this portlet contains some of the sensitive user information which is not displayed</b><br>");

response.getwriter().print("the impersonated user is = " + auser); response.getwriter().print("<br>"); response.getwriter().print("the original user is = " + ouser); response.getwriter().print("<br><h3 style='margin-bottom: 3px'>Welcome!</H3>"); Details</H3>"); response.getwriter().print("<h3 style='margin-bottom: 3px'>Profile response.getwriter().print("<b>name</b> : " + auser); else { response.getwriter().print("<br><h3 style='margin-bottom: 3px'>Welcome!</H3>"); response.getwriter().print("<h3 style='margin-bottom: 3px'>Profile Details</H3><DIV style='margin: 12px; margin-bottom: 36px'>"); response.getwriter().print("<b>name</b> : " + auser); filterchain.dofilter(request, response); Portlet class package com.ibm.impersonationwithfilter; import java.io.ioexception;

import javax.portlet.actionrequest; import javax.portlet.actionresponse; import javax.portlet.genericportlet; import javax.portlet.portletexception; import javax.portlet.portletrequest; import javax.portlet.portletrequestdispatcher; import javax.portlet.portletsession; import javax.portlet.renderrequest; import javax.portlet.renderresponse; A sample portlet based on GenericPortlet public class ImpersonationWithFilterPortlet extends GenericPortlet { public static final String JSP_FOLDER = "/_ImpersonationWithFilter/jsp/"; // JSP folder name public static final String VIEW_JSP = "ImpersonationWithFilterPortletView"; // JSP file name to be rendered on the view mode public static final String SESSION_BEAN = "ImpersonationWithFilterPortletSessionBean"; // Bean name for the portlet session public static final String FORM_SUBMIT = "ImpersonationWithFilterPortletFormSubmit"; // Action name for submit form public static final String FORM_TEXT = "ImpersonationWithFilterPortletFormText"; // Parameter name for the text input

@see javax.portlet.portlet#init() public void init() throws PortletException{ super.init(); Serve up the <code>view</code> mode. @see javax.portlet.genericportlet#doview(javax.portlet.renderrequest, javax.portlet.renderresponse) public void doview(renderrequest request, RenderResponse response) throws PortletException, IOException { // Set the MIME type for the render response response.setcontenttype(request.getresponsecontenttype()); // Check if portlet session exists ImpersonationWithFilterPortletSessionBean sessionbean = getsessionbean(request); if( sessionbean==null ) { response.getwriter().println("<b>no PORTLET SESSION YET</b>"); return; // Invoke the JSP to render

PortletRequestDispatcher rd = getportletcontext().getrequestdispatcher(getjspfilepath(request, VIEW_JSP)); rd.include(request,response); Process an action request. @see javax.portlet.portlet#processaction(javax.portlet.actionrequest, javax.portlet.actionresponse) public void processaction(actionrequest request, ActionResponse response) throws PortletException, java.io.ioexception { if( request.getparameter(form_submit)!= null ) { // Set form text in the session bean ImpersonationWithFilterPortletSessionBean sessionbean = getsessionbean(request); if( sessionbean!= null ) sessionbean.setformtext(request.getparameter(form_text)); Get SessionBean. @param request PortletRequest @return ImpersonationWithFilterPortletSessionBean

private static ImpersonationWithFilterPortletSessionBean getsessionbean(portletrequest request) { PortletSession session = request.getportletsession(); if( session == null ) return null; ImpersonationWithFilterPortletSessionBean sessionbean = (ImpersonationWithFilterPortletSessionBean)session.getAttribute(SESSION_BEAN); if( sessionbean == null ) { sessionbean = new ImpersonationWithFilterPortletSessionBean(); session.setattribute(session_bean,sessionbean); return sessionbean; Returns JSP file path. @param request Render request @param jspfile JSP file name @return JSP file path private static String getjspfilepath(renderrequest request, String jspfile) { String markup = request.getproperty("wps.markup"); if( markup == null ) markup = getmarkup(request.getresponsecontenttype());

return JSP_FOLDER + markup + "/" + jspfile + "." + getjspextension(markup); Convert MIME type to markup name. @param contenttype MIME type @return Markup name private static String getmarkup(string contenttype) { if( "text/vnd.wap.wml".equals(contenttype) ) return "wml"; else return "html"; Returns the file extension for the JSP file @param markupname Markup name @return JSP extension private static String getjspextension(string markupname) { return "jsp";

ImpersonationWithFilterPortletSessionBean package com.ibm.impersonationwithfilter; A sample Java bean that stores portlet instance data in portlet session. public class ImpersonationWithFilterPortletSessionBean { Last text for the text form private String formtext = ""; Set last text for the text form. @param formtext last text for the text form. public void setformtext(string formtext) { this.formtext = formtext; Get last text for the text form. @return last text for the text form public String getformtext() { return this.formtext; Exception class package com.ibm.portal.impersonation.exceptions; public class ImpersonationException extends Throwable{ private static final long serialversionuid = 1L; Resource bundle

# en Resource Bundle # # filename: ImpersonationWithFilterPortletResource_en.properties # Portlet Info resource bundle example javax.portlet.title=impersonationwithfilter javax.portlet.short-title=impersonationwithfilter javax.portlet.keywords=impersonationwithfilter jsp <%@page session="false" contenttype="text/html" pageencoding="iso-8859-1" import="java.util.,javax.portlet.,com.ibm.impersonationwithfilter." %> <%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%> <%@taglib uri="http://www.ibm.com/xmlns/prod/websphere/portal/v6.1/portletclient-model" prefix="portlet-client-model" %> <portlet:defineobjects/> <portlet-client-model:init> <portlet-client-model:require module="ibm.portal.xml."/> <portlet-client-model:require module="ibm.portal.portlet."/> </portlet-client-model:init> <% com.ibm.impersonationwithfilter.impersonationwithfilterportletsessionbe an sessionbean = (com.ibm.impersonationwithfilter.impersonationwithfilterportletsessionbean)re nderrequest.getportletsession().getattribute(com.ibm.impersonationwithfilter. ImpersonationWithFilterPortlet.SESSION_BEAN); %> <DIV style="margin: 6px"> <img src='<%=renderresponse.encodeurl(renderrequest.getcontextpath() + "/_ImpersonationWithFilter/jsp/html/monkey.jpg")%>' alt="monkey" /> <DIV style="margin: 12px; margin-bottom: 36px"> <b>ssn</b> : 898-14-8326 <br> <b>date of Birth</b> : Jul 4, 1910 </DIV> </DIV>