Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

Code Block
titleCASPortletWrapper
package edu.yale.its.tp.cas.client.portlet;

import java.io.IOException;

import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.Portlet;
import javax.portlet.PortletConfig;
import javax.portlet.PortletException;
import javax.portlet.PortletRequest;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;

import edu.yale.its.tp.cas.client.CASAuthenticationException;
import edu.yale.its.tp.cas.client.ProxyTicketValidatorFactory;

/**
 * A JSR-168 portlet wrapper that validates a CAS ticket present as a 
 * particular portlet request parameter.
 * @version $Revision:$ $Date:$
 */
public class CASPortletWrapper 
    implements Portlet {
    
    public static String WRAPPED_PORTLET_CLASS = "edu.yale.its.tp.cas.client.portlet.WRAPPED_PORTLET_CLASS";
    
    /**
     * The Portlet we're wrapping and to which we delegate.
     */
    private Portlet delegate;

    private ProxyTicketValidatorFactory ptvFactory;
    
    public void init(PortletConfig pc) throws PortletException {
        // extract our own configuration from the config and then
        // pass the config along to our delegate.
        
        String wrappedPortlet = pc.getInitParameter(WRAPPED_PORTLET_CLASS);
        if (wrappedPortlet == null) {
            throw new PortletException("CASPortlet requires the init parameter WRAPPED_PORTLET_CLASS");
        }
        
        try {
            this.delegate = (Portlet) Class.forName(wrappedPortlet).newInstance();
        } catch (Exception e) {
            throw new PortletException("Could not intantiate delegate class " + delegate, e);
        }
        
        this.ptvFactory = CASPortletUtils.ptvFactoryForPortletConfig(pc);
        
        this.delegate.init(pc);
        
    }

    public void processAction(ActionRequest actionRequest, ActionResponse actionResponse) throws PortletException, IOException {
        try {
            CASPortletUtils.establishSession(actionRequest, this.ptvFactory);
        } catch (CASAuthenticationException e) {
            throw new PortletException(e);
        }
        
        this.delegate.processAction(actionRequest, actionResponse);
    }

    public void render(RenderRequest renderRequest, RenderResponse renderResponse) throws PortletException, IOException {
        try {
            CASPortletUtils.establishSession(renderRequest, this.ptvFactory);
        } catch (CASAuthenticationException e) {
            throw new PortletException(e);
        }
        
        this.delegate.render(renderRequest, renderResponse);
    }

    public void destroy() {
        this.delegate.destroy();
    }

   
    protected final String getProxyTicket(PortletRequest request, String targetService) {
        return CASPortletUtils.getProxyTicket(request, targetService);
    }

}

This relies heavily on a helper class (which other portlets can use without using the wrapper portlet):

...