head	1.13;
access;
symbols
	TIGRIS_0_8_4:1.12.0.4
	TIGRIS_NOV_12_2000:1.12
	OLDHELM:1.12.0.2
	TIGRIS_NOV_11_2000:1.12
	TIGRIS_BASELINE:1.11;
locks; strict;
comment	@# @;


1.13
date	2000.12.06.19.52.22;	author leonardr;	state dead;
branches;
next	1.12;

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

1.11
date	2000.09.26.19.08.46;	author dlr;	state Exp;
branches;
next	1.10;

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

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

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

1.7
date	2000.09.26.01.28.41;	author dlr;	state Exp;
branches;
next	1.6;

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

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

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

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

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

1.1
date	2000.09.25.22.40.59;	author leonardr;	state Exp;
branches;
next	;


desc
@@


1.13
log
@Begone unused classes that exist elsewhere
@
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.security;

import java.sql.*;

import com.workingdogs.village.*;

import org.joist.database.DataManager;
import org.tigris.helm.security.CompositeManager;

/**
 * This class associates base users with composite users (which represent
 * groups of users.) Note that the database schema currently does not reflect 
 * this setup.
 *
 * @@author <a href="mailto:leonardr@@collab.net">Leonard Richardson</a>
 * @@author <a href="mailto:dlr@@collab.net">Daniel Rall</a>
 * @@version $Id: UserGroupManager.java,v 1.12 2000/10/03 18:11:47 leonardr Exp $
 */

public class UserGroupManager extends CompositeManager
{
    /** 
     * Constructor 
     */
    public UserGroupManager (DataManager dataMgr)
    {
        super(dataMgr, "userID", "userGroupID", "User", "HELM_USER_USERGROUP", 
              "isComposite", "userID");
    }
}


@


1.12
log
@Renamed, will move in the repo as well.
@
text
@d64 1
a64 1
 * @@version $Id: UsersetManager.java,v 1.11 2000/09/26 19:08:46 dlr Exp $
@


1.11
log
@Switched 'XxxSet' back to 'Xxxset' to maintain database consistancy with join tables.
@
text
@d64 1
a64 1
 * @@version $Id: UsersetManager.java,v 1.10 2000/09/26 17:16:56 leonardr Exp $
