head	1.18;
access;
symbols
	TIGRIS_1_1_0RC2:1.16
	TIGRIS_1_1_0RC1:1.16
	TIGRIS_1_1:1.16.0.4
	TIGRIS_1_0_8:1.16
	TIGRIS_1_0_8RC3:1.16
	TIGRIS_1_0_8RC2:1.16
	TIGRIS_1_0_8RC1:1.16
	TIGRIS_1_0_7:1.16
	TIGRIS_1_0_7RC3:1.16
	TIGRIS_1_0_7RC2:1.16
	TIGRIS_1_0_7RC1:1.16
	TIGRIS_1_0_6:1.16
	TIGRIS_1_0_6RC5:1.16
	TIGRIS_1_0_6RC4:1.16
	TIGRIS_1_0_6RC3:1.16
	TIGRIS_1_0_6RC2:1.16
	TIGRIS_1_0_6RC1:1.16
	TIGRIS_1_0_5:1.16
	TIGRIS_1_0_5RC6:1.16
	TIGRIS_1_0_5RC5:1.16
	TIGRIS_1_0_5RC4:1.16
	TIGRIS_1_0_5RC3:1.16
	TIGRIS_1_0_5RC2:1.16
	TIGRIS_1_0_5RC1:1.16
	TIGRIS_1_0_4:1.16
	TIGRIS_1_0_3:1.16
	TIGRIS_1_0_2:1.16
	TIGRIS_1_0_1:1.16
	TIGRIS_1_0:1.16.0.6
	TIGRIS_1_0_0:1.16
	TIGRIS_1_0_0_RC1:1.16.0.2
	dlr:1.1.1
	TIGRIS_0_9_2_4:1.11.4.1
	TIGRIS_0_9_2_3:1.11
	HELM_PEER_PORT_BRANCH:1.1.1.1
	TURBINE_PEER:1.14
	TIGRIS_0_9_2_1:1.14
	TIGRIS_0_9_2:1.11.0.4
	TIGRIS_0_9_0:1.11.0.2
	TIGRIS_0_8_4:1.7.0.2;
locks; strict;
comment	@# @;


1.18
date	2001.07.19.18.42.23;	author dlr;	state Exp;
branches;
next	1.17;

1.17
date	2001.06.13.19.09.59;	author elicia;	state Exp;
branches;
next	1.16;

1.16
date	2001.03.07.01.53.27;	author lucas;	state Exp;
branches;
next	1.15;

1.15
date	2001.02.21.01.08.25;	author dlr;	state Exp;
branches;
next	1.14;

1.14
date	2001.01.26.18.29.09;	author edk;	state Exp;
branches
	1.14.2.1;
next	1.13;

1.13
date	2001.01.26.05.24.08;	author edk;	state dead;
branches;
next	1.12;

1.12
date	2001.01.23.02.28.52;	author elicia;	state Exp;
branches;
next	1.11;

1.11
date	2000.12.12.20.04.34;	author dlr;	state Exp;
branches
	1.11.4.1;
next	1.10;

1.10
date	2000.12.11.23.39.53;	author dlr;	state Exp;
branches;
next	1.9;

1.9
date	2000.12.07.05.06.59;	author dlr;	state Exp;
branches;
next	1.8;

1.8
date	2000.12.06.00.19.03;	author dlr;	state Exp;
branches;
next	1.7;

1.7
date	2000.11.29.00.46.53;	author dlr;	state Exp;
branches
	1.7.2.1;
next	1.6;

1.6
date	2000.11.29.00.37.31;	author dlr;	state Exp;
branches;
next	1.5;

1.5
date	2000.11.27.20.01.24;	author dlr;	state Exp;
branches;
next	1.4;

1.4
date	2000.11.22.09.36.34;	author dlr;	state Exp;
branches;
next	1.3;

1.3
date	2000.11.21.02.33.41;	author dlr;	state Exp;
branches;
next	1.2;

1.2
date	2000.11.21.02.32.47;	author dlr;	state Exp;
branches;
next	1.1;

1.1
date	2000.11.20.23.51.10;	author dlr;	state Exp;
branches
	1.1.1.1;
next	;

1.1.1.1
date	2001.02.21.00.35.22;	author dlr;	state Exp;
branches;
next	;

1.7.2.1
date	2000.12.06.06.01.05;	author dlr;	state Exp;
branches;
next	1.7.2.2;

