head	1.93;
access;
symbols
	TIGRIS_0_9_2_4:1.84.2.1
	TIGRIS_0_9_2_3:1.84.2.1
	HELM_PEER_PORT_BRANCH:1.92.0.2
	TURBINE_PEER:1.92
	TIGRIS_0_9_2_1:1.92
	TIGRIS_0_9_2:1.84.0.2
	TIGRIS_0_9_0:1.59.0.2
	TIGRIS_0_8_4:1.34.0.2
	NEWHELM:1.1.1.1
	TIGRIS_NOV_12_2000:1.1.1;
locks; strict;
comment	@# @;


1.93
date	2001.02.21.02.19.01;	author dlr;	state dead;
branches;
next	1.92;

1.92
date	2001.01.26.18.29.02;	author edk;	state Exp;
branches
	1.92.2.1;
next	1.91;

1.91
date	2001.01.26.05.24.06;	author edk;	state dead;
branches;
next	1.90;

1.90
date	2001.01.25.01.35.10;	author lucas;	state Exp;
branches;
next	1.89;

1.89
date	2001.01.25.00.21.56;	author leonardr;	state Exp;
branches;
next	1.88;

1.88
date	2001.01.24.21.41.49;	author leonardr;	state Exp;
branches;
next	1.87;

1.87
date	2001.01.24.20.42.48;	author dlr;	state Exp;
branches;
next	1.86;

1.86
date	2001.01.19.04.44.20;	author jrobbins;	state Exp;
branches;
next	1.85;

1.85
date	2001.01.19.03.47.40;	author stack;	state Exp;
branches;
next	1.84;

1.84
date	2001.01.18.21.54.11;	author stack;	state Exp;
branches
	1.84.2.1;
next	1.83;

1.83
date	2001.01.18.07.21.44;	author dlr;	state Exp;
branches;
next	1.82;

1.82
date	2001.01.18.07.20.38;	author dlr;	state Exp;
branches;
next	1.81;

1.81
date	2001.01.18.07.18.19;	author dlr;	state Exp;
branches;
next	1.80;

1.80
date	2001.01.17.23.47.38;	author dlr;	state Exp;
branches;
next	1.79;

1.79
date	2001.01.17.02.25.08;	author dlr;	state Exp;
branches;
next	1.78;

1.78
date	2001.01.16.22.22.59;	author dlr;	state Exp;
branches;
next	1.77;

1.77
date	2001.01.16.22.19.11;	author dlr;	state Exp;
branches;
next	1.76;

1.76
date	2001.01.16.22.18.09;	author dlr;	state Exp;
branches;
next	1.75;

1.75
date	2001.01.12.22.25.27;	author leonardr;	state Exp;
branches;
next	1.74;

1.74
date	2001.01.12.21.00.20;	author leonardr;	state Exp;
branches;
next	1.73;

1.73
date	2001.01.11.19.26.25;	author dlr;	state Exp;
branches;
next	1.72;

1.72
date	2001.01.11.19.15.41;	author dlr;	state Exp;
branches;
next	1.71;

1.71
date	2001.01.10.01.52.19;	author leonardr;	state Exp;
branches;
next	1.70;

1.70
date	2001.01.08.23.25.02;	author dlr;	state Exp;
branches;
next	1.69;

1.69
date	2001.01.05.21.42.38;	author leonardr;	state Exp;
branches;
next	1.68;

1.68
date	2001.01.05.00.13.13;	author kmaples;	state Exp;
branches;
next	1.67;

1.67
date	2001.01.04.02.18.39;	author manoj;	state Exp;
branches;
next	1.66;

1.66
date	2001.01.03.00.15.30;	author kmaples;	state Exp;
branches;
next	1.65;

1.65
date	2000.12.30.02.14.01;	author leonardr;	state Exp;
branches;
next	1.64;

1.64
date	2000.12.28.21.09.29;	author dlr;	state Exp;
branches;
next	1.63;

1.63
date	2000.12.27.21.10.01;	author leonardr;	state Exp;
branches;
next	1.62;

1.62
date	2000.12.23.01.23.18;	author dlr;	state Exp;
branches;
next	1.61;

1.61
date	2000.12.23.00.46.20;	author dlr;	state Exp;
branches;
next	1.60;

1.60
date	2000.12.22.03.02.59;	author dlr;	state Exp;
branches;
next	1.59;

1.59
date	2000.12.18.23.44.01;	author leonardr;	state Exp;
branches
	1.59.2.1;
next	1.58;

1.58
date	2000.12.15.18.58.40;	author leonardr;	state Exp;
branches;
next	1.57;

1.57
date	2000.12.15.04.37.45;	author leonardr;	state Exp;
branches;
next	1.56;

1.56
date	2000.12.14.19.39.28;	author dlr;	state Exp;
branches;
next	1.55;

1.55
date	2000.12.14.19.24.27;	author dlr;	state Exp;
branches;
next	1.54;

1.54
date	2000.12.14.03.04.17;	author edk;	state Exp;
branches;
next	1.53;

1.53
date	2000.12.14.02.28.47;	author edk;	state Exp;
branches;
next	1.52;

1.52
date	2000.12.13.01.27.28;	author leonardr;	state Exp;
branches;
next	1.51;

1.51
date	2000.12.13.01.24.14;	author leonardr;	state Exp;
branches;
next	1.50;

1.50
date	2000.12.13.01.21.52;	author leonardr;	state Exp;
branches;
next	1.49;

1.49
date	2000.12.12.21.46.40;	author leonardr;	state Exp;
branches;
next	1.48;

1.48
date	2000.12.09.02.55.11;	author edk;	state Exp;
branches;
next	1.47;

1.47
date	2000.12.09.01.59.45;	author edk;	state Exp;
branches;
next	1.46;

1.46
date	2000.12.08.22.02.35;	author leonardr;	state Exp;
branches;
next	1.45;

1.45
date	2000.12.06.23.01.24;	author dlr;	state Exp;
branches;
next	1.44;

1.44
date	2000.12.06.19.37.41;	author dlr;	state Exp;
branches;
next	1.43;

1.43
date	2000.12.05.23.53.30;	author leonardr;	state Exp;
branches;
next	1.42;

1.42
date	2000.12.05.23.28.58;	author leonardr;	state Exp;
branches;
next	1.41;

1.41
date	2000.12.05.22.09.41;	author leonardr;	state Exp;
branches;
next	1.40;

1.40
date	2000.12.05.04.56.42;	author edk;	state Exp;
branches;
next	1.39;

1.39
date	2000.12.05.04.26.29;	author edk;	state Exp;
branches;
next	1.38;

1.38
date	2000.12.05.04.05.11;	author dlr;	state Exp;
branches;
next	1.37;

1.37
date	2000.12.05.02.54.12;	author dlr;	state Exp;
branches;
next	1.36;

1.36
date	2000.12.05.02.19.16;	author leonardr;	state Exp;
branches;
next	1.35;

1.35
date	2000.12.04.23.00.22;	author dlr;	state Exp;
branches;
next	1.34;

1.34
date	2000.12.01.22.18.49;	author elicia;	state Exp;
branches
	1.34.2.1;
next	1.33;

1.33
date	2000.12.01.10.44.57;	author dlr;	state Exp;
branches;
next	1.32;

1.32
date	2000.12.01.10.19.18;	author dlr;	state Exp;
branches;
next	1.31;

1.31
date	2000.12.01.09.23.43;	author dlr;	state Exp;
branches;
next	1.30;

1.30
date	2000.11.30.23.56.41;	author leonardr;	state Exp;
branches;
next	1.29;

1.29
date	2000.11.30.23.09.32;	author dlr;	state Exp;
branches;
next	1.28;

1.28
date	2000.11.30.08.15.21;	author dlr;	state Exp;
branches;
next	1.27;

1.27
date	2000.11.29.22.35.59;	author elicia;	state Exp;
branches;
next	1.26;

1.26
date	2000.11.29.01.16.32;	author leonardr;	state Exp;
branches;
next	1.25;

1.25
date	2000.11.28.21.08.23;	author leonardr;	state Exp;
branches;
next	1.24;

1.24
date	2000.11.23.03.34.12;	author edk;	state Exp;
branches;
next	1.23;

1.23
date	2000.11.22.17.22.23;	author leonardr;	state Exp;
branches;
next	1.22;

1.22
date	2000.11.22.02.42.26;	author leonardr;	state Exp;
branches;
next	1.21;

1.21
date	2000.11.22.01.51.08;	author edk;	state Exp;
branches;
next	1.20;

1.20
date	2000.11.20.21.43.16;	author leonardr;	state Exp;
branches;
next	1.19;

1.19
date	2000.11.17.22.45.59;	author leonardr;	state Exp;
branches;
next	1.18;

1.18
date	2000.11.17.21.49.37;	author leonardr;	state Exp;
branches;
next	1.17;

1.17
date	2000.11.17.19.49.13;	author leonardr;	state Exp;
branches;
next	1.16;

1.16
date	2000.11.17.08.12.17;	author edk;	state Exp;
branches;
next	1.15;

1.15
date	2000.11.17.02.43.31;	author leonardr;	state Exp;
branches;
next	1.14;

1.14
date	2000.11.17.02.18.31;	author leonardr;	state Exp;
branches;
next	1.13;

1.13
date	2000.11.17.00.29.21;	author leonardr;	state Exp;
branches;
next	1.12;

1.12
date	2000.11.16.00.09.52;	author leonardr;	state Exp;
branches;
next	1.11;

1.11
date	2000.11.15.22.48.40;	author leonardr;	state Exp;
branches;
next	1.10;

1.10
date	2000.11.15.22.32.07;	author leonardr;	state Exp;
branches;
next	1.9;

1.9
date	2000.11.15.21.31.02;	author leonardr;	state Exp;
branches;
next	1.8;

1.8
date	2000.11.15.20.09.25;	author stack;	state Exp;
branches;
next	1.7;

1.7
date	2000.11.15.18.49.04;	author leonardr;	state Exp;
branches;
next	1.6;

1.6
date	2000.11.15.01.39.02;	author leonardr;	state Exp;
branches;
next	1.5;

1.5
date	2000.11.15.01.19.08;	author leonardr;	state Exp;
branches;
next	1.4;

1.4
date	2000.11.15.00.53.40;	author leonardr;	state Exp;
branches;
next	1.3;

1.3
date	2000.11.14.22.57.48;	author leonardr;	state Exp;
branches;
next	1.2;

1.2
date	2000.11.13.19.18.49;	author leonardr;	state Exp;
branches;
next	1.1;

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

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

1.34.2.1
date	2000.12.05.06.34.17;	author jrobbins;	state Exp;
branches;
next	1.34.2.2;

1.34.2.2
date	2000.12.09.06.46.37;	author edk;	state Exp;
branches;
next	;

1.59.2.1
date	2001.01.13.02.36.48;	author leonardr;	state Exp;
branches;
next	;

1.84.2.1
date	2001.01.30.04.37.22;	author jrobbins;	state Exp;
branches;
next	;

1.92.2.1
date	2001.01.28.01.02.17;	author dlr;	state dead;
branches;
next	;


desc
@@


1.93
log
@Moved to om package by Peer port.
@
text
@/* ================================================================
 * Copyright (c) 2000 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 COLLABNET 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.domain;

import java.util.*;
import java.sql.*;

import com.workingdogs.village.*;

import gnu.regexp.RE;
import gnu.regexp.REException;

import org.apache.turbine.services.db.TurbineDB;
import org.apache.turbine.util.db.pool.DBConnection;

import org.webmacro.servlet.WebContext;
import org.webmacro.util.Log;
import org.webmacro.engine.BuildContext;
import org.webmacro.servlet.HandlerException;

import org.joist.database.*;
import org.joist.JoistException;

import org.tigris.helm.DoesNotExist;
import org.tigris.helm.database.*;
import org.tigris.helm.domain.Role;
import org.tigris.helm.project.Project;
import org.tigris.helm.tool.*;
import org.tigris.helm.security.*;
import org.tigris.helm.domain.UserGroup;
import org.tigris.helm.business.Host;
import org.tigris.helm.AlreadyExists;

import org.tigris.anzu.client.MailingAliasSpec;

/**
 * Tigris user.
 *
 * @@author <a href="mailto:dlr@@collab.net">Daniel Rall</a>
 * @@author <a href="mailto:leonardr@@collab.net">Leonard Richardson</a>
 * @@author <a href="mailto:edk@@collab.net">Ed Korthof</a>
 * @@author <a href="mailto:elicia@@collab.net">Elicia David</a>
 * @@author <a href="mailto:jrobbins@@collab.net">Jason Robbins</a>
 * @@version $Id: User.java,v 1.92 2001/01/26 18:29:02 edk Exp $
 */
public class User extends BusinessObject implements Comparable
{
    /**
     * The password ticket database field.
     */
    private static final String PASSWD_TICKET = "passwordTicket";

    /**
     * The name of the template used to create the body of the user role 
     * request email.
     */
    private static final String ROLE_REQ_TMPL = "UserRoleRequest.wm";

    /**
     * The error message used in the exception thrown when password
     * confirmation fails.
     */
    private static final String PASSWD_CONFIRM_ERR =
        "Your passwords do not match";

    /**
     * The regular expression used to validate user names.
     */
    private static RE userNameRE;

    /**
     * The regular expression used to validate real names.
     */
    private static RE realNameRE;

    /**
     * The login name of the guest user.
     */
    private static final String GUEST_LOGIN_ID = "guest";

    /**
     * The log file to write to.
     */
    private static Log log = new Log("user", "User");

    /**
     * Whether to log debugging information.
     */
    private static final boolean debug = true;

    /**
     * Tigris guest user.
     */
    private static User guest;

    protected UserManager uMgr;

    protected DomainManager domMgr;

    protected UserUserGroupManager usrGrpMgr;

    protected UserRoleProjectManager urpMgr;

    protected ProjectManager pMgr;

    protected RoleManager rMgr;


    ////////////////////////////////////////////////////////////////////
    // Class statics
    ////////////////////////////////////////////////////////////////////

    static
    {
        try
        {
            // HELP: Are these things thread safe?
            userNameRE = new RE("^[\\w]{1,16}$");
            realNameRE = new RE("^[\\w' \\-\\.\\,\\(\\)]+$");
        }
        catch (REException e)
        {
            log.exception(e);
        }

        // Retrieve the guest user during class initialization since he will
        // be used so often.
        DBConnection dbConn = null;
        try
        {
            dbConn = TurbineDB.getConnection();
            DataManager dMgr = new DataManager();
            guest = new User(dbConn.getConnection(), dMgr, 
                             new DomainManager(dMgr).getHostDomainID(),
                             GUEST_LOGIN_ID);
        }
        catch (Exception e)
        {
            log.error("Could not create guest user");
        }
        finally
        {
            try
            {
                TurbineDB.releaseConnection(dbConn);
            }
            catch (Exception dbEx)
            {
                log.error("Error releasing database connection: " +
                          dbEx.getMessage());
            }
        }
    }

