<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<%@page import="org.eclipse.alf.security.sso.common.ws.federation.passive.WSFedData"%>
<%@page import="org.eclipse.alf.security.sso.common.ws.federation.passive.remotedata.RemoteDataStorage"%>
<%@page import="org.eclipse.alf.security.sso.server.federationserver.PageRedirector"%>
<%@page import="org.eclipse.alf.security.sso.server.federationserver.config.FedSrvConfigConstants"%>
<%@page import="org.eclipse.alf.security.sso.common.ws.federation.passive.WSFedConstants"%>
<%@page import="javax.servlet.*" %>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">



	
	<%
		response.setHeader("Expires","19-Mar-1971 08:23:00 GMT");
		response.setHeader("Cache-control","no-cache");
		response.setHeader("Pragma","no-cache");
		
		String wa = (String) request.getAttribute(WSFedConstants.PARAM_WA);
		String wctx = (String) request.getAttribute(WSFedConstants.PARAM_WCTX);
		String wreply = (String) request.getAttribute(WSFedConstants.PARAM_WREPLY);
		String wresult = (String) request.getAttribute(WSFedConstants.PARAM_WRESULT);
		String wresultptr = (String) request.getAttribute(WSFedConstants.PARAM_WRESULTPTR);
		
		String redirectMethod = (String) request.getAttribute(PageRedirector.METHOD_ATTR);
		if (redirectMethod == null) {
			redirectMethod = (String) request.getParameter(PageRedirector.METHOD_PARAM);
		}
		if ((redirectMethod == null) || ((redirectMethod.equalsIgnoreCase("POST") == false) &&
										 (redirectMethod.equalsIgnoreCase("GET") == false))) {
			
				redirectMethod = FedSrvConfigConstants.HTTP_REDIRECT_METHOD_DEFAULT;
		}
		
		if ((wa == null) || wreply == null || wreply.trim().length() == 0) 	{
			
			String rdKey = request.getParameter(PageRedirector.RD_PARAM);
			if (rdKey != null) {
				RemoteDataStorage rd = RemoteDataStorage.getInstance();
				WSFedData wsfData = (WSFedData) rd.getDataWithRemove(rdKey);
				if (wsfData != null) {
					wa = wsfData.getWa();
					wctx = wsfData.getWctx();
					wreply = wsfData.getWreply();
					wresult = wsfData.getWresult();
					wresultptr = wsfData.getWresultptr();
				}
			}
			if ((wa == null) || wreply == null || wreply.trim().length() == 0) {
				response.setStatus(HttpServletResponse.SC_FORBIDDEN);
				return;
			}
		}
		
		boolean hasResult = ((wresult != null) && (wresult.trim().length() > 0)) ||
													((wresultptr != null) && (wresultptr.trim().length() > 0));
		if (hasResult == false) {
			request.setAttribute("errorMessage", "Empty result"); 
	    	request.getRequestDispatcher("error.jsp").forward(request, response);
		}
	%>

	<head>
		<!-- <meta http-equiv="refresh" content="0;url=<%=wreply%>"/> -->
	    <title>AFL SSO Authentication Request Processed</title>
	</head>

	<body onload="document.forms[0].submit()">
	
		<script type="text/javascript">
			document.write("<p>You are automatically being redirected back... </p>");
		</script>	
		
		<noscript>
			<p>
				<strong>Note:</strong> Since your browser does not support JavaScript, you must press the
				Continue button once to proceed to the requested site.
			</p>
		</noscript>
		
	
		<form id="postRedirect"  action="<%=wreply%>" method="<%=redirectMethod%>">
			<div>
				<input type="hidden" name="wa" value="<%=wa%>" />
				<%if ((wctx != null) && (wctx.trim().length() > 0)) {%>
					<input type="hidden" name="wctx" value="<%=wctx%>"/>
				<%}%>
				<%if ((wresult != null) && (wresult.trim().length() > 0)) {%>
					<input type="hidden" name="wresult" value="<%=wresult%>"/>
				<%}%>
				<%if ((wresultptr != null) && (wresultptr.trim().length() > 0)) {%>
					<input type="hidden" name="wresultptr" value="<%=wresultptr%>"/>
				<%}%>
			</div>
			
			<noscript>
				<div>
				<input type="submit" value="Continue" />
				</div>
			</noscript>
		</form>
	</body>
</html>