1.7.2.2
date	2000.12.07.05.27.36;	author jrobbins;	state Exp;
branches;
next	;

1.11.4.1
date	2001.02.01.18.49.25;	author jrobbins;	state Exp;
branches;
next	;

1.14.2.1
date	2001.01.28.01.02.19;	author dlr;	state dead;
branches;
next	1.14.2.2;

1.14.2.2
date	2001.02.14.00.41.07;	author elicia;	state Exp;
branches;
next	1.14.2.3;

1.14.2.3
date	2001.02.15.20.50.44;	author leonardr;	state Exp;
branches;
next	;


desc
@@


1.18
log
@Updated in light of the port of Joist JoistProperties class to Helm (as class HelmProperties).
@
text
@/* ================================================================
 * Copyright (c) 2000-2001 CollabNet.  All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 * 
 * 1. Redistributions of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer.
 * 
 * 2. Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * 
 * 3. The end-user documentation included with the redistribution, if
 * any, must include the following acknowlegement: "This product includes
 * software developed by CollabNet (http://www.Collab.Net/)."
 * Alternately, this acknowlegement may appear in the software itself, if
 * and wherever such third-party acknowlegements normally appear.
 * 
 * 4. The hosted project names must not be used to endorse or promote
 * products derived from this software without prior written
 * permission. For written permission, please contact info@@collab.net.
 * 
 * 5. Products derived from this software may not use the "Tigris" name
 * nor may "Tigris" appear in their names without prior written
 * permission of CollabNet.
 * 
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL COLLAB.NET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * ====================================================================
 * 
 * This software consists of voluntary contributions made by many
 * individuals on behalf of CollabNet.
 */

package org.tigris.helm.tool;

import java.net.InetAddress;
import java.net.UnknownHostException;
import javax.servlet.*;
import javax.servlet.http.*;

import org.apache.turbine.util.*;

import org.tigris.helm.tool.HelmProperties;

import org.tigris.helm.tool.HtAccess;
import org.tigris.helm.om.*;
/**
 * Writes a MDA cookie for for mod_auth_mda.
 *
 * @@author <a href="mailto:dlr@@collab.net">Daniel Rall</a>
 * @@version $Id: MDACookie.java,v 1.17 2001/06/13 19:09:59 elicia Exp $
 */
public class MDACookie
{
    /**
     * The name of the cookie expected by the mod_auth_mda Apache module 
     * running on the file server.
     */
    private static final String MDA_COOKIE_NAME = "MDAAuth";

    /**
     * The amount of time that the cookie is valid for.
     */
    private static final int MAX_LIFE_TIME = 86400;

    /**
     * The shared secret with the mod_auth_mda Apache module running on the
     * file server.
     */
    private static final String MDA_CRYPT_KEY = 
        HelmProperties.getProperty("mdaCryptKey");
    //"w b@@5b15#664038f.f9d8U19b7e25 664eY9ad2%4393e,a2ef";

    private static final boolean debug = true;

    /**
     * Writes a cookie containing the digital signature to be interpreted by 
     * the Apache module
     * <a href="http://frogdot.de/mod_auth_mda/">mod_auth_mda</a>.  The cookie
     * scheme (i.e. <code>setSecure(boolean)</code>) is set to the same scheme
     * as that of the request.
     *
     * @@param server The server to create the URL for.  The cookie domain is
     *               also determined from this.
     * @@param user   The user whose email address to sign the URL.
     * @@param dl     The download to create a URL for.
     * @@param req    The HTTP request to get the address of.
     * @@param res    The HTTP reponse to set the cookie on.
     */
    public static void write (String server, Project project, User user, 
                              boolean isPublicDownload, HttpServletRequest req,
                              HttpServletResponse res)
        throws UnknownHostException, Exception
    {
	// Get the cookie value.
	String requestIP = req.getRemoteAddr();
	String realm =
	    HtAccess.generateMDARealmMask(isPublicDownload, project.getID());
	String email = user.getEmail();
	String cargo = "";
	long time = new java.util.Date().getTime() / 1000;
	MDA mda = new MDA();
	String mdaVal = mda.compute(requestIP, MDA_CRYPT_KEY, email, realm,
				    cargo, time);
	if (debug) Log.debug("mdaVal=" + mdaVal);
	mdaVal += mda.getTimestamp() + email + '!' + realm + '!' + cargo;

	// Write the cookie data.
	Cookie cookie = new Cookie(MDA_COOKIE_NAME, mdaVal);
	if (debug) Log.debug("server=" + server);
	String cookieDomain = getCookieDomain(server);
	if (debug) Log.debug("cookieDomain=" + cookieDomain);
	cookie.setDomain(cookieDomain);
	//cookie.setComment("mailto:bugs@@tigris.org");
	cookie.setMaxAge(MAX_LIFE_TIME);
	cookie.setPath("/");
	// Indicate whether or not to have the browser only send this cookie 
	// over SSL once it's been set.
	cookie.setSecure(req.getScheme().equals("https"));

	res.addCookie(cookie);
    }

