of "properties" storage and editing for conferences, communities, users, and the global system. In addition, the "global properties" editing screen got implemented, because it wasn't there yet.
502 lines
14 KiB
Java
502 lines
14 KiB
Java
/*
|
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
|
* (the "License"); you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at <http://www.mozilla.org/MPL/>.
|
|
*
|
|
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
|
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
|
* language governing rights and limitations under the License.
|
|
*
|
|
* The Original Code is the Venice Web Communities System.
|
|
*
|
|
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
|
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
|
* Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
|
*
|
|
* Contributor(s):
|
|
*/
|
|
package com.silverwrist.venice.security;
|
|
|
|
import java.util.*;
|
|
|
|
public class Role implements Comparable, SecLevels
|
|
{
|
|
/*--------------------------------------------------------------------------------
|
|
* Static data members
|
|
*--------------------------------------------------------------------------------
|
|
*/
|
|
|
|
private static Role not_in_list;
|
|
private static Role no_access;
|
|
private static Role unrestricted_user;
|
|
private static Role global_admin;
|
|
private static Role comm_host;
|
|
private static ArrayList global_low;
|
|
private static ArrayList global_high;
|
|
private static ArrayList comm_low;
|
|
private static ArrayList comm_high;
|
|
private static ArrayList conf_low;
|
|
private static ArrayList conf_high;
|
|
private static HashMap all_roles;
|
|
|
|
private static List base_levels = null;
|
|
private static List base_levels_2 = null;
|
|
private static List commreadlist_rc = null;
|
|
private static List commwritelist_rc = null;
|
|
private static List commcreatelist_rc = null;
|
|
private static List commdeletelist_rc = null;
|
|
private static List commjoinlist_rc = null;
|
|
private static List comm_member_levels = null;
|
|
private static List confreadlist_rc = null;
|
|
private static List confpostlist_rc = null;
|
|
private static List confhidelist_rc = null;
|
|
private static List confdeletelist_rc = null;
|
|
private static List conf_member_levels = null;
|
|
private static List new_comm_list_rc = null;
|
|
|
|
/*--------------------------------------------------------------------------------
|
|
* Attributes
|
|
*--------------------------------------------------------------------------------
|
|
*/
|
|
|
|
private int level;
|
|
private String name;
|
|
|
|
/*--------------------------------------------------------------------------------
|
|
* Constructor
|
|
*--------------------------------------------------------------------------------
|
|
*/
|
|
|
|
protected Role(int level, String name)
|
|
{
|
|
this.level = level;
|
|
this.name = name;
|
|
|
|
} // end constructor
|
|
|
|
/*--------------------------------------------------------------------------------
|
|
* External operations
|
|
*--------------------------------------------------------------------------------
|
|
*/
|
|
|
|
public int getLevel()
|
|
{
|
|
return level;
|
|
|
|
} // end getLevel
|
|
|
|
public String getName()
|
|
{
|
|
return name;
|
|
|
|
} // end getName
|
|
|
|
public String toString()
|
|
{
|
|
StringBuffer buf = new StringBuffer(name);
|
|
buf.append('[').append(level).append(']');
|
|
return buf.toString();
|
|
|
|
} // end toString
|
|
|
|
public boolean equals(Object obj)
|
|
{
|
|
if (obj==null)
|
|
return false;
|
|
else if (obj==this)
|
|
return true;
|
|
if (obj instanceof Role)
|
|
{ // compare levels
|
|
Role other = (Role)obj;
|
|
return (level==other.getLevel());
|
|
|
|
} // end if
|
|
|
|
return obj.toString().equals(toString());
|
|
|
|
} // end equals
|
|
|
|
public int hashCode()
|
|
{
|
|
return level;
|
|
|
|
} // end hashCode
|
|
|
|
public int compareTo(Object obj)
|
|
{
|
|
if (!(obj instanceof Role))
|
|
throw new ClassCastException("comparing non-Role to Role");
|
|
Role other = (Role)obj;
|
|
return level - other.getLevel();
|
|
|
|
} // end compareTo
|
|
|
|
/*--------------------------------------------------------------------------------
|
|
* External static operations which generate lists of roles
|
|
*--------------------------------------------------------------------------------
|
|
*/
|
|
|
|
public static Role getRoleForLevel(int level)
|
|
{
|
|
Role rc = (Role)(all_roles.get(new Integer(level)));
|
|
if (rc!=null)
|
|
return rc;
|
|
return new Role(level,"(Level " + level + ")");
|
|
|
|
} // end getRoleForLevel
|
|
|
|
public static List getBaseLevelChoices()
|
|
{
|
|
if (base_levels==null)
|
|
{ // create the returned list
|
|
ArrayList rc = new ArrayList();
|
|
rc.addAll(global_low);
|
|
rc.add(unrestricted_user);
|
|
rc.addAll(global_high);
|
|
rc.remove(rc.size()-1);
|
|
rc.trimToSize();
|
|
base_levels = Collections.unmodifiableList(rc);
|
|
|
|
} // end if
|
|
|
|
return base_levels;
|
|
|
|
} // end getBaseLevelChoices
|
|
|
|
public static List getBaseLevelChoices2()
|
|
{
|
|
if (base_levels_2==null)
|
|
{ // create the returned list
|
|
ArrayList rc = new ArrayList();
|
|
rc.addAll(global_low);
|
|
rc.add(unrestricted_user);
|
|
rc.trimToSize();
|
|
base_levels_2 = Collections.unmodifiableList(rc);
|
|
|
|
} // end if
|
|
|
|
return base_levels_2;
|
|
|
|
} // end getBaseLevelChoices2
|
|
|
|
public static Role getGlobalAdmin()
|
|
{
|
|
return global_admin;
|
|
|
|
} // end getGlobalAdmin
|
|
|
|
public static List getCommunityReadList()
|
|
{
|
|
if (commreadlist_rc==null)
|
|
{ // create the returned list
|
|
ArrayList rc = new ArrayList();
|
|
rc.addAll(global_low);
|
|
rc.addAll(comm_low);
|
|
rc.add(unrestricted_user);
|
|
rc.addAll(comm_high);
|
|
rc.add(global_high.get(0));
|
|
rc.trimToSize();
|
|
commreadlist_rc = Collections.unmodifiableList(rc);
|
|
|
|
} // end if
|
|
|
|
return commreadlist_rc;
|
|
|
|
} // end getCommunityReadList
|
|
|
|
public static List getCommunityWriteList()
|
|
{
|
|
if (commwritelist_rc==null)
|
|
{ // build the return value
|
|
ArrayList rc = new ArrayList();
|
|
rc.addAll(comm_high);
|
|
rc.addAll(global_high);
|
|
rc.trimToSize();
|
|
commwritelist_rc = Collections.unmodifiableList(rc);
|
|
|
|
} // end if
|
|
|
|
return commwritelist_rc;
|
|
|
|
} // end getCommunityWriteList
|
|
|
|
public static List getCommunityCreateList()
|
|
{
|
|
if (commcreatelist_rc==null)
|
|
{ // create the return list
|
|
ArrayList rc = new ArrayList();
|
|
rc.add(global_low.get(global_low.size()-1));
|
|
rc.addAll(comm_low);
|
|
rc.add(unrestricted_user);
|
|
rc.addAll(comm_high);
|
|
rc.add(global_high.get(0));
|
|
rc.trimToSize();
|
|
commcreatelist_rc = Collections.unmodifiableList(rc);
|
|
|
|
} // end if
|
|
|
|
return commcreatelist_rc;
|
|
|
|
} // end getCommunityCreateList
|
|
|
|
public static List getCommunityDeleteList()
|
|
{
|
|
if (commdeletelist_rc==null)
|
|
{ // create the return list
|
|
ArrayList rc = new ArrayList();
|
|
rc.addAll(comm_high);
|
|
rc.addAll(global_high);
|
|
rc.add(no_access);
|
|
rc.trimToSize();
|
|
commdeletelist_rc = Collections.unmodifiableList(rc);
|
|
|
|
} // end if
|
|
|
|
return commdeletelist_rc;
|
|
|
|
} // end getCommunityDeleteList
|
|
|
|
public static List getCommunityJoinList()
|
|
{
|
|
if (commjoinlist_rc==null)
|
|
commjoinlist_rc = Collections.unmodifiableList(global_low);
|
|
return commjoinlist_rc;
|
|
|
|
} // end getCommunityJoinList
|
|
|
|
public static List getCommunityMemberLevelChoices()
|
|
{
|
|
if (comm_member_levels==null)
|
|
{ // figure out the member levels list
|
|
ArrayList rc = new ArrayList();
|
|
rc.add(not_in_list);
|
|
rc.addAll(global_low);
|
|
rc.addAll(comm_low);
|
|
rc.add(unrestricted_user);
|
|
rc.addAll(comm_high);
|
|
rc.remove(rc.size()-1);
|
|
rc.trimToSize();
|
|
comm_member_levels = Collections.unmodifiableList(rc);
|
|
|
|
} // end if
|
|
|
|
return comm_member_levels;
|
|
|
|
} // end getCommunityMemberLevelChoices
|
|
|
|
public static Role getCommunityHostRole()
|
|
{
|
|
return comm_host;
|
|
|
|
} // end getCommunityHostRole
|
|
|
|
public static List getConferenceReadList()
|
|
{
|
|
if (confreadlist_rc==null)
|
|
{ // precalculate the conference read list
|
|
ArrayList rc = new ArrayList();
|
|
rc.addAll(global_low);
|
|
rc.addAll(comm_low);
|
|
rc.addAll(conf_low);
|
|
rc.add(unrestricted_user);
|
|
rc.trimToSize();
|
|
confreadlist_rc = Collections.unmodifiableList(rc);
|
|
|
|
} // end if
|
|
|
|
return confreadlist_rc;
|
|
|
|
} // end getConferenceReadList
|
|
|
|
public static List getConferencePostList()
|
|
{
|
|
if (confpostlist_rc==null)
|
|
{ // precalculate the post list
|
|
ArrayList rc = new ArrayList();
|
|
rc.addAll(global_low);
|
|
rc.addAll(comm_low);
|
|
rc.addAll(conf_low);
|
|
rc.add(unrestricted_user);
|
|
rc.addAll(conf_high);
|
|
rc.trimToSize();
|
|
confpostlist_rc = Collections.unmodifiableList(rc);
|
|
|
|
} // end if
|
|
|
|
return confpostlist_rc;
|
|
|
|
} // return getConferencePostList
|
|
|
|
public static List getConferenceCreateList()
|
|
{
|
|
return getConferencePostList();
|
|
|
|
} // end getConferenceChangeList
|
|
|
|
public static List getConferenceHideList()
|
|
{
|
|
if (confhidelist_rc==null)
|
|
{ // precalculate the hide list
|
|
ArrayList rc = new ArrayList();
|
|
rc.addAll(conf_high);
|
|
rc.addAll(comm_high);
|
|
rc.add(global_high.get(0));
|
|
rc.trimToSize();
|
|
confhidelist_rc = Collections.unmodifiableList(rc);
|
|
|
|
} // end if
|
|
|
|
return confhidelist_rc;
|
|
|
|
} // end getConferenceHideList
|
|
|
|
public static List getConferenceNukeList()
|
|
{
|
|
return getConferenceHideList();
|
|
|
|
} // end getConferenceNukeList
|
|
|
|
public static List getConferenceChangeList()
|
|
{
|
|
return getConferenceHideList();
|
|
|
|
} // end getConferenceChangeList
|
|
|
|
public static List getConferenceDeleteList()
|
|
{
|
|
if (confdeletelist_rc==null)
|
|
{ // precalculate the delete list
|
|
ArrayList rc = new ArrayList();
|
|
rc.addAll(comm_high);
|
|
rc.addAll(global_high);
|
|
rc.add(no_access);
|
|
rc.trimToSize();
|
|
confdeletelist_rc = Collections.unmodifiableList(rc);
|
|
|
|
} // end if
|
|
|
|
return confdeletelist_rc;
|
|
|
|
} // end getConferenceDeleteList
|
|
|
|
public static List getConferenceMemberLevelChoices()
|
|
{
|
|
if (conf_member_levels==null)
|
|
{ // precalculate the list
|
|
ArrayList rc = new ArrayList();
|
|
rc.add(not_in_list);
|
|
rc.addAll(global_low);
|
|
rc.addAll(comm_low);
|
|
rc.addAll(conf_low);
|
|
rc.add(unrestricted_user);
|
|
rc.add(conf_high.get(conf_high.size()-1));
|
|
rc.trimToSize();
|
|
conf_member_levels = Collections.unmodifiableList(rc);
|
|
|
|
} // end if
|
|
|
|
return conf_member_levels;
|
|
|
|
} // end getConferenceMemberLevelChoices
|
|
|
|
public static List getNewCommunityLevelChoices()
|
|
{
|
|
if (new_comm_list_rc==null)
|
|
{ // precalculate the list
|
|
ArrayList rc = new ArrayList();
|
|
rc.add(global_low.get(global_low.size()-1));
|
|
rc.add(unrestricted_user);
|
|
rc.addAll(global_high);
|
|
rc.trimToSize();
|
|
new_comm_list_rc = Collections.unmodifiableList(rc);
|
|
|
|
} // end if
|
|
|
|
return new_comm_list_rc;
|
|
|
|
} // end getNewCommunityLevelChoices
|
|
|
|
/*--------------------------------------------------------------------------------
|
|
* Static initializer
|
|
*--------------------------------------------------------------------------------
|
|
*/
|
|
|
|
static
|
|
{ // begin initializing the "all roles" map
|
|
all_roles = new HashMap();
|
|
not_in_list = new Role(0,"(not in list)");
|
|
all_roles.put(new Integer(0),not_in_list);
|
|
no_access = new Role(NO_ACCESS,"No Access");
|
|
all_roles.put(new Integer(NO_ACCESS),no_access);
|
|
unrestricted_user = new Role(UNRESTRICTED_USER,"'Unrestricted' User");
|
|
all_roles.put(new Integer(UNRESTRICTED_USER),unrestricted_user);
|
|
|
|
Role tmp;
|
|
|
|
// initialize the "global lowband" vector
|
|
global_low = new ArrayList(3);
|
|
tmp = new Role(GLOBAL_ANONYMOUS,"Anonymous User");
|
|
global_low.add(tmp);
|
|
all_roles.put(new Integer(GLOBAL_ANONYMOUS),tmp);
|
|
tmp = new Role(GLOBAL_UNVERIFIED,"Unauthenticated User");
|
|
global_low.add(tmp);
|
|
all_roles.put(new Integer(GLOBAL_UNVERIFIED),tmp);
|
|
tmp = new Role(GLOBAL_NORMAL,"Normal User");
|
|
global_low.add(tmp);
|
|
all_roles.put(new Integer(GLOBAL_NORMAL),tmp);
|
|
global_low.trimToSize();
|
|
|
|
// initialize the "global highband" vector
|
|
global_high = new ArrayList(3);
|
|
tmp = new Role(GLOBAL_ANYADMIN,"Any System Administrator");
|
|
global_high.add(tmp);
|
|
all_roles.put(new Integer(GLOBAL_ANYADMIN),tmp);
|
|
tmp = new Role(GLOBAL_PFY,"System Assistant Administrator");
|
|
global_high.add(tmp);
|
|
all_roles.put(new Integer(GLOBAL_PFY),tmp);
|
|
global_admin = new Role(GLOBAL_BOFH,"Global System Administrator");
|
|
global_high.add(global_admin);
|
|
all_roles.put(new Integer(GLOBAL_BOFH),global_admin);
|
|
global_high.trimToSize();
|
|
|
|
// initialize the "community lowband" vector
|
|
comm_low = new ArrayList(1);
|
|
tmp = new Role(COMM_MEMBER,"Community Member");
|
|
comm_low.add(tmp);
|
|
all_roles.put(new Integer(COMM_MEMBER),tmp);
|
|
comm_low.trimToSize();
|
|
|
|
// initialize the "communtiy highband" vector
|
|
comm_high = new ArrayList(3);
|
|
tmp = new Role(COMM_ANYADMIN,"Any Community Administrator");
|
|
comm_high.add(tmp);
|
|
all_roles.put(new Integer(COMM_ANYADMIN),tmp);
|
|
tmp = new Role(COMM_COHOST,"Community Co-Host");
|
|
comm_high.add(tmp);
|
|
all_roles.put(new Integer(COMM_COHOST),tmp);
|
|
comm_host = new Role(COMM_HOST,"Community Host");
|
|
comm_high.add(comm_host);
|
|
all_roles.put(new Integer(COMM_HOST),comm_host);
|
|
comm_high.trimToSize();
|
|
|
|
// initialize the "conference lowband" vector
|
|
conf_low = new ArrayList(1);
|
|
tmp = new Role(CONFERENCE_MEMBER,"Conference Member");
|
|
conf_low.add(tmp);
|
|
all_roles.put(new Integer(CONFERENCE_MEMBER),tmp);
|
|
conf_low.trimToSize();
|
|
|
|
// initialize the "conference highband" vector
|
|
conf_high = new ArrayList(2);
|
|
tmp = new Role(CONFERENCE_ANYADMIN,"Any Conference Administrator");
|
|
conf_high.add(tmp);
|
|
all_roles.put(new Integer(CONFERENCE_ANYADMIN),tmp);
|
|
tmp = new Role(CONFERENCE_HOST,"Conference Host");
|
|
conf_high.add(tmp);
|
|
all_roles.put(new Integer(CONFERENCE_HOST),tmp);
|
|
conf_high.trimToSize();
|
|
|
|
} // end static initializer
|
|
|
|
} // end class Role
|