    /**
     * Checks whether a user name is valid.
     *
     * @@param userName The user name to check.
     * @@return         Whether the name is valid.
     */
    public static boolean isValidUserName (String userName)
    {
        return (userName != null && userNameRE.isMatch(userName));
    }

    /**
     * Checks whether a real name is valid.
     *
     * @@param realName The real name to check.
     * @@return         Whether the name is valid.
     */
    public static boolean isValidRealName (String realName)
    {
        return (realName != null && realNameRE.isMatch(realName));
    }

    /**
     * Checks whether the specified user exists.
     */
    public static boolean exists (Connection c, DataManager dMgr,
                                  String domainID, String loginID)
        throws JoistDatabaseException, DataSetException, SQLException
    {
        try
        {
            new User(c, dMgr, domainID, loginID);
            return true;
        }
        catch (DoesNotExist e)
        {
            return false;
        }
    }


    ////////////////////////////////////////////////////////////////////
    // Constructors
    ////////////////////////////////////////////////////////////////////

    /**
     * Factory method for getting a handle to a business object by database
     * key.  This method should be used in place of the public constructor 
     * with the signature <code>User(Connection, DataManager, String)</code>.
     */
    public static User getInstance (Connection conn, DataManager dMgr,
                                    String id)
        throws SQLException, DataSetException, JoistDatabaseException,
               DoesNotExist
    {
        Dictionary cache = getCache(User.class);
        User user = (User)cache.get(id);
        if (user == null)
        {
            synchronized (cache)
            {
                user = (User)cache.get(id);
                if (user == null)
                {
                    user = new User(conn, dMgr, id);
                    cache.put(id, user);
                }
            }
        }
        return user;
    }

    /**
     * Returns the guest user.  Only one User instance ever exists for the
     * guest user.
     *
     * @@return The application's guest user.
     */
    public static final User getGuest ()
    {
        return guest;
    }

    /**
     * Constructor for a user which has yet to be created.
     */
    public User (Connection c, DataManager dMgr)
    {
        super(c, dMgr);
    }

    /**
     * Constructor for a business object which already exists--accessed by
     * Record.
     */
    public User (Connection c, DataManager dMgr, Record rec)
        throws DoesNotExist, DataSetException
    {
        super(c, dMgr, rec);
    }

    /**
     * Constructor for a user which already exists -- accessed by
     * userID.  Use <code>getInstance()</code> for public access.
     */
    protected User (Connection c, DataManager dMgr, String userID)
        throws SQLException, DataSetException, JoistDatabaseException,
               DoesNotExist
    {
        super(c, dMgr);
        setRecord(uMgr.getUser(c, userID));
    }

    /**
     * Constructor for a user which already exists.
     *
     * @@param domainID The database key of the domain to get the user from.
     * @@param loginID  The user's login name.
     */
    public User (Connection c, DataManager dMgr, String domainID,
                 String loginID)
        throws SQLException, DataSetException, JoistDatabaseException,
               DoesNotExist
    {
        super(c, dMgr);
        setRecord(domMgr.getUserForLoginID(c, domainID, loginID));
    }

    /**
     * Constructor for a user which already exists -- accessed by
     * email address.
     */
    public User (Connection c, String email, DataManager dMgr, String domainID)
        throws SQLException, DataSetException, JoistDatabaseException,
               DoesNotExist
    {
        super(c, dMgr);
        setRecord(domMgr.getUserForEmail(c, domainID, email));
    }

    /**
     * <b>FIXME: Could get user from the wrong domain!</b>
     * <p>
     * Constructor for a user which already exists.
     *
     * @@param realName The user's real name.
     * @@param domainID The database key of the domain to get the user from.
     */
    public User (String realName, Connection c, DataManager dMgr,
                 String domainID)
        throws SQLException, DataSetException, JoistDatabaseException,
               DoesNotExist
    {
        super(c, dMgr);
        setRecord(uMgr.getUserForName(c, realName));
    }

    /**
     * Constructor for a new user. Adds the user, adding them to the 
     * default user group.
     */
    public User (AccessControlList acl, Connection c, DataManager dMgr, 
                 WebContext context, String domainID, String realName,
                 String loginID, String password, String email)
        throws SQLException, DataSetException, JoistDatabaseException,
               UpdateException, AlreadyExists, DoesNotExist,
               ACLException
    {
        this(acl, c, dMgr, context, domainID, realName,
             loginID, password, email, null);
    }

    /**
     * Constructor for a new user. Adds the user, adding them to the 
     * default user group.
     */
    public User (AccessControlList acl, Connection c, DataManager dMgr, 
                 WebContext context, String domainID, String realName,
                 String userName, String password, String email,
                 String organization)
        throws SQLException, DataSetException, JoistDatabaseException,
               UpdateException, AlreadyExists, DoesNotExist,
               ACLException
    {
        super(c, dMgr);
        acl.assertPermissionForDomain("User - Add", domainID);

        MailingAliasSpec alias;
        try {
            Domain domain = new Domain(c,dMgr,domainID);
            alias = new MailingAliasSpec(domain.getName(), "www", userName);
            alias.setDestination(email);

            alias.create();
        } catch (org.tigris.anzu.exception.AlreadyExists e) {
            if (debug) log.info("caught AlreadyExists in user creation");
            throw new AlreadyExists
                ("user " + userName + " already exists");
        } catch (Exception e) {
            log.exception(e);
            if (debug) log.error("unable to setup email: " + e.getMessage());
            throw new UpdateException("Unable to setup e-mail alias");
        }
        
        Integer userID = uMgr.addUser(conn, context, domainID, realName, 
                                      userName, password, email,
                                      organization, UserType.REGULAR);
        getCache().put(userID.toString(), this);

        try {
            setRecord(uMgr.getUser(conn, userID.toString()));

            // Add the user to the appropriate user group.
            UserGroup.addUserToDomainUserGroup(conn, dMgr, domainID, this);
        } catch (Exception e) {
            try {
                alias.delete();
            } catch (HandlerException he) {
                log.exception(he);
                log.error("Error attempting to delete alias for " + userName +
                          " as part of rollback: " + he.getMessage());
            }
            log.error("Unable to finish creating User: " + e.getMessage());
            log.exception(e);
            if (e instanceof InsertFailedException) {
                throw new org.tigris.helm.AlreadyExists
                    ("Unable to add db entry: User exists: " + userName);
            }
            throw new UpdateException("Unable to finish creating User: " +
                                      e.getMessage());
        }
    }

    /**
     * Creates all the various database managers for this instance.
     *
     * @@param dMgr The associated data manager.
     */
    protected void createManagers ()
    {
        uMgr = (UserManager) dMgr.getManager 
            ("org.joist.database.UserManager");        
        domMgr = (DomainManager) dMgr.getManager 
            ("org.tigris.helm.database.DomainManager");        
        usrGrpMgr = (UserUserGroupManager) dMgr.getManager 
            ("org.tigris.helm.database.UserUserGroupManager");        
        urpMgr = (UserRoleProjectManager) dMgr.getManager 
            ("org.tigris.helm.database.UserRoleProjectManager");        
        pMgr = (ProjectManager) dMgr.getManager 
            ("org.tigris.helm.database.ProjectManager");
        rMgr = (RoleManager) dMgr.getManager 
            ("org.joist.database.RoleManager");
    }

    protected final String getTableName()
    {
        return UserManager.TABLE_NAME;
    }


    ////////////////////////////////////////////////////////////////////
    // Read-write methods.
    ////////////////////////////////////////////////////////////////////

    /**
     * Determines whether the user is the application's guest user.  Useful in
     * WebMacro template code.
     *
     * @@return Whether the guest user.
     */
    public boolean isGuest ()
        throws DataSetException
    {
        return getID().equals(getGuest().getID());
    }

    /**
     * Determines whether the password ticket is valid.
     *
     * @@param ticket The ticket to compare.
     */
    public boolean isValidPasswordTicket (String ticket)
        throws DataSetException, SQLException
    {
        // TODO: Fail on database NULL.
        return (ticket != null && 
                ticket.equals(rec.getValue(PASSWD_TICKET).asString()));
    }

    /**
     * Creates and saves a new password ticket.
     */
    public String newPasswordTicket ()
        throws DataSetException, SQLException
    {
        String ticket = Nonce.buildNonce();
        setPasswordTicket(ticket);
        return ticket;
    }

    /**
     * Removes a used password ticket.
     */
    public void clearPasswordTicket ()
        throws DataSetException, SQLException
    {
        setPasswordTicket("NULL");
    }

    private void setPasswordTicket (String ticket)
        throws DataSetException, SQLException
    {
        PreparedStatement stmt = null;
        try
        {
            stmt = conn.prepareStatement
                ("update " + UserManager.TABLE_NAME + " set " + PASSWD_TICKET +
                 "=" + escapeAndQuoteSQL(ticket) + " where " +
                 UserManager.USER_ID + "=?");
            stmt.setString(1, getID());
            stmt.executeUpdate();
        }
        finally
        {
            if (stmt != null) stmt.close();
        }
    }

    /**
     * Totally deletes a user, disassociating them from all user
     * groups.
     */
    public void delete(AccessControlList acl)
        throws DataSetException, SQLException, JoistDatabaseException, 
               ACLException, DoesNotExist
    {
        acl.assertPermissionForDomain("User - Delete", getDomainID());

        User deletingUser = new User(conn, dMgr, acl.getUserID());

        DomainManager domMgr = (DomainManager) dMgr.getManager 
            ("org.tigris.helm.database.DomainManager");        
        ProjectManager pMgr = (ProjectManager) dMgr.getManager 
            ("org.tigris.helm.database.ProjectManager");        
        String domainName = domMgr.getDomainName(getDomainID());

        //Remove the user from all composite users.
        for (Iterator i = getGroups().iterator(); i.hasNext();)
        {
            UserGroup u = (UserGroup)i.next();
            removeFromGroup(acl, u);
        }

        //Remove the user from all Issuezilla databases they're in.
        AccessControlList userACL = new AccessControlList(conn, dMgr, 
                                                          getID());
        DataSet projects = pMgr.getProjectsForDomain(conn, 
                                                     getDomainID());

        //Revoke all the user's roles.
        urpMgr.deleteRolesForUser(conn, getID());

        // Having deleted the user from individual projects, delete
        // the user from all projects in domain.  Mostly affects 
        // Issuezilla.  
        TigrisUpdate.deleteUser(conn, dMgr, deletingUser, getDomain(), this);

        //Remove the user proper.
        uMgr.deleteUser(conn, getID());

        // remove the alias
        try {
            Domain domain = getDomain(); 
            MailingAliasSpec alias =
                new MailingAliasSpec(domain.getName(), "www", getLoginID());
            alias.delete();
        } catch (Exception e) { // Domain constructor throws this ... bleah
            log.error("unable to delete email address for " + getName() +
                      ": " + e.getMessage());
            log.exception(e);
        }
    }

    /**
     * Removes a user from a particular user group.
     */
    public void removeFromGroup(AccessControlList acl, UserGroup group)
        throws DataSetException, SQLException, JoistDatabaseException, 
               ACLException, DoesNotExist
    {
        group.removeUser(acl, this);
    }


    /**
     * Return a list of all groups to which this user belongs, including
     * the special domain group.
     */
    public List getGroups()
        throws DataSetException, SQLException
    {
        ArrayList groups = new ArrayList();
        DataSet groupSet = usrGrpMgr.getCompositesForBase(conn, getID());
        for (int i = 0; i < groupSet.size(); i++)
        {
            try 
            {
		        Record r = groupSet.getRecord(i);
		        String id 
                    = r.getValue(UserUserGroupManager.USER_GROUP_ID).asString();
                groups.add(new UserGroup(conn, dMgr, id));
            } catch (DoesNotExist ignore) {
            } catch (JoistDatabaseException e) {
		        throw new DataSetException("Got JoistDatabaseException: " 
                    + e.getMessage());
	        }
        }

        return groups;
    }

    /**
     * Return a list of all groups to which this user belongs, not including
     * the special domain group.
     */
    public List getRegularGroups()
        throws DataSetException, SQLException
    {
        List allGroups = getGroups();
        for (Iterator i = allGroups.iterator(); i.hasNext();)
        {
            UserGroup g = (UserGroup)i.next();
            if (g.isHost() || g.isDomain())
            {
                allGroups.remove(g);
            }
        }
        return allGroups;
    }

    public void updateInfo(AccessControlList acl, 
                           WebContext context, 
                           String loginID, String email, 
                           String realName, String organization, 
                           String passwd, String passwdConfirm)
        throws DataSetException, SQLException, JoistDatabaseException, 
               ACLException
    {
        assertEditPermission(acl);
        // TODO: Commit uncommented once tested.
        //assertMatch(passwd, passwdConfirm, PASSWD_CONFIRM_ERR);
        if (!email.equals(getEmail())) {
            try {
                Domain domain = new Domain(conn, dMgr, getDomainID());
                MailingAliasSpec alias =
                    new MailingAliasSpec(domain.getName(), "www", loginID);
                alias.setDestination(email);
                alias.update();
            } catch (Exception e) { // Domain constructor throws this ... bleah
                log.error("unable to update email address for " + loginID +
                          ": " + e.getMessage());
                log.exception(e);
                // TODO : should we throw an exception?  this method should
                // really only throw UpdateException & ACLException ...
                // UpdateException would be the right thing to throw.
            }
        }

        if (!acl.hasPermission("User - Edit", getDomainID()))
        {
            organization = getOrganization();
        }

        Dictionary cache = getCache();
        synchronized (cache)
        {
            uMgr.updateUser(conn, context, getID(), loginID, email,
                            realName, organization, passwd);
            cache.remove(getID());
        }
    }

    /**
     * Updates the user's password.
     *
     * @@param passwd        The new password to use.
     * @@param passwdConfirm Confirmation of the new password.
     *
     * @@throws JoistException Passwords do not match.
     */
    public void updatePassword (WebContext ctx, String passwd, 
                                String passwdConfirm)
        throws DataSetException, SQLException, JoistDatabaseException, 
               JoistException, ACLException
    {
        assertEditPermission(getACL());
        assertMatch(passwd, passwdConfirm, PASSWD_CONFIRM_ERR);
        uMgr.updateUser(conn, ctx, getID(), getLoginID(), null, null, passwd);
    }

    private final void assertEditPermission (AccessControlList acl)
        throws ACLException, DataSetException
    {
        if (debug) log.info("ACL userID is " + acl.getUserID() + 
                            " and userID is " + getID());
        if (!(acl.getUserID().equals(getID()) &&
              acl.hasPermissionForDomain("User - Edit - Self", getDomainID())))
        {
            acl.assertPermissionForDomain("User - Edit", getDomainID());
        }
    }