    /**
     * Converts <code>some.host.foo.com</code> to <code>.foo.com</code> and 
     * <code>foo.com</code> to <code>.foo.com</code>.
     *
     * @@param hostname The hostname--including domain--of the host to determine
     *                 the cookie domain for.
     */
    private static String getCookieDomain (String hostname)
        throws UnknownHostException
    {
        int i = hostname.lastIndexOf('.');
        if (i > 0)
	    {
		i = hostname.lastIndexOf('.', i - 1);
		return (i == -1 ? '.' + hostname : hostname.substring(i));
	    }

        // Couldn't determine the cookie domain from the supplied host
        // name.  Default it to the JVM's host.
        String h = InetAddress.getLocalHost().getHostName();
        return (!h.equals(hostname) ? getCookieDomain(h) : null);
    }
}
@


1.17
log
@abstracted out .htaccess methods (for file downloads) into this class
@
text
@d56 1
a56 1
import org.joist.util.JoistProperties;
d64 1
a64 1
 * @@version $Id: MDACookie.java,v 1.16 2001/03/07 01:53:27 lucas Exp $
d84 1
a84 1
        JoistProperties.getProperty("mdaCryptKey");
@


1.16
log
@Corrected regex madness for Torque upgrade.  -dlr
@
text
@d58 1
d64 1
a64 1
 * @@version $Id: MDACookie.java,v 1.15 2001/02/21 01:08:25 dlr Exp $
d111 1
a111 1
	    project.generateMDARealmMask(isPublicDownload);
@


1.15
log
@This is the highest revision from the HELM_PEER_PORT_BRANCH.  The previous import caused too many conflicts to resolve manually
@
text
@a58 1

d63 1
a63 1
 * @@version $Id: MDACookie.java,v 1.14.2.3 2001/02/15 20:50:44 leonardr Exp $
@


1.14
log
@readding all the files as part of the process of returning to the way
things were as of tuesday
@
text
@d2 1
a2 1
 * Copyright (c) 2000 CollabNet.  All rights reserved.
d54 1
a54 3
import org.webmacro.util.Log;

import com.workingdogs.village.DataSetException;
d58 1
a58 2
import org.tigris.helm.domain.User;
import org.tigris.helm.project.Project;
d64 1
a64 1
 * @@version $Id: MDACookie.java,v 1.12 2001/01/23 02:28:52 elicia Exp $
d85 1
a85 3
        //"w b@@5b15#664038f.f9d8U19b7e25 664eY9ad2%4393e,a2ef";

    private static Log log = new Log("mdaCook", "MDACookie");
d104 1
a104 1
                              Boolean isPublicDownload, HttpServletRequest req,
d106 1
a106 1
        throws UnknownHostException, DataSetException, Exception
d108 25
a132 25
        // Get the cookie value.
        String requestIP = req.getRemoteAddr();
        String realm =
            project.generateMDARealmMask(isPublicDownload.booleanValue());
        String email = user.getEmail();
        String cargo = "";
        long time = new java.util.Date().getTime() / 1000;
        MDA mda = new MDA();
        String mdaVal = mda.compute(requestIP, MDA_CRYPT_KEY, email, realm,
                                    cargo, time);
        if (debug) log.info("mdaVal=" + mdaVal);
        mdaVal += mda.getTimestamp() + email + '!' + realm + '!' + cargo;

        // Write the cookie data.
        Cookie cookie = new Cookie(MDA_COOKIE_NAME, mdaVal);
        if (debug) log.info("server=" + server);
        String cookieDomain = getCookieDomain(server);
        if (debug) log.info("cookieDomain=" + cookieDomain);
        cookie.setDomain(cookieDomain);
        //cookie.setComment("mailto:bugs@@tigris.org");
        cookie.setMaxAge(MAX_LIFE_TIME);
        cookie.setPath("/");
        // Indicate whether or not to have the browser only send this cookie 
        // over SSL once it's been set.
        cookie.setSecure(req.getScheme().equals("https"));
