IBM WebSphere Portal 8.5: User assistance for administrators

Content provider policy requests and responses

Use the Request and Response tabs to define a fine-grained control over HTTP headers, HTTP cookies, and filters. Filters provide a programmatic control over content during the request and response phases of the interaction between IBM® WebSphere® Portal and the web application.

Headers

Specify the allowed (propagated) or blocked headers in the requests and responses to and from the content provider. By default, the Web Application Bridge propagates all the client-side headers. The client-side headers are present in the request that is received from the browser. The Web Application Bridge does not propagate headers that are listed in the block field.

Click Insert Header to add custom headers. The custom headers are useful for the following scenarios:
  • To add more headers that are not there in the request from the browser
  • To add more headers that are not there in the request from the content provider
  • To use single sign-on
  • To send more information
If you add a custom header with the same name as an existing header, the custom header overrides the existing header.

Cookies

Specify the allowed or blocked cookies in the request from the browser or the response from the content provider. By default, the Web Application Bridge blocks all the client-side cookies from reaching the content provider. The client-side cookies are present in the request that is received from the browser. You need to specify the client-side cookies that need to be propagated by selecting Block all, except in the Cookies section of the Request tab and specifying individual cookies.

Click Insert Cookies to add custom cookies. The custom cookies are useful for the following scenarios:
  • To add more cookies that are not there in the request from the browser
  • To add more cookies that are not there in the response from the content provider
  • To use single sign-on
  • To send more information

If you add a custom request cookie with the same name as an existing cookie, the custom cookie overrides the existing cookie. If you add a custom response cookie, the Web Application Bridge adds a Set-Cookie header. The Web Application Bridge uses the provided name and value in responses that are sent from the Reverse Proxy servlet to the browser.

Filters

Filters are Java code that can be started on demand to run custom actions. They modify the request programmatically. Filters are extensions to core feature. Use the servlet filter API to create custom filters. The filters manipulate the request or response from the portal to the content provider. Developers create the filters. First, the administrator clicks Insert request filter to specify the set of filters that are available to apply to this policy. Then, the administrator clicks Add Filter to apply the filter to the policy.

