IBM WebSphere Portal 8.5: User assistance for administrators |
---|
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.
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.
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.
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 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.
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
}
}