    public final boolean canBeViewedBy (AccessControlList acl)
        throws ACLException, DataSetException
    {
        boolean viewable = false;
        if (acl.hasPermissionForDomain("User - View", getDomainID())
            || (acl.getUserID().equals(getID()) &&
                acl.hasPermissionForDomain("User - View - Self", 
                                           getDomainID())))
        {
            viewable = true;
        }
        return viewable;
    }

    /**
     * Asserts that two values match (or are both <code>null</code>).  Useful
     * in password confirmation.
     */
    private static final void assertMatch (String value, String confirm,
                                           String errMsg)
        throws JoistException
    {
        if ( !((value == null && confirm == null) ||
               (value != null && confirm != null && value.equals(confirm))) )
        {
            throw new JoistException(errMsg);
        }
    }

    /**
     * Grants the host admin role to a user.
     */
    public void grantHostAdminRole(AccessControlList acl)
        throws SQLException, DataSetException, JoistDatabaseException, 
               ACLException, DoesNotExist
    {
        acl.assertPermissionForHost("Host Role - Grant");
        Role hostRole = new Role(conn, dMgr, "Host Admin", false);
        //If they already have it, don't bother.
        if (getACL().hasRoleInHost(hostRole.getID()))
        {
            return;
        }
        urpMgr.grant(conn, getID(), hostRole.getID(), pMgr.getHostProjectID(),
                     acl.getUserID());
    }

    /**
     * Revokes the host admin role for a user.
     */
    public void revokeHostAdminRole(AccessControlList acl)
        throws SQLException, DataSetException, JoistDatabaseException,
               ACLException, DoesNotExist
    {        
        acl.assertPermissionForHost("Host Role - Grant");
        Role hostRole = new Role(conn, dMgr, "Host Admin", false);
        //If they don't already have it, don't bother.
        if (!getACL().hasRoleInHost(hostRole.getID()))
        {
            return;
        }
        urpMgr.revoke(conn, null, getID(), hostRole.getID(),
                      pMgr.getHostProjectID());
    }

    /**
     * Grants the domain admin role to a user.
     */
    public void grantDomainAdminRole(AccessControlList acl, String domainID)
        throws SQLException, DataSetException, JoistDatabaseException,
               ACLException, DoesNotExist
    {        
        acl.assertPermissionForDomain("Domain Role - Grant", domainID);
        Role domainRole = new Role(conn, dMgr, "Domain Admin", false);
        //If they don't already have it, don't bother.
        if (getACL().hasRoleInDomain(domainRole.getID(), domainID))
        {
            return;
        }
        String projectID = pMgr.getDomainProjectID(domainID);
        urpMgr.grant(conn, getID(), domainRole.getID(), projectID, 
                     acl.getUserID());
    }

    /**
     * Revokes the domain admin role for a user.
     */
    public void revokeDomainAdminRole(AccessControlList acl, String domainID)
        throws SQLException, DataSetException, JoistDatabaseException,
               ACLException, DoesNotExist
    {
        acl.assertPermissionForDomain("Domain Role - Grant", domainID);
        Role domainRole = new Role(conn, dMgr, "Domain Admin", false);
        //If they don't already have it, don't bother.
        if (!getACL().hasRoleInDomain(domainRole.getID(), domainID))
        {
            return;
        }
        String projectID = pMgr.getDomainProjectID(domainID);
        urpMgr.revoke(conn, null, getID(), domainRole.getID(), projectID);
    }

    /**
     * Grants the "Click Through Viewer" role to a user.
     */
    public void setClickThroughAsViewed(Domain domain)
        throws SQLException, DataSetException, JoistDatabaseException,
               DoesNotExist
    {        
        String projectID = domain.getSpecialProject().getID();
        String rootID = uMgr.getUserForLoginID(conn, "root")
            .getValue(UserManager.USER_ID).asString();
        urpMgr.grantNamedRole(conn, getID(), "Click-through Viewer", 
                              projectID, rootID);
    }

    public void grantRole(AccessControlList acl, Role role)
        throws SQLException, DataSetException, JoistDatabaseException,
               ACLException, DoesNotExist
    {
        grantRole(acl, role, new Host(conn, dMgr).getSpecialProject());
    }

    public void grantRole(AccessControlList acl, Role role, Domain domain)
        throws SQLException, DataSetException, JoistDatabaseException,
               ACLException, DoesNotExist
    {
        grantRole(acl, role, domain.getSpecialProject());
    }

    public void grantRole(AccessControlList acl, Role role, Project project)
        throws SQLException, DataSetException, JoistDatabaseException,
               ACLException, DoesNotExist
    {
        User grantingUser = new User(conn, dMgr, acl.getUserID());
        grantingUser.assertRoleGrantPermission(project);
        if (getACL().hasRoleInProject(role.getName(), project.getID()))
        {
            return;
        }
        urpMgr.grant(conn, getID(), role.getID(), project.getID(), 
                     acl.getUserID());
        // This is kind of ugly.  But project owners should have their
        // names in a special alias -- owner@@{project}.{domain}
        if (role.getName().equals("Project Owner")) {
            AnzuTigrisTask.setOwnerAlias(conn, dMgr, grantingUser.getID(),
                    project.getID(), true);
        }
    }

    public boolean requestRole(AccessControlList acl, Role role, 
                               Project project)
        throws SQLException, DataSetException, JoistDatabaseException,
               DoesNotExist, JoistException, ACLException
    {
        String pID = project.getID();
        if ((!project.isApproved()
             && acl.hasPermissionForProject("Unapproved Project Role - Grant",
                                            pID))
            || (project.isApproved() 
                && acl.hasPermissionForProject("Project Role - Grant", pID)))
        {
            urpMgr.grant(conn, getID(), role.getID(), project.getID(), 
                         acl.getUserID());
            // This is really ugly here.  But project owners should have their
            // names in a special alias -- owner@@{project}.{domain}
            if (role.getName().equals("Project Owner")) {
                AnzuTigrisTask.setOwnerAlias(conn, dMgr, null,
                        project.getID(), true);
            }
            return true;
        } else {
            acl.assertPermissionForProject("Project Role - Request",
                                           project.getID());

            return requestRoleWithoutApproval(role, project);
        }
    }

    /*
     * Handles some higher-level permissions checking than the ACL can do.
     */
    public boolean canRevokeRole(User user, Project project)
        throws DataSetException, SQLException, JoistDatabaseException
    {

        String perm = "";
        boolean canRevoke = false;
        AccessControlList acl = getACL();
        if (project.isHost()) 
        {
            if (acl.hasPermissionForHost("Host Role - Grant")) 
                canRevoke = true;
        } else if (project.isDomain()) {
            if (acl.hasPermissionForDomain("Domain Role - Grant",
                                           project.getDomainID())) 
                canRevoke = true;
        } else {
            ArrayList acceptablePerms = new ArrayList();
            acceptablePerms.add("Project Role - Grant");
            if (user.getID().equals(getID()))
            {
                acceptablePerms.add("Project Role - Revoke - Self");
            }
            for (Iterator i = acceptablePerms.iterator(); i.hasNext();)
            {
                perm = (String)i.next();
                if (acl.hasPermissionForProject(perm, project.getID()))
                    canRevoke = true;
            }
        }
        return canRevoke;
    }


    public String issueTrackingAccountType(Project project)
        throws SQLException, DataSetException, JoistDatabaseException
    {
	AccessControlList acl = getACL();
	String type="";
	String pID = project.getID();
	String pName = project.getName();
	String lID = getLoginID();
	
	if (acl.hasPermissionForProject
	    ("Project Issue Tracking - Configure", pID))
        {
            type = "admin";
            if (debug) 
            {
                //log.info(lID + " is an administrator of " + pName);
            }
        } else if (acl.hasPermissionForProject
                   ("Project Issue Tracking - Change", pID)) {
            if (debug) 
            {
                //log.info(lID + " is a developer on " + pName); 
            }
            type = "developer";
        } else if (acl.hasPermissionForProject
                   ("Project Issue Tracking - Submit", pID)) {
            if (debug) 
            {
                //log.info (lID + " is an observer on " + pName); 
            }
            type = "observer";
        } else {
            if (debug) 
            {
                //log.info(lID + " has no issue tracking role in " + pName);
            }
        }
	return type;
    }
    
    /**
     * This is needed during ProjectMembershipRequest, which uses
     * Invitation -- a user with an invitation needs to be able to
     * request a role even if they don't have Project Role - Request.
     *
     * @@param role The role requested
     * @@param project The project in which the role is being requested
     * @@return whether or not the request was successful.
     */
    public boolean requestRoleWithoutApproval(Role role, Project project)
        throws JoistException, JoistDatabaseException, DataSetException,
               SQLException, DoesNotExist
    {
        boolean ret = urpMgr.request(conn, getID(), role.getID(), 
                                         project.getID());
        
        String subject = "New role requested.";
        BuildContext ctx = TemplateInterpolator.createContext();
        ctx.put("user", this);
        ctx.put("role", role);
        ctx.put("project", project);
        String body = TemplateInterpolator.interpolate(ROLE_REQ_TMPL, ctx,
                                                       getClass());
        Role ownerRole = new Role(conn, dMgr, "Project Owner", false);
        HelmEmailer emailer = new HelmEmailer(conn, dMgr);
        emailer.messageUsersWithProjectRole
            (ownerRole, project, subject, body.toString());

        return ret;
    }
    
    public void revokeRole(AccessControlList acl, Role role)
        throws SQLException, DataSetException, JoistDatabaseException,
               ACLException, DoesNotExist
    {
        revokeRole(acl, role, new Host(conn, dMgr).getSpecialProject());
    }

    public void revokeRole(AccessControlList acl, Role role, Domain domain)
        throws SQLException, DataSetException, JoistDatabaseException,
               ACLException, DoesNotExist
    {
        revokeRole(acl, role, domain.getSpecialProject());
    }

    public void revokeRole(AccessControlList acl, Role role, Project project)
        throws SQLException, DataSetException, JoistDatabaseException,
               ACLException, DoesNotExist
    {
        User revokingUser = new User(conn, dMgr, acl.getUserID());
        if (revokingUser.canRevokeRole(this, project))
        {
            urpMgr.revoke(conn, revokingUser.getID(), getID(), role.getID(), 
                          project.getID());            
        }
        // This is kind of ugly.  But project owners should have their
        // names in a special alias -- owner@@{project}.{domain}
        if (role.getName().equals("Project Owner")) {
            AnzuTigrisTask.setOwnerAlias(conn, dMgr, revokingUser.getID(),
                    project.getID(), true);
        }
    }


    ////////////////////////////////////////////////////////////////////
    // Read-only methods.
    ////////////////////////////////////////////////////////////////////

    public int compareTo(Object o)
        throws ClassCastException
    {
        User u = (User)o;
        int val = -1;
        try 
        {
            val = getName().compareTo(u.getName());
        } catch (DataSetException ignore) {}
        return val;
    }

    public boolean equals(User u)
    {
        boolean val = false;
        try 
        {
            if (getID().equals(u.getID()))
            {
                val = true;
            }
        } catch (DataSetException ignore) {}        
        return val;       
    }

    public void rebuildACL()
        throws DataSetException, SQLException, JoistDatabaseException,
               DoesNotExist
    {
        for (Iterator i = expand().iterator(); i.hasNext();)
        {
            User u = (User)i.next();
            AccessControlList.rebuildACL(conn, dMgr, u.getID());
        }
    }

    /**
     * Returns a list of Users represending all the users
     * this user represents. If called on a base user, 
     * returns a list containing only itself.
     */    
    public List expand() 
        throws DataSetException, SQLException, JoistDatabaseException,
               DoesNotExist
    {
        List users = null;
	if (isBase())
	{
	    users = new ArrayList();
	    users.add(this);
	} else {
	    users = asGroup().expand();
	}
        return users;
    }

    public UserGroup asGroup()
    throws DataSetException
    {
        UserGroup g = null;
        if (isGroup())           
        {
            try {
                g = new UserGroup(conn, dMgr, this.rec);
            } catch (DoesNotExist ignore) {}
        }
        return g;
    }

    /**
     * The grant permission implies revoke as well. 
     */
    public void assertRoleGrantPermission (Project project)
        throws SQLException, DataSetException, JoistDatabaseException,
               ACLException
    {
        getACL().assertPermissionForProject
            (project.requiredRoleGrantAction(), project.getID());
    }
                                      
    public boolean hasRoleGrantPermission (Project project)
        throws SQLException, DataSetException, JoistDatabaseException,
               ACLException
    {
        return getACL().hasPermissionForProject
            (project.requiredRoleGrantAction(), project.getID());
    }

    public List getRequestedRolesInProject (String projectID)
        throws DataSetException, SQLException, JoistDatabaseException,
               DoesNotExist
    {
        ArrayList roles = new ArrayList ();
        DataSet roleset = urpMgr.getRequestedRolesForUserProject (conn,
                                                                  getUserID (),
                                                                  projectID);
        for (int i = 0; i < roleset.size (); i++)
        {
            Record r = rMgr.getRole(conn, 
                                    roleset.getRecord(i)
                                    .getValue(UserRoleProjectManager.ROLE_ID)
                                    .toString());
            roles.add(new Role(conn, dMgr, r));
        }
        return roles;
    }

    public List getRolesInProject (String projectID)
        throws DataSetException, SQLException, JoistDatabaseException,
               DoesNotExist
    {
        
        ArrayList roles = new ArrayList ();
        DataSet roleset = urpMgr.getRolesForUserProject (conn,
                                                         getUserID (),
                                                         projectID);
        for (int i = 0; i < roleset.size (); i++)
        {
            Record r = rMgr.getRole(conn, 
                                    roleset.getRecord(i)
                                    .getValue(UserRoleProjectManager.ROLE_ID)
                                    .toString ());
            roles.add(new Role(conn, dMgr, r));
        }
        return roles;
    }

    public List getAvaliableRolesInProject (String projectID)
        throws DataSetException, SQLException, JoistDatabaseException,
               DoesNotExist
    {
        String rID = UserRoleProjectManager.ROLE_ID;
        DataSet allRoles = rMgr.listRolesByType(conn, "project");
        ArrayList avaliableRoles = new ArrayList();

        Map approved = new HashMap();
        DataSet approvedRoles = urpMgr.getRolesForUserProject 
            (conn, getUserID(), projectID);
        for (int i = 0; i < approvedRoles.size(); i++)
        {
            approved.put(approvedRoles.getRecord(i).getValue(rID).toString(),
                         Boolean.TRUE);
        }

        Map requested = new HashMap();
        DataSet requestedRoles = urpMgr.getRequestedRolesForUserProject 
            (conn, getUserID(), projectID);
        for (int i = 0; i < requestedRoles.size(); i++)
        {
            requested.put(requestedRoles.getRecord(i).getValue(rID).toString(),
                          Boolean.TRUE);
        }
        
        for (int i = 0; i < allRoles.size(); i++)
        {
            String roleID = allRoles.getRecord(i).getValue
                (RoleManager.ROLE_ID).toString();
            Role role = new Role(conn, dMgr, roleID);
            if (!requested.containsKey(roleID)
                && !approved.containsKey(roleID) 
                && role.isRequestable())
            {
                avaliableRoles.add(role);
            }
        }
        return avaliableRoles;
    }