Complete the following steps to create custom filters:
Tip: Contact IBM Support for details about how to write filters.
  1. Create a Java file with the following sample code. The following code inserts a sample header and cookie into a request that goes from the portal to the content provider site:
    package com.ibm.wps.wab.filter;
    
    import java.io.IOException;
    import java.io.UnsupportedEncodingException;
    import java.net.HttpURLConnection;
    import java.net.URLEncoder;
    import java.util.ArrayList;
    import java.util.Iterator;
    import java.util.List;
    import java.util.Map;
    import java.util.TreeMap;
    
    import javax.naming.Context;
    import javax.naming.InitialContext;
    import javax.naming.NamingException;
    import javax.servlet.Filter;
    import javax.servlet.FilterChain;
    import javax.servlet.FilterConfig;
    import javax.servlet.ServletException;
    import javax.servlet.ServletRequest;
    import javax.servlet.ServletResponse;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletRequestWrapper;
    
    import com.ibm.portal.um.PumaHome;
    import com.ibm.portal.um.PumaProfile;
    import com.ibm.portal.um.User;
    import com.ibm.portal.um.exceptions.PumaException;
    import com.ibm.wps.logging.LogManager;
    import com.ibm.wps.logging.Logger;
    import com.ibm.wps.vwat.servlet.ReverseProxyRequest;
    import com.ibm.wps.wab.outbound.model.api.HostConfig;
    import com.ibm.wps.wab.outbound.model.api.PolicyConfig;
    
    @SuppressWarnings("unused")
    public class SampleRequestFilter implements Filter {
    
    	private static final Logger LOGGER = LogManager.getLogManager().getLogger(SampleRequestFilter.class);
    	private ReverseProxyRequest reverseProxyRequest = null;
    	
    	@Override
    	public void destroy() {
    		// TODO Auto-generated method stub
    
    	}
    
    	@Override
    	public void doFilter(ServletRequest request, ServletResponse response,
    			FilterChain chain) throws IOException, ServletException {
    		final boolean isDebugEnabled = LOGGER.isLogging(Logger.TRACE_HIGH);
    		final String METHOD_NAME = "doFilter";
    		if (isDebugEnabled) {
    			LOGGER.entry(Logger.TRACE_HIGH, METHOD_NAME, "SampleRequestFilter");
    		}
    		this.reverseProxyRequest  = (ReverseProxyRequest)request;
    		
    		//add a custom cookie
    		String cookieName = "TestCookieName";
    		String cookieValue = "TestCookieValue";		
    		addCookie(cookieName, cookieValue);
    		
    		//add a custom header
    		String headerName = "TestHeaderName";
    		String headerValue = "TestHeaderValue";
    		addHeader(headerName, headerValue);
    		
    		
    		//Please not do not remove this
    		chain.doFilter(request, response);
    	}
    
    	public void addCookie(final String name, String value) {
    		final boolean isDebugEnabled = LOGGER.isLogging(Logger.TRACE_HIGH);
    		final String METHOD_NAME = "addCookie";
    		if (isDebugEnabled) {
    			LOGGER.entry(Logger.TRACE_HIGH, METHOD_NAME);
    		}
    		if (name == null || name.trim().length() == 0) {
    			return;
    		}
    		if (value != null) {
    			value = value.trim();
    		}
    		else {
    			value = "";
    		}		
    		
    		String cookieHeader = reverseProxyRequest.getConnection().getRequestProperty("Cookie");	
    		if(cookieHeader != null)
    			cookieHeader = cookieHeader + ";" + name + "=" + value;
    		else
    			cookieHeader = name + "=" + value;		
    		reverseProxyRequest.getConnection().setRequestProperty("Cookie", cookieHeader);
    		
    		if (isDebugEnabled) {
    			LOGGER.exit(Logger.TRACE_HIGH, METHOD_NAME);
    		}		
    	}
    	
    	public void addHeader(final String name, final String value) {
    		final boolean isDebugEnabled = LOGGER.isLogging(Logger.TRACE_HIGH);
    		final String METHOD_NAME = "addHeader";
    		if (isDebugEnabled) {
    			LOGGER.entry(Logger.TRACE_HIGH, METHOD_NAME, new Object[]{name, value});
    		}
    		
    		if (name == null || name.trim().length() == 0) {
    			return;
    		}
    		this.reverseProxyRequest.getConnection().addRequestProperty(name, value);	
    		if (isDebugEnabled) {
    			LOGGER.exit(Logger.TRACE_HIGH, METHOD_NAME);
    		}
    	}
    	
    	@Override
    	public void init(FilterConfig arg0) throws ServletException {
    		// TODO Auto-generated method stub
    
    	}
    
    }
  2. Complete the following steps to engage the filter:
    1. Create a filter component Java file with at least one class that implements the javax.servlet.Filter interface.
    2. Compile the filter component Java file against the following items:
      • VWAT servlet (runtime.jar in the wp_profile/installedApps/cell-name/wp.vwat.servlet.ear.ear/wp.vwat.servlet.war/WEB-INF/lib directory)
      • VWAT engine JAR files (in the wp.vwat.engine.jar in wps/shared/app directory)
      • All portal/WAS Java archive and compressed files
      Tip: Use the Rational Application Developer Portal project because it already has the correct build paths for IBM WebSphere Portal and IBM WebSphere Application Server.
    3. Build a .jar file with the compiled class files.
    4. Place the .jar file in the same location as the runtime.jar file.
    5. Restart the WebSphere_Portal server.

Library | Support | Terms of use |

Thursday, May 7, 2015 12:23am EST

Copyright IBM Corporation 2000, 2014.