WSPRedirectHandlerServlet.java revision 564945e59b60a40c3b9458177b2ff63e2947686c
/**
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2006 Sun Microsystems Inc. All Rights Reserved
*
* The contents of this file are subject to the terms
* of the Common Development and Distribution License
* (the License). You may not use this file except in
* compliance with the License.
*
* You can obtain a copy of the License at
* See the License for the specific language governing
* permission and limitations under the License.
*
* When distributing Covered Code, include this CDDL
* Header Notice in each file and include the License file
* at opensso/legal/CDDLv1.0.txt.
* If applicable, add the following below the CDDL Header,
* with the fields enclosed by brackets [] replaced by
* your own identifying information:
* "Portions Copyrighted [year] [name of copyright owner]"
*
* $Id: WSPRedirectHandlerServlet.java,v 1.6 2008/08/06 17:28:10 exu Exp $
*
*/
/**
* Portions Copyrighted 2012-2014 ForgeRock AS
*/
/**
* Class that works in conjection with InteractionManager to facilitate
* WSP- resource owner interactions
*/
public class WSPRedirectHandlerServlet extends HttpServlet {
private static ResourceBundle i18n =
throws ServletException {
super.init(servletConfig);
try {
} catch (ParserConfigurationException pce) {
throw new ServletException(pce);
} catch (SAXException se) {
throw new ServletException(se);
} catch (IOException ioe) {
throw new ServletException(ioe);
}
if (debug.messageEnabled()) {
}
}
throws IOException {
//testXSL(httpRequest, httpResponse);
}
throws IOException {
}
throws IOException {
if (queryString != null) {
if (i != -1) {
if (j != -1) {
}
}
}
if (debug.messageEnabled()) {
"WSPRedirectHandlerServlet.handleRequest():"
+ "queryString: " + queryString
+ " : wspRedirectHandler:" + wspRedirectHandler
+ " : handlerHostId:" + handlerHostId
+ " : lbWspRedirectHandler:" + lbWspRedirectHandler);
}
if (handlerHostId != null) {
//check for trusted handlers
if (debug.warningEnabled()) {
"WSPRedirectHandlerServlet.handleRequest():"
+ "denied attempt to forward to untrusted host id:"
+ handlerHostId);
}
return;
}
if (debug.messageEnabled()) {
"WSPRedirectHandlerServlet.handleRequest()"
+ ":localServerId=" + localServerId
+ ":handlerHostId=" + handlerHostId
+ ":forwarding request to " + forwardToUrl);
}
return;
}
}
if (debug.messageEnabled()) {
"WSPRedirectHandlerServlet.handleRequest():"
+ "no need to forward, "
+ "processing request in the local server");
}
if (debug.messageEnabled()) {
"WSPRedirectHandlerServlet.handleRequest():entering "
+ "with requestURL=" + requestURL
+ ":messageID=" + messageID
+ ":returnToURL=" + returnToURL);
}
if (debug.messageEnabled()) {
"WSPRedirecthandlerServlet.handleRequest():"
+ " entering with returnToRL=" + returnToURL
+ " :a new request");
}
//returnToURL should not have ResendMessage parameter
+ "=") == -1)) {
"WSPRedirecthandlerServlet.handleRequest():"
+ "invalid Request - illegal parameter:"
+ ":returnToURL=" + returnToURL);
"Invalid Request - illegal parameter:"
+ ":returnToURL=" + returnToURL);
return;
}
//returnToURL should be https
"WSPRedirecthandlerServlet.handleRequest():"
+ "Invalid Request "
+ " not https"
+ ":returnToURL=" + returnToURL);
"Invalid Request "
+ " not https"
+ ":returnToURL=" + returnToURL);
return;
}
//returnToURL should point to requestHost
if (InteractionConfig.getInstance()
"WSPRedirecthandlerServlet.handleRequest():"
+ "Invalid Request ReturnToHost differs from "
+ " RequestHost"
+ ":returnToURL=" + returnToURL
+ ":requestHost="
"Invalid Request ReturnToHost differs from "
+ " RequestHost"
+ ":returnToURL=" + returnToURL
+ ":requestHost="
return;
}
//save returnToURL against messageID in InteractionManager
} else { //no returnToURL, response submission
if (debug.messageEnabled()) {
"WSPRedirecthandlerServlet.handleRequest():"
+ " entering without retunrnToRL:"
+ " response for query");
}
//get returnToURL against messageID in InteractionManager
if (returnToURL == null) {
"WSPRedirecthandlerServlet.handleRequest():"
+ " returnToURL, cacheEntry "
+ " not found to redirect, for TransactionID : "
+ messageID);
" returnToURL not found in cache");
} else {
}
}
} else {
"WSPRedirecthandlerServlet.handleRequest():"
+ "request without messageID"
+ ":requestURL=" + requestURL);
//show some error page
"Invalid Request - missing messageID"
+ ":requestURL=" + requestURL);
}
if (debug.messageEnabled()) {
"WSPRedirecthandlerServlet.handleRequest():returning");
}
}
/*
* an XSL stylesheet and sends the page to browser.
*/
throws IOException {
// generate html page, with action url pointing back to this servlet
// set query parameters transID and responseID
if (lbWspRedirectHandler == null) {
} else {
+ "=" + localServerId;
}
if (debug.messageEnabled()) {
"WSPRedirectHandlerServlet.sendInteractionRequestPage():"
+ "action=" + action);
}
if (!wmlClient) { //not a wmlClient, assume html client
if (debug.messageEnabled()) {
+ "sendInteractionRequestPage():"
+ "clientType=html");
}
} else { //a wml client
if (debug.messageEnabled()) {
+ "sendInteractionRequestPage():"
+ "clientType=wml");
}
"<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.1//EN\"");
}
try {
//style inquiryElement and send it to browser
"com.sun.identity.liberty.ws.interaction.jaxb");
} else {
}
if (LogUtil.isLogEnabled()) {
}
} catch (JAXBException je) {
"WSPRedirectHandlerServlet.sendInteractionRequestPage():"
+ "catching JAXBException =", je);
"Error creating JAXBObject:"
+ je.getMessage());
} catch (ParserConfigurationException pce) {
"WSPRedirectHandlerServlet.sendInteractionRequestPage():"
+ "catching ParserConfigurationException =", pce);
"Error creating interaction request page:"
+ pce.getMessage());
} catch (TransformerException tce) {
"WSPRedirectHandlerServlet.sendInteractionRequestPage():"
+ "catching TransformerException =", tce);
"Error creating interaction request page:"
+ tce.getMessage());
}
}
throws IOException {
if (debug.messageEnabled()) {
"WSPRedirectHandlerServlet.sendInteractionResponsePage():"
+"entering");
}
try {
//read and save query parameters;
while ( parameterNames.hasMoreElements()) {
/*
ParameterType parameterType
= JAXBObjectFactory.getObjectFactory()
.createParameterType();
*/
if (debug.messageEnabled()) {
+ ".sendInteractionResponsePage():"
+ "parameterName=" + parameterName
+ ", parameterValue=" + parameterValue);
}
if (index != -1) {
+ PARAMETER_PREFIX.length());
}
}
if (LogUtil.isLogEnabled()) {
objs);
}
//store InteractionResponse in interaction manager;
} else {
}
if (debug.messageEnabled()) {
"WSPRedirectHandlerServlet."
+ " sendInteractionResponsePage():"
+ "redirecting user agent to returnToURL="
+ returnToURL);
}
if (LogUtil.isLogEnabled()) {
objs);
}
} catch (JAXBException je) {
"WSPRedirectHandlerServlet.sendInteractionResponsePage():"
+ "catching JAXBException =", je);
"Error createing JAXBObject:"
+ je.getMessage());
} catch (Exception e) {
"WSPRedirectHandlerServlet.sendInteractionResponsePage():"
+ "catching Exception =", e);
}
}
}
throws IOException {
if (!wmlClient) { //not a wml client
} else { //a wml client
}
}
boolean answer = false;
if (requestHost != null) {
try {
answer = true;
}
} catch (MalformedURLException mfe) {
"WSPRedirecthandlerServlet.handleRequest():"
+ "malformed "
+ "=" + returnToURL);
}
}
}
//requestHost does not include domain under jdk1.3
if ( (answer == false)
answer =true;
}
if (debug.messageEnabled()) {
"WSPRedirectHandlerServlet.checkReturnToHost():"
+ " returning: "
+ ":requestHost=" + requestHost
+ ":returnToHost=" + returnToHost
+ ":returnValue=" + answer);
}
return answer;
}
// TODO: need to find a way to detect client
return false;
}
throws IOException {
if (debug.messageEnabled()) {
"WSPRedirectHandlerServlet.forwardRequest():"
+ "forwardToUrl:" + forwardToUrl);
}
try {
urlConnection.setDoInput(true);
urlConnection.setDoOutput(true);
urlConnection.setUseCaches(false);
while (enumer.hasMoreElements()) {
}
byte[] buffer = new byte[1024];
int len = 0;
}
if (statusLine != null) {
if (debug.messageEnabled()) {
+ " status line:" + statusLine);
}
int j = -1;
if (i != -1) {
}
if ( (i != -1) && (j !=-1) ) {
}
}
}
}
}
} finally {
try {
}
}
}
}
} catch (Exception e) {
if (debug.warningEnabled()) {
+ "exception in finally block:", e);
}
}
}
}
throws IOException {
if (debug.messageEnabled()) {
"WSPRedirectHandlerServlet.sendErrorPageUntrustedHost()");
}
+ "</title>");
+ "</h1>");
}
}