d134 1
a134 1
        res.addCookie(cookie);
d149 4
a152 4
        {
            i = hostname.lastIndexOf('.', i - 1);
            return (i == -1 ? '.' + hostname : hostname.substring(i));
        }
@


1.14.2.1
log
@Porting to the Turbine Peer system.  -dlr and leonardr
@
text
@d67 1
a67 1
 * @@version $Id: MDACookie.java,v 1.14 2001/01/26 18:29:09 edk Exp $
@


1.14.2.2
log
@ported to turbine
@
text
@d54 3
a56 1
import org.apache.turbine.util.*;
d60 2
a61 1
import org.tigris.helm.om.*;
d88 3
a90 1
    //"w b@@5b15#664038f.f9d8U19b7e25 664eY9ad2%4393e,a2ef";
d109 1
a109 1
                              boolean isPublicDownload, HttpServletRequest req,
d111 1
a111 1
        throws UnknownHostException, Exception
d113 25
a137 25
	// Get the cookie value.
	String requestIP = req.getRemoteAddr();
	String realm =
	    project.generateMDARealmMask(isPublicDownload);
	String email = user.getEmail();
	String cargo = "";
	long time = new java.util.Date().getTime() / 1000;
	MDA mda = new MDA();
	String mdaVal = mda.compute(requestIP, MDA_CRYPT_KEY, email, realm,
				    cargo, time);
	if (debug) Log.debug("mdaVal=" + mdaVal);
	mdaVal += mda.getTimestamp() + email + '!' + realm + '!' + cargo;

	// Write the cookie data.
	Cookie cookie = new Cookie(MDA_COOKIE_NAME, mdaVal);
	if (debug) Log.debug("server=" + server);
	String cookieDomain = getCookieDomain(server);
	if (debug) Log.debug("cookieDomain=" + cookieDomain);
	cookie.setDomain(cookieDomain);
	//cookie.setComment("mailto:bugs@@tigris.org");
	cookie.setMaxAge(MAX_LIFE_TIME);
	cookie.setPath("/");
	// Indicate whether or not to have the browser only send this cookie 
	// over SSL once it's been set.
	cookie.setSecure(req.getScheme().equals("https"));
d139 1
a139 1
	res.addCookie(cookie);
d154 4
a157 4
	    {
		i = hostname.lastIndexOf('.', i - 1);
		return (i == -1 ? '.' + hostname : hostname.substring(i));
	    }
@


1.14.2.3
log
@Normalized copyright dates.
@
text
@d2 1
a2 1
 * Copyright (c) 2000-2001 CollabNet.  All rights reserved.
d64 1
a64 1
 * @@version $Id: MDACookie.java,v 1.14.2.2 2001/02/14 00:41:07 elicia Exp $
@


1.13
log
@revert this stuff to its state as of 2001/01/24 12:42:00 GMT -- with
the following exceptions, which have some different modifications so
they'll work with changes which have happened in joist:

ProjectNewsEdit.java
SkinManager.java
SkinStyleElementValueManager.java
StyleElementManager.java
StyleManager.java

it compiles.  i dunno if it works, though.
@
text
@@


1.12
log
@write method now accepting boolean isPublic instead of object
@
text
@d67 1
a67 1
 * @@version $Id: MDACookie.java,v 1.11 2000/12/12 20:04:34 dlr Exp $
@


1.11
log
@Changed IS_PRIVATE to IS_PUBLIC--propogating all the way through to the UI.
@
text
@a61 1
import org.tigris.helm.project.Download;
d67 1
a67 1
 * @@version $Id: MDACookie.java,v 1.10 2000/12/11 23:39:53 dlr Exp $
d95 1
a95 1
     * Writes a cookie containing the digital signature to be interpretted by 
d109 1
a109 1
                              Download dl, HttpServletRequest req,
d116 1
a116 1
            project.generateMDARealmMask(dl.isPublic().booleanValue());
@


1.11.4.1
log
@moved changed from HEAD for ProjectDocuments and ProjectDownloads
@
text
@d62 1
d68 1
a68 1
 * @@version $Id: MDACookie.java,v 1.14 2001/01/26 18:29:09 edk Exp $