    public List getProjectsForUserGroups()
        throws DataSetException, SQLException, JoistDatabaseException,
               DoesNotExist
    {        
        // Get groups the user is a member of 
        DataSet userGroups = usrGrpMgr.getCompositesForBase(conn, getUserID());

        // Create list of userID's including IDs of groups
        ArrayList effectiveUserIDs = new ArrayList();
        effectiveUserIDs.add(getUserID());        
        if (userGroups != null)
        {
	    for (int i = 0; i < userGroups.size(); i++)
	    {
                effectiveUserIDs.add(userGroups.getRecord(i).getValue(usrGrpMgr.USER_GROUP_ID));
            }
	}

        // Get dataset of projects for these users
        DataSet projects = urpMgr.getProjectsForUsers
                                 (conn, effectiveUserIDs);

        ArrayList projectsForUser = new ArrayList();
	String projectID;

        for (int i = 0; i < projects.size(); i++)
        {
            projectID = projects.getRecord(i).getValue(UserRoleProjectManager.PROJECT_ID).toString();
            projectsForUser.add(new Project (conn, dMgr, projectID));
        }

	return projectsForUser;
    }


    public List getProjectsForUser ()
        throws DataSetException, SQLException, JoistDatabaseException,
               DoesNotExist
    {        
        ArrayList projects = new ArrayList ();
        DataSet projectset = urpMgr.getProjectsForUser (conn, getUserID ());
        
        for (int i = 0; i < projectset.size (); i++)
        {
            Record r = projectset.getRecord (i);
            projects.add(new Project (conn, dMgr, r));
        }
        return projects;
    }

    ////////////////////////////////////////////////////////////////////
    // Field accessor methods.
    ////////////////////////////////////////////////////////////////////

    public AccessControlList getACL ()
        throws SQLException, DataSetException, JoistDatabaseException
    {
        return AccessControlList.getACL(conn, dMgr, getID());
    }

    /**
     * Returns the user's database key.
     */
    public String getID () throws DataSetException
    {
        return rec.getValue(UserManager.USER_ID).asString();
    }

    /**
     * @@deprecated Use getID() instead.
     */
    public String getUserID () throws DataSetException
    {
        return getID();
    }

    /**
     * Returns the user's domain.
     */
    public Domain getDomain() 
        throws DataSetException, JoistDatabaseException, DoesNotExist
    {
        return new Domain(conn, dMgr, getDomainID());
    }

    /**
     * Returns the database key of user's domain.
     */
    public String getDomainID () throws DataSetException
    {
        return rec.getValue("domainID").asString();
    }

    /**
     * Returns the user's login name.
     */
    public String getLoginID () throws DataSetException
    {
        return rec.getValue(UserManager.LOGIN_ID).asString();
    }

    /**
     * Returns the user's real name.
     */
    public String getName () throws DataSetException
    {
        return rec.getValue(UserManager.NAME).asString();
    }

    public String getType () throws DataSetException
    {
        return rec.getValue(UserManager.TYPE).asString();
    }

    public boolean isGroup() throws DataSetException
    {
	return !isBase();
    }

    public boolean isDomain() throws DataSetException
    {
        return getType().equals(UserType.DOMAIN);
    }

    public boolean isHost() throws DataSetException
    {
        return getType().equals(UserType.HOST);
    }

    public boolean isBase() throws DataSetException
    {
        return getType().equals(UserType.REGULAR) || getType().equals(UserType.NOBODY);
    }

    public String getAddress1 () throws DataSetException
    {
        return rec.getValue("address1").asString();
    }

    public String getAddress2 () throws DataSetException
    {
        return rec.getValue("address2").asString();
    }

    public String getCity () throws DataSetException
    {
        return rec.getValue("city").asString();
    }

    public String getState () throws DataSetException
    {
        return rec.getValue("state").asString();
    }

    public String getPostalCode () throws DataSetException
    {
        return rec.getValue ("postalCode").asString();
    }

    public String getCountry () throws DataSetException
    {
        return rec.getValue("country").asString();
    }

    public String getCitizenship () throws DataSetException
    {
        return rec.getValue("citizenship").asString();
    }

    public String getPhone () throws DataSetException    {
        return rec.getValue("phone").asString();
    }

    public String getAltPhone () throws DataSetException
    {
        return rec.getValue("altPhone").asString();
    }

    public String getFax () throws DataSetException
    {
        return rec.getValue("fax").asString();
    }

    public String getCell () throws DataSetException
    {
        return rec.getValue("cell").asString();
    }

    public String getPager () throws DataSetException
    {
        return rec.getValue("pager").asString();
    }

    public String getEmail () throws DataSetException
    {
        return rec.getValue(UserManager.EMAIL).asString();
    }

    public String getOrganization () throws DataSetException
    {
        String org = rec.getValue(UserManager.ORGANIZATION).asString();
        if (org == null) org = "";
        return org;
    }

    public String getDomainEmail () 
        throws DataSetException, JoistDatabaseException, DoesNotExist
    {
        String domName = getDomain().getName();
        return getLoginID() + "@@" + domName;
    }

}
@


1.92
log
@readding all the files as part of the process of returning to the way
things were as of tuesday
@
text
@d88 1
a88 1
 * @@version $Id: User.java,v 1.86 2001/01/19 04:44:20 jrobbins Exp $
@


1.92.2.1
log
@Porting to the Turbine Peer system.  -dlr and leonardr
@
text
@d88 1
a88 1
 * @@version $Id: User.java,v 1.92 2001/01/26 18:29:02 edk Exp $
@


1.91
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
@d65 1
a65 4
import org.joist.database.DataManager;
import org.joist.database.JoistDatabaseException;
import org.joist.database.UserType;

d88 1
a88 1
 * @@version $Id: User.java,v 1.90 2001/01/25 01:35:10 lucas Exp $
d224 3
a226 3
    public static boolean exists (DataManager dMgr, String domainID,
                                  String loginID)
        throws DBException, DoesNotExist
d228 9
a236 2
        new User(dMgr, domainID, loginID);
        return true;
d247 1
a247 1
     * with the signature <code>User(DataManager, String)</code>.
d249 4
a252 2
    public static User getInstance (DataManager dMgr, String id)
        throws DoesNotExist, DBException
d263 1
a263 1
                    user = new User(dMgr, id);
d285 1
a285 1
    public User (DataManager dMgr)
d287 1
a287 1
        super(dMgr);
d294 2
a295 2
    public User (DataManager dMgr, Record rec)
        throws DoesNotExist, DBexception
d297 1
a297 1
        super(dMgr, rec);
d304 3
a306 2
    protected User (DataManager dMgr, String userID)
        throws DoesNotExist, DBException
d308 2
a309 1
        super(dMgr, uMgr.getUser(userID));
d318 4
a321 2
    public User (DataManager dMgr, String domainID, String loginID)
        throws DoesNotExist, DBException
d323 2
a324 1
        super(dMgr, uMgr.getUserForLoginID(domainID, loginID));
d328 1
a328 1
     * Constructor for a user who already exists -- accessed by
d331 3
a333 3
    public User (DataManager dMgr, String domainID, String email,
                 boolean ignore)
        throws DoesNotExist, DBException
d335 2
a336 1
        super(dMgr, uMgr.getUserForEmail(domainID, email));
d340 3
a342 1
     * Constructor for a user who already exists.
d347 4
a350 3
    public User (DataManager dMgr, String realName, 
                 String domainID, String ignore)
        throws DoesNotExist, DBException
d352 2
a353 1
        super(dMgr, uMgr.getUserForName(domainID, realName));
