/*
* First try and locate the session, if there is no session then this is
* definitely not a reverse proxy request
*/
LaunchSession launchSession = null;
SessionInfo session = locateSession(request, response);
if (session == null) {
// If we have no session, then this cannot be a reverse proxy
// request
if (log.isDebugEnabled())
log.debug("No session, not a reverse proxy.");
return false;
}
try {
// Perhaps this is a reverse proxy?
String host = request.getHost();
ReverseProxyWebForward wf = null;
// Active Proxy
if (host != null && !host.equals("") && host.indexOf('.') > -1) {
int idx = host.indexOf('.');
if (idx != -1) {
try {
String uniqueId = host.substring(0, idx);
launchSession = LaunchSessionFactory.getInstance().getLaunchSession(session, uniqueId);
if (launchSession != null) {
wf = (ReverseProxyWebForward) launchSession.getResource();
launchSession.checkAccessRights(null, session);
if (!((ReverseProxyWebForward) wf).getActiveDNS()) {
throw new Exception("Appears to be an active DNS request but the associated web forward is not active DNS. Is someone trying something funny???");
}
LogonControllerFactory.getInstance().addCookies(request, response, session.getLogonTicket(), session);
return handleReverseProxy(pathInContext, pathParams, request, response, launchSession);
}
} catch (Exception ex) {
if (log.isDebugEnabled())
log.debug("Active DNS web forward lookup failed", ex);
}
} else {
if (log.isDebugEnabled())
log.debug("Not active DNS.");
}
}
String hostHeader = request.getHost();
int idx = hostHeader.indexOf(':');
if (idx > -1)
hostHeader = hostHeader.substring(0, idx);
/* Ordinary reverse proxy? There can only ever be one launch session per reverse proxy
* as there is no way of maintaining the session across requests. If a user launches the
* resource more than once, the old launch session will be removed
*/
for (LaunchSession rs : LaunchSessionFactory.getInstance().getLaunchSessionsForType(session,
WebForwardPlugin.WEBFORWARD_RESOURCE_TYPE)) {
if (rs.getResource() instanceof ReverseProxyWebForward) {
wf = (ReverseProxyWebForward) rs.getResource();
// Check that its not reverseProxyRedirect.jsp because if we don't it breaks access after first attempt in same session
if (wf.isValidPath(pathInContext) || (wf.getHostHeader() != null && wf.getHostHeader().equals(hostHeader) && !pathInContext.startsWith("/reverseProxyRedirect.jsp"))) {
rs.checkAccessRights(null, session);
return handleReverseProxy(pathInContext, pathParams, request, response, rs);
}
}
}
} catch (Exception e) {
log.error("Failed to process web forward.", e);
if (session != null) {
session.getHttpSession().setAttribute(Constants.EXCEPTION, e);
response.sendRedirect("/showPopupException.do");
} else {
throw new RequestHandlerException("Failed to process web forward.", 500);
}
return true;