d96 1
a96 1
     * Writes a cookie containing the digital signature to be interpreted by 
d110 1
a110 1
                              Boolean isPublicDownload, HttpServletRequest req,
d117 1
a117 1
            project.generateMDARealmMask(isPublicDownload.booleanValue());
@


1.10
log
@Extra line of trace.
@
text
@d68 1
a68 1
 * @@version $Id: MDACookie.java,v 1.9 2000/12/07 05:06:59 dlr Exp $
d117 1
a117 1
            project.generateMDARealmMask(dl.isPrivate().booleanValue());
@


1.9
log
@Support two part domains as per IZ #1515.
@
text
@d68 1
a68 1
 * @@version $Id: MDACookie.java,v 1.8 2000/12/06 00:19:03 dlr Exp $
d129 1
@


1.8
log
@Get the crypt key from the properties file.
@
text
@d68 1
a68 1
 * @@version $Id: MDACookie.java,v 1.7 2000/11/29 00:46:53 dlr Exp $
d143 2
a144 1
     * Converts <code>"some.host.foo.com"</code> to <code>".foo.com"</code>.
d156 1
a156 4
            if (i != -1)
            {
                return hostname.substring(i);
            }
@


1.7
log
@The same scheme used to make a request of the servlet should be
employed for the security status of the cookie.
@
text
@d58 2
d68 1
a68 1
 * @@version $Id: MDACookie.java,v 1.6 2000/11/29 00:37:31 dlr Exp $
d88 2
a89 1
        "w b@@5b15#664038f.f9d8U19b7e25 664eY9ad2%4393e,a2ef";
@


1.7.2.1
log
@Dynamically retrieve MDA crypt key (shared secret) from the global configuration.
@
text
@a57 2
import org.joist.util.JoistProperties;

d66 1
a66 1
 * @@version $Id: MDACookie.java,v 1.7 2000/11/29 00:46:53 dlr Exp $
d86 1
a86 2
        JoistProperties.getProperty("mdaCryptKey");
        //"w b@@5b15#664038f.f9d8U19b7e25 664eY9ad2%4393e,a2ef";
@


1.7.2.2
log
@moved a change from HEAD
@
text
@d68 1
a68 1
 * @@version $Id: MDACookie.java,v 1.7.2.1 2000/12/06 06:01:05 dlr Exp $
d143 1
a143 2
     * Converts <code>some.host.foo.com</code> to <code>.foo.com</code> and 
     * <code>foo.com</code> to <code>.foo.com</code>.
d155 4
a158 1
            return (i == -1 ? '.' + hostname : hostname.substring(i));
@


1.6
log
@only spew when in debug mode
@
text
@d66 1
a66 1
 * @@version $Id: MDACookie.java,v 1.5 2000/11/27 20:01:24 dlr Exp $
d95 3
a97 1
     * <a href="http://frogdot.de/mod_auth_mda/">mod_auth_mda</a>.
d132 3
a134 3
        // Have the browser only send this cookie over SSL (after it has been
        // set).
        //cookie.setSecure(true);
@


1.5
log
@Possible fix for all our woes.
@
text
@d66 1
a66 1
 * @@version $Id: MDACookie.java,v 1.4 2000/11/22 09:36:34 dlr Exp $
d90 2
d119 1
a119 1
        //log.info("mdaVal=" + mdaVal);
d125 1
a125 1
        log.info("cookieDomain=" + cookieDomain);
@


1.4
log
@Get the IP of the request for use in the cookie value generation rather
than using the web/app server's.
@
text
@d66 1
a66 1
 * @@version $Id: MDACookie.java,v 1.3 2000/11/21 02:33:41 dlr Exp $
d128 3
a130 1
        cookie.setSecure(true);
@


1.3
log
@Removed legacy comment--cookie domain is no longer hardcoded.
@
text
@d66 1
a66 1
 * @@version $Id: MDACookie.java,v 1.2 2000/11/21 02:32:47 dlr Exp $
d99 1
d103 2
a104 1
                              Download dl, HttpServletResponse res)
d108 1
a110 3
        InetAddress inetAddr = (server != null ? 
                                InetAddress.getByName(server) : 
                                InetAddress.getLocalHost());