d360 1
a360 1
    public User (AccessControlList acl, DataManager dMgr, 
d363 3
a365 2
        throws ACLException, UpdateException, AlreadyExists, DoesNotExist,
               DBException
d367 2
a368 2
        this(acl, dMgr, context, domainID, realName, loginID, password, email,
             null);
d375 1
a375 1
    public User (AccessControlList acl, DataManager dMgr, 
d379 3
a381 2
        throws ACLException, UpdateException, AlreadyExists, DoesNotExist,
               DBException
d383 1
a383 1
        super(dMgr);
d395 2
a396 1
            throw new AlreadyExists("user " + userName + " already exists");
d403 1
a403 1
        Record user = uMgr.addUser(domainID, realName, 
d406 1
a406 1
        getCache().put(user.getValue(USER_ID).asString(), this);
d409 1
a409 1
            setRecord(user);
d412 1
a412 1
            UserGroup.addUserToDomainUserGroup(dMgr, domainID, this);
d423 4
d440 1
a440 1
            ("org.tigris.helm.database.UserManager");        
d450 1
a450 1
            ("org.tigris.helm.database.RoleManager");
d470 1
a470 1
        throws DBException
d481 1
a481 1
        throws DBException
d492 1
a492 1
        throws DBException
d503 1
a503 1
        throws DBException
a507 3
    /**
     * TODO: Move implementation to Helm's new UserManager.
     */
d509 1
a509 1
        throws DBException
d532 2
a533 1
        throws ACLException, DoesNotExist, DBException
d537 1
a537 1
        User deletingUser = new User(dMgr, acl.getUserID());
d553 4
a556 2
        AccessControlList userACL = new AccessControlList(dMgr, getID());
        DataSet projects = pMgr.getProjectsForDomain(getDomainID());
d559 1
a559 1
        urpMgr.deleteRolesForUser(getID());
d564 1
a564 1
        TigrisUpdate.deleteUser(dMgr, deletingUser, getDomain(), this);
d567 1
a567 1
        uMgr.deleteUser(getID());
d586 2
a587 1
        throws ACLException, DoesNotExist, DBException
d598 1
a598 1
        throws DBException
d601 1
a601 1
        DataSet groupSet = usrGrpMgr.getCompositesForBase(getID());
d606 4
a609 4
                Record r = groupSet.getRecord(i);
                String id =
                    r.getValue(UserUserGroupManager.USER_GROUP_ID).asString();
                groups.add(new UserGroup(dMgr, id));
d612 3
a614 2
                throw new DBException(e);
            }
d625 1
a625 1
        throws DBException
d644 2
a645 1
        throws ACLException, DBException
d652 1
a652 1
                Domain domain = new Domain(dMgr, getDomainID());
d675 2
a676 2
            uMgr.updateUser(getID(), getDomainID(), loginID, email,
                            realName, organization, passwd, null);
d691 2
a692 1
        throws ACLException, JoistException, DBException
d696 1
a696 1
        uMgr.updateUser(getID(), null, null, null, null, passwd, null);
d700 1
a700 1
        throws ACLException, DBException
d712 1
a712 1
        throws ACLException, DBException
d744 2
a745 1
        throws ACLException, DoesNotExist, DBException
d748 1
a748 1
        Role hostRole = new Role(dMgr, "Host Admin", false);
d754 1
a754 1
        urpMgr.grant(getID(), hostRole.getID(), pMgr.getHostProjectID(),
d762 2
a763 1
        throws ACLException, DoesNotExist, DBException
d766 1
a766 1
        Role hostRole = new Role(dMgr, "Host Admin", false);
d772 1
a772 1
        urpMgr.revoke(null, getID(), hostRole.getID(),
d780 2
a781 1
        throws ACLException, DoesNotExist, DBException
d784 1
a784 1
        Role domainRole = new Role(dMgr, "Domain Admin", false);
d791 2
a792 1
        urpMgr.grant(getID(), domainRole.getID(), projectID, acl.getUserID());
d799 2
a800 1
        throws ACLException, DoesNotExist, DBException
d803 1
a803 1
        Role domainRole = new Role(dMgr, "Domain Admin", false);
d810 1
a810 1
        urpMgr.revoke(null, getID(), domainRole.getID(), projectID);
d817 2
a818 1
        throws DoesNotExist, DBException
d821 1
a821 1
        String rootID = uMgr.getUserForLoginID("root")
d823 2
a824 2
        urpMgr.grantNamedRole(getID(), "Click-through Viewer", projectID,
                              rootID);
d828 2
a829 1
        throws ACLException, DoesNotExist, DBException
d831 1
a831 1
        grantRole(acl, role, new Host(dMgr).getSpecialProject());
d835 2
a836 1
        throws ACLException, DoesNotExist, DBException
d842 2
a843 1
        throws ACLException, DoesNotExist, DBException
d845 1
a845 1
        User grantingUser = new User(dMgr, acl.getUserID());
d851 1
a851 1
        urpMgr.grant(getID(), role.getID(), project.getID(), 
d856 1
a856 1
            AnzuTigrisTask.setOwnerAlias(dMgr, grantingUser.getID(),
d863 2
a864 1
        throws ACLException, DoesNotExist, JoistException, DBException
d873 1
a873 1
            urpMgr.grant(getID(), role.getID(), project.getID(), 
d878 2
a879 2
                AnzuTigrisTask.setOwnerAlias(dMgr, null, project.getID(),
                                             true);
d894 1
a894 1
        throws DBException
d927 1
a927 1
        throws DBException
d976 2
a977 1
        throws  DBException, JoistException, DoesNotExist, DBException
d979 2
a980 1
        boolean ret = urpMgr.request(getID(), role.getID(), project.getID());
d989 2
a990 2
        Role ownerRole = new Role(dMgr, "Project Owner", false);
        HelmEmailer emailer = new HelmEmailer(dMgr);
d998 2
a999 1
        throws ACLException, DoesNotExist, DBException
d1001 1
a1001 1
        revokeRole(acl, role, new Host(dMgr).getSpecialProject());
d1005 2
a1006 1
        throws ACLException, DoesNotExist, DBException
d1012 2
a1013 1
        throws ACLException, DoesNotExist, DBException
d1015 1
a1015 1
        User revokingUser = new User(dMgr, acl.getUserID());
d1018 1
a1018 1
            urpMgr.revoke(revokingUser.getID(), getID(), role.getID(), 
d1024 1
a1024 1
            AnzuTigrisTask.setOwnerAlias(dMgr, revokingUser.getID(),
d1060 2
a1061 1
        throws DoesNotExist, DBException
d1066 1
a1066 1
            AccessControlList.rebuildACL(dMgr, u.getID());
d1076 2
a1077 1
        throws DoesNotExist, DBException
d1091 1
a1091 1
        throws DBException
d1097 1
a1097 1
                g = new UserGroup(dMgr, this.rec);
d1107 2
a1108 1
        throws ACLException, DBException
d1115 2
a1116 1
        throws ACLException, DBException
d1123 2
a1124 1
        throws DoesNotExist, DBException
d1127 3
a1129 2
        DataSet roleset = urpMgr.getRequestedRolesForUserProject(getUserID(),
                                                                 projectID);
d1132 2
a1133 1
            Record r = rMgr.getRole(roleset.getRecord(i)
d1136 1
a1136 1
            roles.add(new Role(dMgr, r));
d1142 2
a1143 1
        throws DoesNotExist, DBException
d1147 3
a1149 1
        DataSet roleset = urpMgr.getRolesForUserProject(getID(), projectID);
d1152 2
a1153 1
            Record r = rMgr.getRole(roleset.getRecord(i)
d1156 1
a1156 1
            roles.add(new Role(dMgr, r));
d1162 2
a1163 1
        throws DoesNotExist, DBException
d1166 1
a1166 1
        DataSet allRoles = rMgr.listRolesByType("project");
d1170 2
a1171 2
        DataSet approvedRoles = urpMgr.getRolesForUserProject(getUserID(),
                                                              projectID);
d1180 1
a1180 1
            (getUserID(), projectID);
d1191 1
a1191 1
            Role role = new Role(dMgr, roleID);
d1203 2
a1204 1
        throws DoesNotExist, DBException
d1207 1
a1207 1
        DataSet userGroups = usrGrpMgr.getCompositesForBase(getUserID());
d1216 1
a1216 2
                effectiveUserIDs.add(userGroups.getRecord(i)
                                     .getValue(usrGrpMgr.USER_GROUP_ID));
d1221 2
a1222 1
        DataSet projects = urpMgr.getProjectsForUsers(effectiveUserIDs);
d1229 2
a1230 3
            projectID = projects.getRecord(i)
                .getValue(UserRoleProjectManager.PROJECT_ID).toString();
            projectsForUser.add(new Project(dMgr, projectID));
d1238 2
a1239 1
        throws DoesNotExist, DBException
d1242 1
a1242 1
        DataSet projectset = urpMgr.getProjectsForUser(getUserID());
d1247 1
a1247 1
            projects.add(new Project(dMgr, r));
d1257 1
a1257 1
        throws DBException
d1259 1
a1259 1
        return AccessControlList.getACL(dMgr, getID());
d1265 1
a1265 1
    public String getID () throws DBException
d1273 1
a1273 1
    public String getUserID () throws DBException
d1282 1
a1282 1
        throws DBException, DoesNotExist
d1284 1
a1284 1
        return new Domain(dMgr, getDomainID());
d1290 1
a1290 1
    public String getDomainID () throws DBException
d1298 1
a1298 1
    public String getLoginID () throws DBException
d1306 1
a1306 1
    public String getName () throws DBException
d1311 1
a1311 1
    public String getType () throws DBException
d1316 1
a1316 1
    public boolean isGroup() throws DBException
d1321 1
a1321 1
    public boolean isDomain() throws DBException
d1326 1
a1326 1
    public boolean isHost() throws DBException
d1331 1
a1331 1
    public boolean isBase() throws DBException
d1336 1
a1336 1
    public String getAddress1 () throws DBException
d1341 1
a1341 1
    public String getAddress2 () throws DBException
d1346 1
a1346 1
    public String getCity () throws DBException
d1351 1
a1351 1
    public String getState () throws DBException
d1356 1
a1356 1
    public String getPostalCode () throws DBException
d1361 1
a1361 1
    public String getCountry () throws DBException
d1366 1
a1366 1
    public String getCitizenship () throws DBException
d1371 1
a1371 1
    public String getPhone () throws DBException    {
d1375 1
a1375 1
    public String getAltPhone () throws DBException
d1380 1
a1380 1
    public String getFax () throws DBException
d1385 1
a1385 1
    public String getCell () throws DBException
d1390 1
a1390 1
    public String getPager () throws DBException
d1395 1
a1395 1
    public String getEmail () throws DBException
d1400 1
a1400 1
    public String getOrganization () throws DBException
d1408 1
a1408 1
        throws DoesNotExist, DBException
d1413 1
@


1.90
log
@fixed syntax error
@
text
@d91 1
a91 1
 * @@version $Id: User.java,v 1.89 2001/01/25 00:21:56 leonardr Exp $
@


1.89
log
@* Removed all references to JDBC connections.  Connections are now pulled
  directly from the connection pool.
* Made use of DBException.
- dlr@@collab.net
@
text
@d91 1
a91 1
 * @@version $Id: User.java,v 1.88 2001/01/24 21:41:49 leonardr Exp $
d827 1
a827 1
        throws ACLException, DoesNotExist, JoistException, DBException,
@


1.88
log
@Ported UserManager and RoleManager to Helm. Started moving other TableManagers toward a grab-connection-on-demand model. Massive breakage ensues. dlr and I are working on it.
@
text
@d91 1
a91 1
 * @@version $Id: User.java,v 1.87 2001/01/24 20:42:48 dlr Exp $
d227 2
a228 2
    public static boolean exists (Connection c, DataManager dMgr,
                                  String domainID, String loginID)
d231 1
a231 1
        new User(c, dMgr, domainID, loginID);
d243 1
a243 1
     * with the signature <code>User(Connection, DataManager, String)</code>.
d245 1
a245 2
    public static User getInstance (Connection conn, DataManager dMgr,
                                    String id)
d257 1
a257 1
                    user = new User(conn, dMgr, id);
d279 1
a279 1
    public User (Connection c, DataManager dMgr)
d281 1
a281 1
        super(c, dMgr);
d288 1
a288 1
    public User (Connection c, DataManager dMgr, Record rec)
d291 1
a291 1
        super(c, dMgr, rec);
d298 1
a298 1
    protected User (Connection c, DataManager dMgr, String userID)
d301 1
a301 2
        super(c, dMgr);
        setRecord(uMgr.getUser(userID));
d310 1
a310 2
    public User (Connection c, DataManager dMgr, String domainID,
                 String loginID)
d313 1
a313 2
        super(c, dMgr);
        setRecord(uMgr.getUserForLoginID(domainID, loginID));
d320 1
a320 1
    public User (Connection c, DataManager dMgr, String domainID, String email,
d324 1
a324 2
        super(c, dMgr);
        setRecord(uMgr.getUserForEmail(domainID, email));
d333 1
a333 1
    public User (Connection c, DataManager dMgr, String realName, 
d337 1
a337 2
        super(c, dMgr);
        setRecord(uMgr.getUserForName(domainID, realName));
d344 1
a344 1
    public User (AccessControlList acl, Connection c, DataManager dMgr, 
d350 2
a351 2
        this(acl, c, dMgr, context, domainID, realName,
             loginID, password, email, null);
d358 1
a358 1
    public User (AccessControlList acl, Connection c, DataManager dMgr, 
d365 1
a365 1
        super(c, dMgr);
d377 1
a377 2
            throw new AlreadyExists
                ("user " + userName + " already exists");
d393 1
a393 1
            UserGroup.addUserToDomainUserGroup(conn, dMgr, domainID, this);
d458 1
a458 1
        throws DBException, SQLException
d469 1
a469 1
        throws DBException, SQLException
d480 1
a480 1
        throws DBException, SQLException
d485 3
d489 1
a489 1
        throws DBException, SQLException
d516 1
a516 1
        User deletingUser = new User(conn, dMgr, acl.getUserID());
d532 2
a533 4
        AccessControlList userACL = new AccessControlList(conn, dMgr, 
                                                          getID());
        DataSet projects = pMgr.getProjectsForDomain(conn, 
                                                     getDomainID());
d536 1
a536 1
        urpMgr.deleteRolesForUser(conn, getID());
d541 1
a541 1
        TigrisUpdate.deleteUser(conn, dMgr, deletingUser, getDomain(), this);
d563 1
a563 2
        throws DBException, 
               ACLException, DoesNotExist
d574 1
a574 1
        throws DBException, SQLException
d577 1
a577 1
        DataSet groupSet = usrGrpMgr.getCompositesForBase(conn, getID());
d582 4
a585 4
		        Record r = groupSet.getRecord(i);
		        String id 
                    = r.getValue(UserUserGroupManager.USER_GROUP_ID).asString();
                groups.add(new UserGroup(conn, dMgr, id));
d588 2
a589 3
		        throw new DataSetException("Got JoistDatabaseException: " 
                    + e.getMessage());
	        }
d600 1
a600 1
        throws DBException, SQLException
d619 1
a619 2
        throws DBException, 
               ACLException
d626 1
a626 1
                Domain domain = new Domain(conn, dMgr, getDomainID());
d665 1
a665 2
        throws DBException, 
               JoistException, ACLException
d673 1
a673 1
        throws ACLException, DataSetException
d685 1
a685 1
        throws ACLException, DataSetException
d720 1
a720 1
        Role hostRole = new Role(conn, dMgr, "Host Admin", false);
d726 1
a726 1
        urpMgr.grant(conn, getID(), hostRole.getID(), pMgr.getHostProjectID(),
d737 1
a737 1
        Role hostRole = new Role(conn, dMgr, "Host Admin", false);
d743 1
a743 1
        urpMgr.revoke(conn, null, getID(), hostRole.getID(),
d754 1
a754 1
        Role domainRole = new Role(conn, dMgr, "Domain Admin", false);
d761 1
a761 2
        urpMgr.grant(conn, getID(), domainRole.getID(), projectID, 
                     acl.getUserID());
d771 1
a771 1
        Role domainRole = new Role(conn, dMgr, "Domain Admin", false);
d778 1
a778 1
        urpMgr.revoke(conn, null, getID(), domainRole.getID(), projectID);
d790 2
a791 2
        urpMgr.grantNamedRole(conn, getID(), "Click-through Viewer", 
                              projectID, rootID);
d797 1
a797 1
        grantRole(acl, role, new Host(conn, dMgr).getSpecialProject());
d809 1
a809 1
        User grantingUser = new User(conn, dMgr, acl.getUserID());
d815 1
a815 1
        urpMgr.grant(conn, getID(), role.getID(), project.getID(), 
d820 1
a820 1
            AnzuTigrisTask.setOwnerAlias(conn, dMgr, grantingUser.getID(),
d827 1
a827 1
        throws DoesNotExist, JoistException, ACLException, DBException,
d836 1
a836 1
            urpMgr.grant(conn, getID(), role.getID(), project.getID(), 
d841 2
a842 2
                AnzuTigrisTask.setOwnerAlias(conn, dMgr, null,
                        project.getID(), true);
d939 1
a939 2
        throws  DBException, JoistException, JoistDatabaseException, DataSetException,
               SQLException, DoesNotExist
d941 1
a941 2
        boolean ret = urpMgr.request(conn, getID(), role.getID(), 
                                         project.getID());
d950 2
a951 2
        Role ownerRole = new Role(conn, dMgr, "Project Owner", false);
        HelmEmailer emailer = new HelmEmailer(conn, dMgr);
d961 1
a961 1
        revokeRole(acl, role, new Host(conn, dMgr).getSpecialProject());
d965 1
a965 2
        throws DBException,
               ACLException, DoesNotExist
d973 1
a973 1
        User revokingUser = new User(conn, dMgr, acl.getUserID());
d976 1
a976 1
            urpMgr.revoke(conn, revokingUser.getID(), getID(), role.getID(), 
d982 1
a982 1
            AnzuTigrisTask.setOwnerAlias(conn, dMgr, revokingUser.getID(),
d1018 1
a1018 2
        throws DBException,
               DoesNotExist
d1023 1
a1023 1
            AccessControlList.rebuildACL(conn, dMgr, u.getID());
d1047 1
a1047 1
    throws DBException
d1053 1
a1053 1
                g = new UserGroup(conn, dMgr, this.rec);
d1063 1
a1063 2
        throws DBException,
               ACLException
d1070 1
a1070 2
        throws DBException,
               ACLException
d1080 2
a1081 3
        DataSet roleset = urpMgr.getRequestedRolesForUserProject (conn,
                                                                  getUserID (),
                                                                  projectID);
d1084 1
a1084 2
            Record r = rMgr.getRole(conn, 
                                    roleset.getRecord(i)
d1087 1
a1087 1
            roles.add(new Role(conn, dMgr, r));
d1097 1
a1097 3
        DataSet roleset = urpMgr.getRolesForUserProject (conn,
                                                         getUserID (),
                                                         projectID);
d1100 1
a1100 2
            Record r = rMgr.getRole(conn, 
                                    roleset.getRecord(i)
d1103 1
a1103 1
            roles.add(new Role(conn, dMgr, r));
d1112 1
a1112 1
        DataSet allRoles = rMgr.listRolesByType(conn, "project");
d1116 2
a1117 2
        DataSet approvedRoles = urpMgr.getRolesForUserProject 
            (conn, getUserID(), projectID);
d1126 1
a1126 1
            (conn, getUserID(), projectID);
d1137 1
a1137 1
            Role role = new Role(conn, dMgr, roleID);
d1149 1
a1149 2
        throws DBException,
               DoesNotExist
d1152 1
a1152 1
        DataSet userGroups = usrGrpMgr.getCompositesForBase(conn, getUserID());
d1167 1
a1167 2
        DataSet projects = urpMgr.getProjectsForUsers
                                 (conn, effectiveUserIDs);
d1174 3
a1176 2
            projectID = projects.getRecord(i).getValue(UserRoleProjectManager.PROJECT_ID).toString();
            projectsForUser.add(new Project (conn, dMgr, projectID));
d1187 1
a1187 1
        DataSet projectset = urpMgr.getProjectsForUser (conn, getUserID ());
d1192 1
a1192 1
            projects.add(new Project (conn, dMgr, r));
d1204 1
a1204 1
        return AccessControlList.getACL(conn, dMgr, getID());
d1227 1
a1227 1
        throws DBException, JoistDatabaseException, DoesNotExist
d1229 1
a1229 1
        return new Domain(conn, dMgr, getDomainID());
d1353 1
a1353 1
        throws DBException, JoistDatabaseException, DoesNotExist
a1357 1

@


1.87
log
@Making use of DBException.
@
text
@d65 4
a68 1
import org.joist.database.*;
d91 1
a91 1
 * @@version $Id: User.java,v 1.86 2001/01/19 04:44:20 jrobbins Exp $
d229 1
a229 1
        throws JoistDatabaseException, DataSetException, SQLException
d231 2
a232 9
        try
        {
            new User(c, dMgr, domainID, loginID);
            return true;
        }
        catch (DoesNotExist e)
        {
            return false;
        }
d247 1
a247 2
        throws DBException,
               DoesNotExist
d290 1
a290 1
        throws DoesNotExist, DataSetException
d300 1
a300 2
        throws DBException,
               DoesNotExist
d303 1
a303 1
        setRecord(uMgr.getUser(c, userID));
d314 1
a314 2
        throws DBException,
               DoesNotExist
d317 1
a317 1
        setRecord(domMgr.getUserForLoginID(c, domainID, loginID));
d321 1
a321 1
     * Constructor for a user which already exists -- accessed by
d324 3
a326 3
    public User (Connection c, String email, DataManager dMgr, String domainID)
        throws DBException,
               DoesNotExist
d329 1
a329 1
        setRecord(domMgr.getUserForEmail(c, domainID, email));
d333 1
a333 3
     * <b>FIXME: Could get user from the wrong domain!</b>
     * <p>
     * Constructor for a user which already exists.
d338 3
a340 4
    public User (String realName, Connection c, DataManager dMgr,
                 String domainID)
        throws DBException,
               DoesNotExist
d343 1
a343 1
        setRecord(uMgr.getUserForName(c, realName));
d353 2
a354 3
        throws DBException,
               UpdateException, AlreadyExists, DoesNotExist,
               ACLException
d368 2
a369 3
        throws DBException,
               UpdateException, AlreadyExists, DoesNotExist,
               ACLException
d391 1
a391 1
        Integer userID = uMgr.addUser(conn, context, domainID, realName, 
d394 1
a394 1
        getCache().put(userID.toString(), this);
d397 1
a397 1
            setRecord(uMgr.getUser(conn, userID.toString()));
a410 4
            if (e instanceof InsertFailedException) {
                throw new org.tigris.helm.AlreadyExists
                    ("Unable to add db entry: User exists: " + userName);
            }
d424 1
a424 1
            ("org.joist.database.UserManager");        
d434 1
a434 1
            ("org.joist.database.RoleManager");
d516 1
a516 2
        throws DBException, 
               ACLException, DoesNotExist
d550 1
a550 1
        uMgr.deleteUser(conn, getID());
d658 2
a659 2
            uMgr.updateUser(conn, context, getID(), loginID, email,
                            realName, organization, passwd);
d679 1
a679 1
        uMgr.updateUser(conn, ctx, getID(), getLoginID(), null, null, passwd);
d727 1
a727 2
        throws DBException, 
               ACLException, DoesNotExist
d744 1
a744 2
        throws DBException,
               ACLException, DoesNotExist
d761 1
a761 2
        throws DBException,
               ACLException, DoesNotExist
d779 1
a779 2
        throws DBException,
               ACLException, DoesNotExist
d796 1
a796 2
        throws DBException,
               DoesNotExist
d799 1
a799 1
        String rootID = uMgr.getUserForLoginID(conn, "root")
d806 1
a806 2
        throws DBException,
               ACLException, DoesNotExist
d812 1
a812 2
        throws DBException,
               ACLException, DoesNotExist
d818 1
a818 2
        throws DBException,
               ACLException, DoesNotExist
d838 1
a838 2
        throws DBException,
               DoesNotExist, JoistException, ACLException
d950 1
a950 1
        throws JoistException, JoistDatabaseException, DataSetException,
d972 1
a972 2
        throws DBException,
               ACLException, DoesNotExist
d985 1
a985 2
        throws DBException,
               ACLException, DoesNotExist
d1094 1
a1094 2
        throws DBException,
               DoesNotExist
d1112 1
a1112 2
        throws DBException,
               DoesNotExist
d1131 1
a1131 2
        throws DBException,
               DoesNotExist
d1184 2
a1185 1
                effectiveUserIDs.add(userGroups.getRecord(i).getValue(usrGrpMgr.USER_GROUP_ID));
@


1.86
log
@Reverted to less optimal isGuest() determination because it actually works.  -dlr
@
text
@d88 1
a88 1
 * @@version $Id: User.java,v 1.85 2001/01/19 03:47:40 stack Exp $
d251 1
a251 1
        throws SQLException, DataSetException, JoistDatabaseException,
d305 1
a305 1
        throws SQLException, DataSetException, JoistDatabaseException,
d320 1
a320 1
        throws SQLException, DataSetException, JoistDatabaseException,
d332 1
a332 1
        throws SQLException, DataSetException, JoistDatabaseException,
d349 1
a349 1
        throws SQLException, DataSetException, JoistDatabaseException,
d363 1
a363 1
        throws SQLException, DataSetException, JoistDatabaseException,
d379 1
a379 1
        throws SQLException, DataSetException, JoistDatabaseException,
d470 1
a470 1
        throws DataSetException
d481 1
a481 1
        throws DataSetException, SQLException
d492 1
a492 1
        throws DataSetException, SQLException
d503 1
a503 1
        throws DataSetException, SQLException
d509 1
a509 1
        throws DataSetException, SQLException
d532 1
a532 1
        throws DataSetException, SQLException, JoistDatabaseException, 
d586 1
a586 1
        throws DataSetException, SQLException, JoistDatabaseException, 
d598 1
a598 1
        throws DataSetException, SQLException
d625 1
a625 1
        throws DataSetException, SQLException
d644 1
a644 1
        throws DataSetException, SQLException, JoistDatabaseException, 
d691 1
a691 1
        throws DataSetException, SQLException, JoistDatabaseException, 
d744 1
a744 1
        throws SQLException, DataSetException, JoistDatabaseException, 
d762 1
a762 1
        throws SQLException, DataSetException, JoistDatabaseException,
d780 1
a780 1
        throws SQLException, DataSetException, JoistDatabaseException,
d799 1
a799 1
        throws SQLException, DataSetException, JoistDatabaseException,
d817 1
a817 1
        throws SQLException, DataSetException, JoistDatabaseException,
d828 1
a828 1
        throws SQLException, DataSetException, JoistDatabaseException,
d835 1
a835 1
        throws SQLException, DataSetException, JoistDatabaseException,
d842 1
a842 1
        throws SQLException, DataSetException, JoistDatabaseException,
d863 1
a863 1
        throws SQLException, DataSetException, JoistDatabaseException,
d894 1
a894 1
        throws DataSetException, SQLException, JoistDatabaseException
d927 1
a927 1
        throws SQLException, DataSetException, JoistDatabaseException
d998 1
a998 1
        throws SQLException, DataSetException, JoistDatabaseException,
d1005 1
a1005 1
        throws SQLException, DataSetException, JoistDatabaseException,
d1012 1
a1012 1
        throws SQLException, DataSetException, JoistDatabaseException,
d1060 1
a1060 1
        throws DataSetException, SQLException, JoistDatabaseException,
d1076 1
a1076 2
        throws DataSetException, SQLException, JoistDatabaseException,
               DoesNotExist
d1090 1
a1090 1
    throws DataSetException
d1106 1
a1106 1
        throws SQLException, DataSetException, JoistDatabaseException,
d1114 1
a1114 1
        throws SQLException, DataSetException, JoistDatabaseException,
d1122 1
a1122 1
        throws DataSetException, SQLException, JoistDatabaseException,
d1141 1
a1141 1
        throws DataSetException, SQLException, JoistDatabaseException,
d1161 1
a1161 1
        throws DataSetException, SQLException, JoistDatabaseException,
d1202 1
a1202 1
        throws DataSetException, SQLException, JoistDatabaseException,
d1237 1
a1237 2
        throws DataSetException, SQLException, JoistDatabaseException,
               DoesNotExist
d1255 1
a1255 1
        throws SQLException, DataSetException, JoistDatabaseException
d1263 1
a1263 1
    public String getID () throws DataSetException
d1271 1
a1271 1
    public String getUserID () throws DataSetException
d1280 1
a1280 1
        throws DataSetException, JoistDatabaseException, DoesNotExist
d1288 1
a1288 1
    public String getDomainID () throws DataSetException
d1296 1
a1296 1
    public String getLoginID () throws DataSetException
d1304 1
a1304 1
    public String getName () throws DataSetException
d1309 1
a1309 1
    public String getType () throws DataSetException
d1314 1
a1314 1
    public boolean isGroup() throws DataSetException
d1319 1
a1319 1
    public boolean isDomain() throws DataSetException
d1324 1
a1324 1
    public boolean isHost() throws DataSetException
d1329 1
a1329 1
    public boolean isBase() throws DataSetException
d1334 1
a1334 1
    public String getAddress1 () throws DataSetException
d1339 1
a1339 1
    public String getAddress2 () throws DataSetException
d1344 1
a1344 1
    public String getCity () throws DataSetException
d1349 1
a1349 1
    public String getState () throws DataSetException
d1354 1
a1354 1
    public String getPostalCode () throws DataSetException
d1359 1
a1359 1
    public String getCountry () throws DataSetException
d1364 1
a1364 1
    public String getCitizenship () throws DataSetException
d1369 1
a1369 1
    public String getPhone () throws DataSetException    {
d1373 1
a1373 1
    public String getAltPhone () throws DataSetException
d1378 1
a1378 1
    public String getFax () throws DataSetException
d1383 1
a1383 1
    public String getCell () throws DataSetException
d1388 1
a1388 1
    public String getPager () throws DataSetException
d1393 1
a1393 1
    public String getEmail () throws DataSetException
d1398 1
a1398 1
    public String getOrganization () throws DataSetException
d1406 1
a1406 1
        throws DataSetException, JoistDatabaseException, DoesNotExist
@


1.85
log
@Reverting to previous version.  My fix didn't work for getRegularGroup exception.
@
text
@d88 1
a88 1
 * @@version $Id: User.java,v 1.84 2001/01/18 21:54:11 stack Exp $
d472 1
a472 1
        return (this == getGuest());
@


1.84
log
@Close dataset when done w/ it in the getGroup method
@
text
@d88 1
a88 1
 * @@version $Id: User.java,v 1.83 2001/01/18 07:21:44 dlr Exp $
d602 3
a604 3
        try
        { 
            for (int i = 0; i < groupSet.size(); i++)
d606 9
a614 17
                try 
                {
		            Record r = groupSet.getRecord(i);
		            String id 
                        = r.getValue(UserUserGroupManager.USER_GROUP_ID).asString();
                    groups.add(new UserGroup(conn, dMgr, id));
                } catch (DoesNotExist ignore) {
                } catch (JoistDatabaseException e) {
		            throw new DataSetException("Got JoistDatabaseException: " 
                        + e.getMessage());
	            }
            }
        }

        finally
        {
            if( groupSet != null ) groupSet.close( );
@


1.84.2.1
log
@moved over a bug fix from HEAD
@
text
@d88 1
a88 1
 * @@version $Id: User.java,v 1.84 2001/01/18 21:54:11 stack Exp $
d472 1
a472 1
        return getID().equals(getGuest().getID());
@


1.83
log
@Noted that only one User instance ever exists for the guest user.
@
text
@d88 1
a88 1
 * @@version $Id: User.java,v 1.82 2001/01/18 07:20:38 dlr Exp $
d600 1
d602 19
a620 2
        ArrayList groups = new ArrayList();
        for (int i = 0; i < groupSet.size(); i++)
d622 1
a622 8
            try {
		Record r = groupSet.getRecord(i);
		String id = r.getValue(UserUserGroupManager.USER_GROUP_ID).asString();
                groups.add(new UserGroup(conn, dMgr, id));
            } catch (DoesNotExist ignore) {
            } catch (JoistDatabaseException e) {
		throw new DataSetException("Got JoistDatabaseException: " + e.getMessage());
	    }
d624 1
@


1.82
log
@* Noted that the isGuest() method is to be used in template code.
* Provided cheaper comparison using memory addresses.
@
text
@d88 1
a88 1
 * @@version $Id: User.java,v 1.81 2001/01/18 07:18:19 dlr Exp $
d272 2
a273 1
     * Returns the guest user.
@


1.81
log
@Added isGuest() method which determines whether the user is the
application's guest user.
@
text
@d88 1
a88 1
 * @@version $Id: User.java,v 1.80 2001/01/17 23:47:38 dlr Exp $
d463 2
a464 1
     * Determines whether the user is the application's guest user.
d471 1
a471 1
        return getID().equals(getGuest().getID());
@


1.80
log
@Added static exists() method to that checks whether the specified user
exists.
@
text
@d88 1
a88 1
 * @@version $Id: User.java,v 1.79 2001/01/17 02:25:08 dlr Exp $
d461 11
@


1.79
log
@Use a WebMacro template to generate the body of the message used for
the email sent by the requestRoleWithoutApproval() method.
@
text
@d88 1
a88 1
 * @@version $Id: User.java,v 1.78 2001/01/16 22:22:59 dlr Exp $
d219 18
@


1.78
log
@More cleanup.
@
text
@d62 1
d88 1
a88 1
 * @@version $Id: User.java,v 1.77 2001/01/16 22:19:11 dlr Exp $
d98 6
a946 1
        HelmEmailer emailer = new HelmEmailer(conn, dMgr);
d948 6
a953 7
        StringBuffer body = new StringBuffer();
        body.append(getName())
            .append(" has requested the ").append(role.getName()) 
            .append(" role in the " ).append(project.getName())
            .append(" project.\n\n")
            .append("To approve or reject this request, go to:\n")
            .append("   ").append(project.projectMembersURL());
d955 1
@


1.77
log
@Better wording for JavaDoc.
@
text
@d87 1
a87 1
 * @@version $Id: User.java,v 1.76 2001/01/16 22:18:09 dlr Exp $
a228 2
        boolean cachingOn = true;
        User user=null;
d230 1
a230 1
        user = (User)cache.get(id);
d276 1
a276 1
     * userID.
@


1.76
log
@People seem to be confused about what a factor method is.
@
text
@d87 1
a87 1
 * @@version $Id: User.java,v 1.75 2001/01/12 22:25:27 leonardr Exp $
d221 2
a222 2
     * key.  Use this method instead if you feel the need to make
     * User(Connection, DataManager, String) public.
@


1.75
log
@Show user group memberships on user edit page.
@
text
@d87 1
a87 1
 * @@version $Id: User.java,v 1.74 2001/01/12 21:00:20 leonardr Exp $
d221 2
a222 1
     * key.
@


1.74
log
@Make it easier to turn caching off is that is desired later.
@
text
@d87 1
a87 1
 * @@version $Id: User.java,v 1.73 2001/01/11 19:26:25 dlr Exp $
d555 5
d579 19
d1281 10
d1293 1
a1293 1
        return getType().equals(UserType.REGULAR);
@


1.73
log
@Added broken constructor to support existing code in UserGroupAdd
servlet that was previously using a TableManager directly.
@
text
@d87 1
a87 1
 * @@version $Id: User.java,v 1.72 2001/01/11 19:15:41 dlr Exp $
d228 2
d231 1
a231 1
        User user = (User)cache.get(id);
@


1.72
log
@Name var after db field.
@
text
@d87 1
a87 1
 * @@version $Id: User.java,v 1.71 2001/01/10 01:52:19 leonardr Exp $
d310 17
@


1.71
log
@Filter interface is much simpler now. The more complicated interface is commented out in case we need it again.
@
text
@d87 1
a87 1
 * @@version $Id: User.java,v 1.70 2001/01/08 23:25:02 dlr Exp $
d318 1
a318 1
                 String userName, String password, String email)
d324 1
a324 1
             userName, password, email, null);
@


1.70
log
@Corrected a bunch of regressions to previous User instantion method.  Deprecated User's getUserID() method in favor of getID() for better conformance with BusinessObject interface and orthoginality with other business objects.  Added a guest user and interface.  Added some JavaDoc to User.
@
text
@d87 1
a87 1
 * @@version $Id: User.java,v 1.69 2001/01/05 21:42:38 leonardr Exp $
d1309 3
a1311 1
        return rec.getValue(UserManager.ORGANIZATION).asString();
@


1.69
log
@Big patch bringing the smart script runner online.
@
text
@d57 3
d87 1
a87 1
 * @@version $Id: User.java,v 1.68 2001/01/05 00:13:13 kmaples Exp $
d114 5
d128 5
d162 28
d246 10
d277 1
a277 1
    public User (Connection c, DataManager dMgr, String userID)
d286 4
a289 2
     * Constructor for a user which already exists -- accessed by
     * loginID.
d292 1
a292 1
                 String userName)
d297 1
a297 1
        setRecord(domMgr.getUserForLoginID(c, domainID, userName));
d1179 3
d1187 3
d1195 3
d1204 3
d1212 3
d1220 3
@


1.68
log
@Big patch implementing a pilot test of the smart 'determine which scripts to run' system.
@
text
@d84 1
a84 1
 * @@version $Id: User.java,v 1.67 2001/01/04 02:18:39 manoj Exp $
d804 1
a804 1
                log.info(lID + " is an administrator of " + pName);
d810 1
a810 1
                log.info(lID + " is a developer on " + pName); 
d817 1
a817 2
                log.info
                    (lID + " is an observer on " + pName); 
d823 1
a823 1
                log.info(lID + " has no issue tracking role in " + pName);
d910 1
a910 1
    public boolean equals(Project p)
d915 1
a915 1
            if (getID().equals(p.getID()))
d919 1
a919 1
        } catch (DataSetException ignore) {}
d921 11
@


1.67
log
@Since the username of the user is referred to as "loginID" in the rest
of the code, change the references in updateInfo() to match.
@
text
@d84 1
a84 1
 * @@version $Id: User.java,v 1.66 2001/01/03 00:15:30 kmaples Exp $
d226 1
a226 1
    protected User (Connection c, DataManager dMgr, String userID)
a451 2
	log.info("!!! Deleting user, dammit!");

a456 2
	log.info("!!! Done deleting user, dammit!");        

d488 1
a488 1
        for (int i = 0; i < groups.size(); i++)
d491 7
a497 2
                groups.add(new UserGroup(conn, dMgr, groupSet.getRecord(i)));
            } catch (DoesNotExist ignore) {}
d925 33
d1154 6
a1159 1
        return getType().equals(UserType.GROUP);
@


1.66
log
@Worked with Leonard to add call to 'deleteUser()' after deleting user from
specific projects.  This helps to address #1623 - removing users from IZ
when in single-db mode.
@
text
@d84 1
a84 1
 * @@version $Id: User.java,v 1.65 2000/12/30 02:14:01 leonardr Exp $
d503 1
a503 1
                           String username, String email, 
d516 1
a516 1
                    new MailingAliasSpec(domain.getName(), "www", username);
d520 1
a520 1
                log.error("unable to update email address for " + username +
d537 1
a537 1
            uMgr.updateUser(conn, context, getID(), username, email,
@


1.65
log
@Added isGroup and getType methods.
@
text
@d84 1
a84 1
 * @@version $Id: User.java,v 1.64 2000/12/28 21:09:29 dlr Exp $
d448 1
a448 16
        for (int i = 0; i < projects.size(); i++)
        {
            Project project = new Project(conn, dMgr, 
                                          projects.getRecord(i));
            if (userACL.hasPermissionForProject
                ("Project Issue Tracking - Configure", project.getID())
                || userACL.hasPermissionForProject
                ("Project Issue Tracking - Change", project.getID()) 
                || userACL.hasPermissionForProject
                ("Project Issue Tracking - Submit", project.getID()))
            {
                TigrisUpdate.deleteMember(conn, dMgr, deletingUser,
                                          project, this);
            }
        }            
        
d451 10
a460 1
        
d466 1
a466 1
            Domain domain = new Domain(conn, dMgr, getDomainID());
@


1.64
log
@Removed some extraneous whitespace.
@
text
@d84 1
a84 1
 * @@version $Id: User.java,v 1.63 2000/12/27 21:10:01 leonardr Exp $
d1117 10
@


1.63
log
@Allow parentheses in user names.
@
text
@d84 1
a84 1
 * @@version $Id: User.java,v 1.62 2000/12/23 01:23:18 dlr Exp $
d225 1
a225 1
     */    
d237 1
a237 1
     */    
d250 1
a250 1
     */    
d262 1
a262 1
     */    
d277 1
a277 1
     */    
@


1.62
log
@Added class header comment.
@
text
@d84 1
a84 1
 * @@version $Id: $
d143 1
a143 1
            realNameRE = new RE("^[\\w' \\-\\.\\,]+$");
@


1.61
log
@First use of BusinessObject's instance cache interface.
@
text
@d76 10
@


1.60
log
@Propogated object cache interface.
@
text
@d169 26
d216 1
a216 1
    public User (Connection c, DataManager dMgr, String userID)
d299 1
d312 1
a312 1
                          "as part of rollback: " + he.getMessage());
d318 1
a318 1
                    ("Unable to add db entry -- user exists: " + userName);
a345 5
    protected Dictionary getCache ()
    {
        return null;
    }

d530 7
a536 2
        uMgr.updateUser(conn, context, getID(), username, email,
                        realName, organization, passwd);
@


1.59
log
@Ported session list servlet from Joist.
@
text
@d319 9
a327 1
    protected final String getTableName() { return UserManager.TABLE_NAME; }
@


1.59.2.1
log
@getGroups works properly -> delete works properly. Also got rid of a bunch of gratuitious exceptions that were being thrown due to null organizations.
@
text
@d454 1
a454 1
        throws DataSetException, SQLException, JoistDatabaseException, DoesNotExist
d458 1
a458 1
        for (int i = 0; i < groupSet.size(); i++)
d460 3
a462 4
            Record r = groupSet.getRecord(i);
            
            UserGroup g = new UserGroup(conn, dMgr, r.getValue(usrGrpMgr.USER_GROUP_ID).asString());
            groups.add(g);
d1140 1
a1140 4

        String o = rec.getValue(UserManager.ORGANIZATION).asString();
        if (o == null) o = "";
        return o;
@


1.58
log
@Wide-ranging patch containing code which will eventually cause fewer MemberAdd and MemberDelete scripts to be run.
@
text
@d534 14
@


1.57
log
@Big patch whose main effect is to make dynamic the list of roles on UserEdit dynamic.
@
text
@d413 4
a416 2
                ("Project Issue Tracking - Configure", project.getID()) ||
                userACL.hasPermissionForProject
@


1.56
log
@Inline checks for null as part of the validation process.
@
text
@d71 1
d634 14
d806 14
@


1.55
log
@Migrated in User field validation routines from UserInfo servlet.
@
text
@d148 1
a148 1
        return userNameRE.isMatch(userName);
d159 1
a159 1
        return realNameRE.isMatch(realName);
@


1.54
log
@* adjust for corrections to Role constructor
* correct another Role constructor which listed the DataManager before
  the Connection
@
text
@d54 2
a55 2
import org.joist.database.*;
import org.joist.JoistException;
d61 3
d89 13
d104 3
d121 42
a162 2
    protected final String getTableName() { return UserManager.TABLE_NAME; }
    
d164 1
a164 1
    // Constructors.
d317 2
@


1.53
log
@* handle project deletion w/ anzu
* switch some method signatures in AnzuTigrisTask and add deleteProject
* switch from remove to delete where appropriate (when removing an
  object entirely, rather than just removing it from a container)
@
text
@d493 1
a493 1
        Role hostRole = new Role(dMgr, conn, "Host Admin", false);
d511 1
a511 1
        Role hostRole = new Role(dMgr, conn, "Host Admin", false);
d529 1
a529 1
        Role domainRole = new Role(dMgr, conn, "Domain Admin", false);
d548 1
a548 1
        Role domainRole = new Role(dMgr, conn, "Domain Admin", false);
d723 1
a723 1
        Role ownerRole = new Role(dMgr, conn, "Project Owner", false);
d866 1
a866 1
            Role role = new Role(dMgr, conn, roleID);
@


1.52
log
@Let's try this again.
@
text
@d221 1
a221 1
                alias.remove();
d224 1
a224 1
                log.error("Error attempting to remove alias for " + userName +
d371 1
a371 1
            alias.remove();
d587 1
a587 1
            AnzuTigrisTask.setOwnerAlias(conn, dMgr, grantingUser,
d743 1
a743 1
            AnzuTigrisTask.setOwnerAlias(conn, dMgr, revokingUser,
@


1.51
log
@Corrected typo.
@
text
@d174 2
a175 2
        return new User(acl, c, dMgr, context, domainID, realName,
                        userName, password, email, null);
@


1.50
log
@Desparate attempt to fix sandbox breakage.
@
text
@d175 1
a175 1
                        userName, password, email, null)
@


1.49
log
@Support for user organization
@
text
@d169 15
@


1.48
log
@support for owner aliases -- basically, owner@@{project}.{domain}
is an alias which sends e-mail to each of the people who's listed
as project owner for {project}.
@
text
@d169 2
a170 1
                 String userName, String password, String email)
d197 1
a197 1
                                      UserType.REGULAR);
d391 2
a392 2
                           String realName, String passwd,
                           String passwdConfirm)
d416 5
d422 1
a422 1
                        realName, passwd);
d1015 5
@


1.47
log
@delete the .qmail files for users when the user is deleted
@
text
@a351 1
            log.info("trying to remove alias for " + getName());
d563 6
d585 6
d718 6
@


1.46
log
@Put some permission checking in the User object where it should go... haven't yet moved it out of the old place (TigrisUpdate) though
@
text
@d349 13
@


1.45
log
@Even though the PASSWD_TICKET field is a varchar(255), MySQL is
treating the supplied ticket like a floating point number of greater
precision than it can handle.  This was resulting in the numerical
ticket being rounded off, but has been corrected via quoting.
@
text
@d582 1
d611 42
@


1.44
log
@Added a new ctor for creating a user instance for a given domain via
his or her email address.
@
text
@d289 2
a290 1
                 '=' + ticket + " where " + UserManager.USER_ID + "=?");
@


1.43
log
@Enabled security check of records passed into business objects.
@
text
@d152 12
@


1.42
log
@Added a check so that business objects cannot be created with records from the wrong table. Also added some new business objects.
@
text
@d101 2
@


1.41
log
@Added support for resigning your own roles.
@
text
@d119 1
a119 1
        throws DoesNotExist
@


1.40
log
@provide a less confusing message : generally this will only occur when
the user exists.  (admin -- and other mailing lists in www -- are
special cases...)
@
text
@a549 1
            log.info("Granting role.");
a553 1
            log.info("Requesting role.");
d561 34
d627 1
a627 2
    public void revokeRole(AccessControlList acl, User user, Role role, 
                           Project project)
d632 5
a636 2
        revokingUser.assertRoleGrantPermission(project);
        urpMgr.revoke(conn, revokingUser.getID(), user.getID(), role.getID(), project.getID());
@


1.39
log
@handle AlreadyExists errors cleanly for user creation
@
text
@d173 1
a173 1
                ("user " + userName + " email alias exists");
@


1.38
log
@Set user's email.  Set domainID field in same method call.
@
text
@d68 1
d157 1
a157 1
               UpdateException, InsertFailedException, DoesNotExist,
d168 1
d170 4
d176 1
a176 1
            if (debug) log.error("Unable to setup email: " + e.getMessage());
d199 4
@


1.37
log
@Removed incorrect comment.
@
text
@d174 3
a176 2
        Integer userID = uMgr.addUser(conn, context, realName, userName, 
                                      password);
a178 13
            PreparedStatement stmt = null;
            try
            {
                stmt = conn.prepareStatement
                    ("update User set domainID=?, type='base' where userID=?");
                stmt.setInt(1, Integer.parseInt(domainID));
                stmt.setInt(2, userID.intValue());
                stmt.executeUpdate();
            }
            finally
            {
                if (stmt != null) stmt.close();
            }
@


1.36
log
@Added and used method to show the user's sourcecast address, as opposed to the address they signed up with.
@
text
@d168 1
a168 1
        } catch (Exception e) { // Domain constructor throws this ... bleah
@


1.35
log
@minor error handling cleanup
@
text
@d806 6
d889 7
@


1.34
log
@added revoking UserID to call to UserRoleProjectManager.revoke--manager needs it to pass to TigrisUpdate.reflectRevoke
@
text
@d170 2
a171 2
            if (debug) log.error("unable to set up email: " + e.getMessage());
            throw new UpdateException("unable to set up e-mail alias");
d174 3
a177 2
            Integer userID = uMgr.addUser(conn, context, realName, userName, 
                                          password);
d192 1
a192 1
            
d198 4
a201 4
            } catch (HandlerException e2) {
                log.exception(e2);
                log.error("error attempting to remove alias for " + userName +
                        "as part of rollback: " + e2.getMessage());
d203 1
a203 1
            log.error("unable to complete creating User: "+e.getMessage());
d205 2
a206 2
            throw new UpdateException("unable to finish creating User: " +
                    e.getMessage());
@


1.34.2.1
log
@merged in changes from HEAD
@
text
@a67 1
import org.tigris.helm.AlreadyExists;
d156 1
a156 1
               UpdateException, AlreadyExists, DoesNotExist,
a166 1

d168 1
a168 5
        } catch (org.tigris.anzu.exception.AlreadyExists e) {
            if (debug) log.info("caught AlreadyExists in user creation");
            throw new AlreadyExists
                ("user " + userName + " already exists");
        } catch (Exception e) {
d170 2
a171 2
            if (debug) log.error("unable to setup email: " + e.getMessage());
            throw new UpdateException("Unable to setup e-mail alias");
a173 4
        Integer userID = uMgr.addUser(conn, context, domainID, realName, 
                                      userName, password, email,
                                      UserType.REGULAR);

d175 15
d191 1
a191 1

d197 4
a200 4
            } catch (HandlerException he) {
                log.exception(he);
                log.error("Error attempting to remove alias for " + userName +
                          "as part of rollback: " + he.getMessage());
d202 1
a202 1
            log.error("Unable to finish creating User: " + e.getMessage());
d204 2
a205 6
            if (e instanceof InsertFailedException) {
                throw new org.tigris.helm.AlreadyExists
                    ("Unable to add db entry -- user exists: " + userName);
            }
            throw new UpdateException("Unable to finish creating User: " +
                                      e.getMessage());
a804 6
    public Domain getDomain() 
        throws DataSetException, JoistDatabaseException, DoesNotExist
    {
        return new Domain(conn, dMgr, getDomainID());
    }

a881 7
    }

    public String getDomainEmail () 
        throws DataSetException, JoistDatabaseException, DoesNotExist
    {
        String domName = getDomain().getName();
        return getLoginID() + "@@" + domName;
@


1.34.2.2
log
@changes to support owner email aliases.  tested in head, tested in
branch, and ok'ed by jr.
@
text
@a333 12

        // remove the alias
        try {
            Domain domain = new Domain(conn, dMgr, getDomainID());
            MailingAliasSpec alias =
                new MailingAliasSpec(domain.getName(), "www", getLoginID());
            alias.remove();
        } catch (Exception e) {
            log.error("unable to delete email address for " + getName() +
                      ": " + e.getMessage());
            log.exception(e);
        }
d378 1
a378 1
            } catch (Exception e) {
a535 6
        // This is kind of ugly.  But project owners should have their
        // names in a special alias -- owner@@{project}.{domain}
        if (role.getName().equals("Project Owner")) {
            AnzuTigrisTask.setOwnerAlias(conn, dMgr, grantingUser,
                    project.getID(), true);
        }
a552 6
            // This is really ugly here.  But project owners should have their
            // names in a special alias -- owner@@{project}.{domain}
            if (role.getName().equals("Project Owner")) {
                AnzuTigrisTask.setOwnerAlias(conn, dMgr, null,
                        project.getID(), true);
            }
a602 6
        // This is kind of ugly.  But project owners should have their
        // names in a special alias -- owner@@{project}.{domain}
        if (role.getName().equals("Project Owner")) {
            AnzuTigrisTask.setOwnerAlias(conn, dMgr, revokingUser,
                    project.getID(), true);
        }
@


1.33
log
@The record that the User business object is wrapped around is not
updatable.  Refactored accordingly.
@
text
@d470 1
a470 1
        urpMgr.revoke(conn, getID(), hostRole.getID(),
d508 1
a508 1
        urpMgr.revoke(conn, getID(), domainRole.getID(), projectID);
d596 2
a597 1
    public void revokeRole(AccessControlList acl, Role role, Project project)
d603 1
a603 1
        urpMgr.revoke(conn, getID(), role.getID(), project.getID());
@


1.32
log
@Added clearPasswordTicket() method for removing a used password
ticket.
@
text
@d251 1
a251 1
    public void newPasswordTicket ()
d254 3
a256 2
        rec.setValue(PASSWD_TICKET, Nonce.buildNonce());
        rec.save();
d265 6
d276 1
a276 1
                 "=NULL where " + UserManager.USER_ID + "=?");
@


1.31
log
@UserManager is a donkey.
@
text
@d259 21
@


1.30
log
@Mega patch which makes script data persistent and which provides a general framework for tasks to be run (which will be used by anzu eventually)
@
text
@d380 1
a380 1
        uMgr.updateUser(conn, ctx, getID(), null, null, null, passwd);
@


1.29
log
@Added method for updating the user's password.
@
text
@d268 2
d297 2
a298 1
                TigrisUpdate.deleteMember(project, this);
@


1.28
log
@Added support for password change tickets to be emailed.
@
text
@d78 7
d333 2
a334 2
                           String realName, String password, 
                           String passwordConfirm)
d338 3
a340 6
        log.info("ACL ID is " + acl.getUserID() + " and ID is " + getID());
        if (!(acl.getUserID().equals(getID()) &&
              acl.hasPermissionForDomain("User - Edit - Self", getDomainID())))
        {
            acl.assertPermissionForDomain("User - Edit", getDomainID());
        }
d343 1
a343 1
                Domain domain = new Domain(conn,dMgr,getDomainID());
d350 1
a350 1
                        " : " + e.getMessage());
d357 1
a357 1
        
d359 46
a404 1
                        realName, password);
d757 1
a757 1
    public AccessControlList getACL()
@


1.27
log
@added getProjectsForUserGroups method; this gets a List of Project objects including those projects that are associated with groups the user is a member of.
@
text
@d73 9
d83 1
d85 1
d87 1
d89 1
d91 1
a93 3
    private static Log log = new Log("user", "User");
    private static final boolean debug = true;

d227 23
@


1.26
log
@All addition of users to user groups should go through the business objects.
@
text
@d620 35
@


1.25
log
@Mega patch providing more user group admin functionality.
@
text
@d175 1
a175 3
            usrGrpMgr.addUserToGroup(conn, getID(), 
                                     usrGrpMgr.getUserIDForDomainUserGroup
                                     (conn, domainID));
@


1.24
log
@stop putting user's e-mail addresses in the generic addresses list --
instead, put them in www (so that user@@www.domain and user@@domain will
work).
@
text
@d67 1
d236 1
a236 2
        DataSet groups = usrGrpMgr.getCompositesForBase(conn, getID());
        for (int i = 0; i < groups.size(); i++)
d238 2
a239 3
            String groupID = groups.getRecord(i)
                .getValue(UserUserGroupManager.USER_GROUP_ID).toString();
            usrGrpMgr.removeUserFromGroup(conn, getID(), groupID);
d265 24
@


1.23
log
@The app should now respect the Unapproved Project Role - Grant action properly.
@
text
@d146 1
a146 1
            alias = new MailingAliasSpec(domain.getName(), "", userName);
d285 2
a286 2
                MailingAliasSpec 
                    alias = new MailingAliasSpec(domain.getName(),"",username);
@


1.22
log
@Bugfixes and template changes related to UserGroupEdit.
@
text
@d503 1
a503 1
    protected void assertRoleGrantPermission (Project project)
d511 1
a511 1
    protected boolean hasRoleGrantPermission (Project project)
@


1.21
log
@new invitations stuff : if you have a valid ticket, you can request
roles, even if the project is private and you have none so far.
@
text
@d17 1
a17 1
 * software developed by Collab.Net (http://www.Collab.Net/)."
d27 1
a27 1
 * permission of Collab.Net.
d32 1
a32 1
 * IN NO EVENT SHALL COLLAB.NET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
d70 1
a70 1
public class User extends BusinessObject
d72 7
a78 7
    private UserManager uMgr;
    private DomainManager domMgr;
    private UserUserGroupManager usrGrpMgr;
    private UserRoleProjectManager urpMgr;
    private ProjectManager pMgr;
    private RoleManager rMgr;

d475 25
d684 1
a684 2
    public String getPhone () throws DataSetException
    {
@


1.20
log
@Added user group business object.
@
text
@d424 19
a442 1
            boolean ret = urpMgr.request(conn, getID(), role.getID(), 
d444 13
a456 13
            
            HelmEmailer emailer = new HelmEmailer(conn, dMgr);
            String subject = "New role requested.";
            StringBuffer body = new StringBuffer();
            body.append(getName())
                .append(" has requested the ").append(role.getName()) 
                .append(" role in the " ).append(project.getName())
                .append(" project.\n\n")
                .append("To approve or reject this request, go to:\n")
                .append("   ").append(project.projectMembersURL());
            Role ownerRole = new Role(dMgr, conn, "Project Owner", false);
            emailer.messageUsersWithProjectRole
                (ownerRole, project, subject, body.toString());
d458 1
a458 2
            return ret;
        }
@


1.19
log
@Cop out of grantRole if they *don't* already have the role, not if they *do*
@
text
@d87 8
@


1.18
log
@Implemented requestable roles and requesting roles in proprietary projects.
@
text
@d388 1
a388 1
        if (!getACL().hasRoleInProject(role.getName(), project.getID()))
@


1.17
log
@Send mail to domain admins on creation of unapproved project.
@
text
@d538 4
a541 1
            if (!requested.containsKey(roleID) && !approved.containsKey(roleID))
d543 1
a543 1
                avaliableRoles.add(new Role(dMgr, conn, roleID));
@


1.16
log
@notify anzu during user creation & when updates alter the e-mail address
@
text
@d429 1
a429 1
            emailer.mailUsersWithProjectRoleFromSystem
@


1.15
log
@Don't grant or revoke script-intensive roles unless it results in a change of state for the user.
@
text
@d59 1
d68 2
d126 2
a127 2
                 WebContext context, String domainID,
                 String realName, String userName, String password)
d134 12
d147 34
a180 14
        Integer userID = uMgr.addUser(conn, context, realName, userName, 
                                      password);
        PreparedStatement stmt = null;
        try
        {
            stmt = conn.prepareStatement
                ("update User set domainID=?, type='base' where userID=?");
            stmt.setInt(1, Integer.parseInt(domainID));
            stmt.setInt(2, userID.intValue());
            stmt.executeUpdate();
        }
        finally
        {
            if (stmt != null) stmt.close();
a181 6
        setRecord(uMgr.getUser(conn, userID.toString()));
        
        // Add the user to the appropriate user group.
        usrGrpMgr.addUserToGroup(conn, getID(), 
                                 usrGrpMgr.getUserIDForDomainUserGroup
                                 (conn, domainID));
d273 16
@


1.14
log
@Don't run MemberAdd on non-base projects.
@
text
@d251 1
a251 1
     * Grants the domain admin role to a user.
a256 1
        String role = "Host Admin";
d258 8
a265 5
        //TODO: If they already have the role, return.
        if (debug) log.info("host project id=" + pMgr.getHostProjectID());
        urpMgr.grantNamedRole(conn, getID(), "Host Admin",
                              pMgr.getHostProjectID(),
                              acl.getUserID());
d276 8
a283 3
        //TODO: If they don't have the role, return.
        urpMgr.revokeNamedRole(conn, getID(), "Host Admin",
                               pMgr.getHostProjectID());
d292 19
d313 6
a318 1
        //TODO: If they already have the role, return.
d320 1
a320 2
        urpMgr.grantNamedRole(conn, getID(), "Domain Admin", projectID, 
                              acl.getUserID());
a336 12
    /**
     * Revokes the domain admin role for a user.
     */
    public void revokeDomainAdminRole(AccessControlList acl, String domainID)
        throws SQLException, DataSetException, JoistDatabaseException,
               ACLException, DoesNotExist
    {
        acl.assertPermissionForDomain("Domain Role - Grant", domainID);
        String projectID = pMgr.getDomainProjectID(domainID);
        urpMgr.revokeNamedRole(conn, getID(), "Domain Admin", projectID);
    }

d343 4
@


1.13
log
@Made the TigrisUpdate stuff saner with the use of business objects.
@
text
@d257 1
d259 1
d272 1
a272 1
    {
d274 1
d287 1
d294 1
a294 1
     * Grants the domain admin role to a user.
@


1.12
log
@More specific message to project owners on role request.
@
text
@d87 1
a87 1
    public User (Connection conn, DataManager dMgr, Record rec)
d90 1
a90 1
        super(conn, dMgr, rec);
d187 1
a187 1
               ACLException
d213 2
a214 7
            Record project = projects.getRecord(i);
            String projectID = project
                .getValue(ProjectManager.PROJECT_ID).toString();
            String projectName = project
                .getValue(ProjectManager.PROJECT_NAME).toString();
            String brandName = null;                                      
            
d216 1
a216 1
                ("Project Issue Tracking - Configure", projectID) ||
d218 1
a218 1
                ("Project Issue Tracking - Submit", projectID))
d220 1
a220 3
                TigrisUpdate.deleteMember(domainName, projectName, 
                                          projectID, brandName, 
                                          getLoginID());
d255 1
a255 1
               ACLException
d269 1
a269 1
               ACLException
d281 1
a281 1
               ACLException
d308 1
a308 1
               ACLException
@


1.11
log
@Got rid of more superfluous UpdateException throwage.
@
text
@a357 1
            //TODO: Make this a better message, with links etc.
d361 3
a363 2
                .append(" project.");

@


1.10
log
@Check the granting/revoking user's permission, rather than the person with the role to be granted or revoked.
@
text
@d186 2
a187 2
        throws DataSetException, SQLException, UpdateException, 
               JoistDatabaseException, ACLException
d244 1
a244 1
               UpdateException, ACLException
d262 1
a262 1
               UpdateException, ACLException
d276 1
a276 1
               UpdateException, ACLException
d288 1
a288 1
               UpdateException, ACLException
d301 1
a301 1
               UpdateException, DoesNotExist
d315 1
a315 1
               UpdateException, ACLException
d324 1
a324 1
               UpdateException, ACLException, DoesNotExist
d335 1
a335 1
               UpdateException, DoesNotExist, JoistException, ACLException
d374 1
a374 1
               UpdateException, ACLException, DoesNotExist
@


1.9
log
@Set type of created user so they're not 'nobody'
@
text
@d324 1
a324 1
               UpdateException, ACLException
d326 2
a327 1
        assertRoleGrantPermission(project);
d374 1
a374 1
               UpdateException, ACLException
d376 2
a377 1
        assertRoleGrantPermission(project);
@


1.8
log
@Was using getUser when what was wanted was getUserLoginID in getClickThroughAsViewed
@
text
@d138 1
a138 1
                ("update User set domainID=? where userID=?");
@


1.7
log
@Fixed security bug. Also display buttons for role manipulation in UserEdit only if you can use those roles.
@
text
@d304 1
a304 1
        String rootID = uMgr.getUser(conn, "root")
@


1.6
log
@Fixed incorrect method call.
@
text
@d326 1
a326 7
        if (project.isApproved())
        {
            assertRoleGrantPermission(acl, role, project);
        } else {
            acl.assertPermissionForProject
                ("Unapproved Project Role - Grant", project.getID());
        }
d375 1
a375 1
        assertRoleGrantPermission(acl, role, project);
d387 11
a397 3
    protected void assertRoleGrantPermission (AccessControlList acl, 
                                              Role role, Project project)
        throws DataSetException, ACLException
d399 2
a400 13
        // Determine necessary permission, erring on the side of fascism.
        String neededPermission = "Host Role - Grant";
        String type = role.getType();
        if (type.equals(Role.PROJECT_ROLE))
        {
            neededPermission = "Project Role - Grant";
        }
        else if (type.equals(Role.DOMAIN_ROLE))
        {
            neededPermission = "Domain Role - Grant";
        }

        acl.assertPermissionForProject(neededPermission, project.getID());
@


1.5
log
@Send mail to project owners when someone requests a role in a project.
@
text
@d369 1
a369 1
            Role ownerRole = new Role(dMgr, conn, "Project Owner");
@


1.4
log
@Added method to set click-through user role thingy.
@
text
@d55 1
d340 1
a340 1
               UpdateException, ACLException
d357 17
a373 2
            return urpMgr.request(conn, getID(), role.getID(), 
                                  project.getID());
@


1.3
log
@Split up ProjectMembershipRequest to show requested/approved/other roles.
@
text
@d296 14
@


1.2
log
@Fixed project deletion and ProjectMembershipRequest
@
text
@d421 38
@


1.1
log
@Initial revision
@
text
@d231 1
a231 1
        urpMgr.deleteUser(conn, getID());
d327 18
a344 3
        acl.assertPermissionForProject("Project Role - Request",
                                       project.getID());
        return urpMgr.request(conn, getID(), role.getID(), project.getID());
@


1.1.1.1
log
@Merging newhelm tree into helm, as per IZ issue #557.  Previous major version of helm is tagged TIGRIS_NOV_11_2000.
@
text
@@