d67 2
a68 2
public class UsersetManager extends CompositeManager {

d72 4
a75 3
    public UsersetManager(DataManager dataMgr) {
        super(dataMgr, "userID", "usersetID", "User", "UserUserset", "isSet", 
              "userID");
@


1.10
log
@Brought field and table names in line with new database schema
@
text
@d64 1
a64 1
 * @@version $Id: UserSetManager.java,v 1.9 2000/09/26 02:29:30 dlr Exp $
d67 1
a67 1
public class UserSetManager extends CompositeManager {
d72 3
a74 2
    public UserSetManager(DataManager dataMgr) {
        super(dataMgr, "userID", "usersetID", "User", "UserUserset", "isSet", "userID");
@


1.9
log
@Obliterated evil tab characters.  No other change.
@
text
@d64 1
a64 1
 * @@version $Id: UserSetManager.java,v 1.8 2000/09/26 02:24:34 dlr Exp $
d73 1
a73 1
        super(dataMgr, "user", "userSet", "TUser", "UserSet", "isSet", "id");
d76 2
@


1.8
log
@Renamed xxxset to xxxSet.  Going to move the files in the repository to preserve history.
@
text
@d64 1
a64 1
 * @@version $Id: UserSetManager.java,v 1.7 2000/09/26 01:28:41 dlr Exp $
d73 1
a73 1
	super(dataMgr, "user", "userSet", "TUser", "UserSet", "isSet", "id");
@


1.7
log
@Added myself and Leonard to headers.
@
text
@d64 1
a64 1
 * @@version $Id: CompositeManager.java,v 1.4 2000/09/26 01:20:02 dlr Exp $
d67 1
a67 1
public class UsersetManager extends CompositeManager {
d72 1
a72 1
    public UsersetManager(DataManager dataMgr) {
d75 1
a75 3
    
} /* end class UsersetManager */

@


1.6
log
@Updated class members.
@
text
@d59 6
a64 2
 * groups of users.) Note that the database schema currently does not reflect this
 * setup.
@


1.5
log
@Made CompositeManager abstract and added its subclasses. Defanged
UsersetTest until the database is brought into line with CompositeManager.
@
text
@a64 9
    private static final String unitTable = "TUser";

    private static final String joinTable = "Userset";
    private static final String joinBaseField = "user";
    private static final String joinCompositeField = "userset";

    private static final String isCompositeField = "isSet";
    private static final String idField = "id";

d69 1
a69 1
	super(dataMgr);
@


1.4
log
@- Used sanitizeSQL metho
- Made stuff fit in my 80 char wide window
@
text
@d48 1
a48 1
package org.tigris.helm.database;
a49 6
import org.webmacro.servlet.*;
import org.webmacro.engine.*;
import org.webmacro.broker.*;

import javax.servlet.*;
import javax.servlet.http.*;
a53 2
import org.joist.util.*;
import org.joist.database.TableManager;
d55 1
d58 3
a60 4
 * This class deals with usersets, and manages the proper database
 * activities related to their creation and deletion, ensuring
 * database integrity. 
 *
a61 1
public class UsersetManager extends TableManager {
d63 7
a69 23
    /**
     * This exception indicates that the given Userset already exists.
     */
    public static class AlreadyExists extends Exception {
	private String usersetID;
	
	/**
	 * Create a new "userset already exists" exception
	 *
	 * @@param usersetID The userset that already exists.
	 */
	public AlreadyExists(String usersetID) {
	    super("Userset " + usersetID + " already exists");
	    this.usersetID = usersetID;
	}
	
	/**
	 * Return the userset that already exists
	 */
	public String getUsersetID() {
	    return usersetID;
	}
    } /* end class AlreadyExists */
d71 2
a72 23
    /**
     * This exception indicates that no Userset with the given name exists.
     */
    public static class NoSuchUserset extends Exception {
	private String userset;
	
	/**
	 * Create a new "no such Userset" exception
	 *
	 * @@param userset The name of the offending userset.
	 */
	public NoSuchUserset(String userset) {
	    super("Userset " + userset + " does not exist");
	    this.userset = userset;
	}
	
	/**
	 * Return the userset that caused this exception
	 */
	public String getUserset() {
	    return userset;
	}
    } /* end class NoSuchUserset */    
d74 2
a75 2
    /**
     * This exception indicates that no Userset with the given ID exists.
a76 22
    public static class NoSuchUsersetID extends Exception {
	private String usersetID;
	
	/**
	 * Create a new "no such Userset ID" exception
	 *
	 * @@param usersetID The ID of the offending userset.
	 */
	public NoSuchUsersetID(String usersetID) {
	    super("Userset with ID " + usersetID + " does not exist");
	    this.usersetID = usersetID;
	}
	
	/**
	 * Return the userset that caused this exception
	 */
	public String getUsersetID() {
	    return usersetID;
	}
    } /* end class NoSuchUserset */    

    /** Constructor */
d81 1
a81 76
    /**
     * Get the unique identifier of a Userset from a name.
     *
     * @@param connection A database connection
     * @@param userset The name of the userset to get the ID of
     *
     * @@return A String containing the unique ID.
     *
     * @@exception SQLException if there was a database error
     * @@exception NoSuchUserset if the named userset does not exist.
     */
    public static String getID(Connection connection, String userset)    
    throws SQLException, DataSetException, NoSuchUserset
    {
	String usersetID = "";
	String query = "SELECT usersetID FROM Userset WHERE userset = " + 
            sanitizeSQL(userset);
	QueryDataSet qds = new QueryDataSet(connection, query);
	qds.fetchRecords();
	if (!qds.containsRecord(0)) {
	    throw new NoSuchUserset(userset);
	} else {
	    usersetID = qds.getRecord(0).getValue(0).asString();	    
	}
	qds.close();
	return usersetID;
    }

    /**
     * Get the name of a given userset from the unique ID.
     *
     * @@param connection A database connection
     * @@param id The ID of the userset to get the name of
     *
     * @@return a String containing the name.
     *
     * @@exception SQLException if there was a database error
     * @@exception NoSuchUserset if the identified userset does not exist.
     */
    public static String getName(Connection connection, String usersetID)    
    throws SQLException, DataSetException, NoSuchUsersetID
    {
	String query="SELECT userset FROM Userset WHERE usersetID = '" + 
            usersetID + "'";
	QueryDataSet qds = new QueryDataSet(connection, query);	
	qds.fetchRecords();
	if (!qds.containsRecord(0)) {
	     throw new NoSuchUsersetID(usersetID);
	 } else {
	     return qds.getRecord(0).getValue(0).asString();
	 }
     }    

     /**
      * Add a new userset to the database. This should set up all the
      * tables and such that any other database accessor will expect to
      * find.
      *
      * @@param connection A database connection
      * @@param userset The name of the new userset
      *
      * @@exception SQLException if there was a database error
      * @@exception AlreadyExists if a Userset by this name already exists
      */
    public static void addUserset(Connection connection, String userset)    
	throws SQLException, DataSetException, AlreadyExists {
	
	TableDataSet tds = new TableDataSet(connection, "Userset");
	tds.where("userset = " + sanitizeSQL(userset));
	if (tds.fetchRecords().containsRecord(0))
	    throw new AlreadyExists(userset);
	
	Record r = tds.addRecord();
	r.setValue("userset", userset);
	r.save();
    }
a82 60
    /**
     * Remove a userset from the database.
     *
     * @@param connection A database connection
     * @@param userset The name of the Userset to delete
     *
     * @@exception SQLException if there was a database error
     */
    public static void deleteUserset(Connection connection, String usersetID)
	throws SQLException, DataSetException {

	// Delete the Userset. If we set up the relationships between
	// tables properly, this should also remove everyone belonging
	// to the userset and all the roles in groups the userset has.
	TableDataSet tds = new TableDataSet(connection, "Userset");
	tds.where("usersetID = '" + usersetID + "'");
	Record r = tds.fetchRecords().getRecord(0);
	r.markToBeDeleted();
	r.save();
    }

    /**
     * Retrieve a list of Usersets from the database.
     *
     * @@param connection A database connection
     * @@return a List of UsersetManager.Entry objects representing all the Usersets
     *         in the database.
     */
    public static DataSet getUsersets(Connection connection)
	throws SQLException, DataSetException {
	
	TableDataSet tds = new TableDataSet(connection, "Userset");
	return tds.fetchRecords();
    }

    /**
     * Add a TUser to a Userset.
     *
     * @@param connection A database connection
     * @@param user The user ID to add to the Userset
     * @@param userset The userset to add to.
     *
     * @@exception SQLException if there was a database error
     * @@exception AlreadyExists if a Userset by this name already exists
     */
    public static void addUserToUserset(Connection connection, String userID, 
					String usersetID)					     throws SQLException, DataSetException {

	TableDataSet tds = new TableDataSet(connection, "UserUserset");
	tds.where("userID = '" + userID + "' AND usersetID = '" + usersetID + 
                  '\'');
	if (!tds.fetchRecords().containsRecord(0)) {
	    Record r = tds.addRecord();
	    r.setValue("userID", userID);
	    r.setValue("usersetID", usersetID);
	    r.save();
	}
    }
    
} /* end class ModuleManager */
@


1.3
log
@extraneous space
@
text
@d164 2
a165 1
	String query = "SELECT usersetID FROM Userset WHERE userset = '" + userset + "'";
d191 2
a192 1
	String query="SELECT userset FROM Userset WHERE usersetID = '" + usersetID + "'";
d217 1
a217 1
	tds.where("userset = '" + userset + "'");
d222 1
a222 1
	r.setValue("userset",userset);
d275 2
a276 1
	tds.where("userID = '" + userID + "' AND usersetID = '" + usersetID + "'");
d279 2
a280 2
	    r.setValue("userID",userID);
	    r.setValue("usersetID",usersetID);
@


1.2
log
@Was passing empty userset variable value, rather than usersetID that
couldn't be found.
@
text
@d132 1
a132 1
	    super("Userset  with ID " + usersetID + " does not exist");
@


1.1
log
@The start of Tigris' new permission system.
@
text
@a189 1
	String userset = "";
d194 1
a194 1
	     throw new NoSuchUsersetID(userset);
@