d115 2
a116 2
        String mdaVal = mda.compute(inetAddr.getHostAddress(), MDA_CRYPT_KEY, 
                                    email, realm, cargo, time);
@


1.2
log
@Improved implementation.  Beware my kung fu styles.
@
text
@d66 1
a66 1
 * @@version $Id: MDACookie.java,v 1.1 2000/11/20 23:51:10 dlr Exp $
d117 1
a117 1
        //if (debug) log.info("mdaVal=" + mdaVal);
a121 1
        // TODO: Do not hard code.
@


1.1
log
@Set a MDAAuth cookie for mod_auth_mda.
@
text
@d54 2
d66 1
a66 1
 * @@version $Id: $
d88 2
d95 2
a96 1
     * @@param server The server to create the URL for.
d120 1
a120 1
        // TODO: Write the cookie data.
d123 3
a125 1
        cookie.setDomain(".collab.net");
d132 25
@


1.1.1.1
log
@Replacing the HEAD with the HELM_PEER_PORT_BRANCH.
@
text
@d2 1
a2 1
 * Copyright (c) 2000-2001 CollabNet.  All rights reserved.
d54 1
a54 1
import org.apache.turbine.util.*;
d56 3
a58 3
import org.joist.util.JoistProperties;

import org.tigris.helm.om.*;
d64 1
a64 1
 * @@version $Id: MDACookie.java,v 1.14.2.3 2001/02/15 20:50:44 leonardr Exp $
d84 1
a84 4
        JoistProperties.getProperty("mdaCryptKey");
    //"w b@@5b15#664038f.f9d8U19b7e25 664eY9ad2%4393e,a2ef";

    private static final boolean debug = true;
d87 1
a87 1
     * Writes a cookie containing the digital signature to be interpreted by 
d89 1
a89 3
     * <a href="http://frogdot.de/mod_auth_mda/">mod_auth_mda</a>.  The cookie
     * scheme (i.e. <code>setSecure(boolean)</code>) is set to the same scheme
     * as that of the request.
d91 1
a91 2
     * @@param server The server to create the URL for.  The cookie domain is
     *               also determined from this.
a93 1
     * @@param req    The HTTP request to get the address of.
d97 2
a98 3
                              boolean isPublicDownload, HttpServletRequest req,
                              HttpServletResponse res)
        throws UnknownHostException, Exception
d100 23
a122 25
	// Get the cookie value.
	String requestIP = req.getRemoteAddr();
	String realm =
	    project.generateMDARealmMask(isPublicDownload);
	String email = user.getEmail();
	String cargo = "";
	long time = new java.util.Date().getTime() / 1000;
	MDA mda = new MDA();
	String mdaVal = mda.compute(requestIP, MDA_CRYPT_KEY, email, realm,
				    cargo, time);
	if (debug) Log.debug("mdaVal=" + mdaVal);
	mdaVal += mda.getTimestamp() + email + '!' + realm + '!' + cargo;

	// Write the cookie data.
	Cookie cookie = new Cookie(MDA_COOKIE_NAME, mdaVal);
	if (debug) Log.debug("server=" + server);
	String cookieDomain = getCookieDomain(server);
	if (debug) Log.debug("cookieDomain=" + cookieDomain);
	cookie.setDomain(cookieDomain);
	//cookie.setComment("mailto:bugs@@tigris.org");
	cookie.setMaxAge(MAX_LIFE_TIME);
	cookie.setPath("/");
	// Indicate whether or not to have the browser only send this cookie 
	// over SSL once it's been set.
	cookie.setSecure(req.getScheme().equals("https"));
d124 1
a124 24
	res.addCookie(cookie);
    }

    /**
     * Converts <code>some.host.foo.com</code> to <code>.foo.com</code> and 
     * <code>foo.com</code> to <code>.foo.com</code>.
     *
     * @@param hostname The hostname--including domain--of the host to determine
     *                 the cookie domain for.
     */
    private static String getCookieDomain (String hostname)
        throws UnknownHostException
    {
        int i = hostname.lastIndexOf('.');
        if (i > 0)
	    {
		i = hostname.lastIndexOf('.', i - 1);
		return (i == -1 ? '.' + hostname : hostname.substring(i));
	    }

        // Couldn't determine the cookie domain from the supplied host
        // name.  Default it to the JVM's host.
        String h = InetAddress.getLocalHost().getHostName();
        return (!h.equals(hostname) ? getCookieDomain(h) : null);
@


