Preserving HTML fragments on redirection

WebSEAL provides an example configuration of HTML redirection. This example uses cookies to store the original URL in the browser and JavaScript to later read that URL and perform the redirection. The example shows how to save the HTML fragment during an authentication operation.

In addition to enabling HTML redirection, modify the JavaScript on the user interface form (such as login.html) to store the HTML fragment for the subsequent redirect. The page before redirection must store the originally requested resource, complete with HTML fragment, in a cookie in the client web browser cookie jar. When the redirection page returns, the example JavaScript reads the cookie value and redirects the client to the originally requested resource while preserving the HTML fragment.

You can use this configuration with any of the login mechanisms for which WebSEAL provides a login page. Uncomment the line of JavaScript that sets the TAMOriginalURL cookie in the corresponding WebSEAL templates. These WebSEAL templates include: login.html, stepuplogin.html and certlogin.html.

For example, to preserve the HTML fragment with forms-based authentication complete the following steps:

Steps

  1. Update the login.html page. Uncomment the bold line of JavaScript to set a cookie named TAMOriginalURL on the client browser with a URI encoded copy of the originally requested URL. This JavaScript is included in the default login.html file that is supplied with WebSEAL.
    <SCRIPT LANGUAGE=JavaScript>
    var warningString = "<B>WARNING:</B> To maintain the login session, 
    				make sure that your browser is configured to accept Cookies."; 
    document.cookie = 'acceptsCookies=yes'; 
    if(document.cookie == ''){ 
    	document.write(warningString); 
    } 
    else{ 
    document.cookie = 'acceptsCookies=yes; expires=Fri, 13-Apr-1970 00:00:00 GMT'; 
    document.cookie = 'TAMOriginalURL=' + encodeURIComponent(window.location) +
    			"; Path=/;";
    }</SCRIPT>

  2. Ensure the html-redirect configuration entry in the [acnt-mgt] stanza specifies the redirect.html file that is supplied with WebSEAL. This file contains the following script, which parses the cookies in the browser and looks for the TAMOriginalURL cookie set by the preceding page. When this cookie is found, it is URI decoded and set to expire immediately. The line containing window.location.href then performs the redirection.
    <SCRIPT LANGUAGE=JavaScript>
    var redirect = "TAMOriginalURL=";
    var cookies = document.cookie.split(';');
    var redirectURL = "%LOCATION%";
    for(var i=0; i<cookies.length; i++) {
    	var cookie = cookies[i];
    	while (cookie.charAt(0)==' ') {
    		cookie = cookie.substring(1, cookie.length);
    		if (cookie.indexOf(redirect) == 0) {
    			redirectURL = cookie.substring(redirect.length, cookie.length);
    			document.cookie = 'TAMOriginalURL=; expires=Thu, 01-Jan-70 00:00:01 GMT;';
    			i = cookies.length;
    			break;
    		}	}}window.location.href = decodeURIComponent(redirectURL);
    </SCRIPT>
    In some situations it is not possible to set a cookie before the redirection is to take place, such as when a local response redirect is performed. For these situations, WebSEAL includes the macro %LOCATION%, which is inserted into the static redirect page. This macro contains the complete URL of the redirection and can be used when cookies cannot be set. However, in this situation any HTTP fragment information is lost.

Parent topic: HTML redirection