completed the transition away from features and toward "services" - the old

database-based configuration has been replaced with the new XML-based one.
This paves the way for further modularization of the code.
This commit is contained in:
Eric J. Bowersox 2001-11-22 04:53:17 +00:00
parent 85518ca0d5
commit f5a5009932
29 changed files with 813 additions and 544 deletions

View File

@ -53,7 +53,7 @@
<!-- Members service --> <!-- Members service -->
<service id="Members" index="4"> <service id="Members" index="4">
<setup default="true" locked="true"/> <setup default="true" locked="true"/>
<access permission="Community.Read"/> <access permission="Community.Read" role="Community.Member"/>
<link sequence="4800" href="members?sig=${cid}" type="servlet">Members</link> <link sequence="4800" href="members?sig=${cid}" type="servlet">Members</link>
</service> </service>

View File

@ -198,22 +198,6 @@ CREATE TABLE refcategory (
UNIQUE INDEX display (parent, name) UNIQUE INDEX display (parent, name)
); );
# A reference to feature codes and what they mean.
CREATE TABLE refsigftr (
ftr_code SMALLINT NOT NULL PRIMARY KEY,
is_default TINYINT DEFAULT 0,
is_locked TINYINT DEFAULT 0,
is_hidden TINYINT DEFAULT 0,
require_read TINYINT DEFAULT 1,
sequence SMALLINT NOT NULL,
min_level SMALLINT UNSIGNED DEFAULT 0,
symbol CHAR(4) NOT NULL,
name VARCHAR(64) NOT NULL,
applet VARCHAR(64) NOT NULL,
UNIQUE INDEX name_x (name),
UNIQUE index sequence_x (sequence)
);
# The table mapping SIGs and their associated features. # The table mapping SIGs and their associated features.
CREATE TABLE sigftrs ( CREATE TABLE sigftrs (
sigid INT NOT NULL, sigid INT NOT NULL,
@ -472,18 +456,18 @@ INSERT INTO refaudit (type, descr) VALUES
(111, 'Admin Change User Account'), (111, 'Admin Change User Account'),
(112, 'Admin Set Account Security'), (112, 'Admin Set Account Security'),
(113, 'Admin Lock/Unlock Account'), (113, 'Admin Lock/Unlock Account'),
(201, 'Create New SIG'), (201, 'Create New Community'),
(202, 'Set SIG Membership'), (202, 'Set Community Membership'),
(203, 'Set SIG Contact Info'), (203, 'Set Community Contact Info'),
(204, 'Set SIG Feature Set'), (204, 'Set Community Services'),
(205, 'Set SIG Name'), (205, 'Set Community Name'),
(206, 'Set SIG Alias'), (206, 'Set Community Alias'),
(207, 'Set SIG Category'), (207, 'Set Community Category'),
(208, 'Set SIG Hiding Information'), (208, 'Set Community Hiding Information'),
(209, 'Set SIG Members-Only Flag'), (209, 'Set Community Members-Only Flag'),
(210, 'Set SIG Join Key'), (210, 'Set Community Join Key'),
(211, 'Set SIG Security Levels'), (211, 'Set Community Security Levels'),
(212, 'Delete SIG'), (212, 'Delete Community'),
(301, 'Create New Conference'), (301, 'Create New Conference'),
(302, 'Set Conference Security Levels'), (302, 'Set Conference Security Levels'),
(303, 'Set Conference Name'), (303, 'Set Conference Name'),
@ -874,15 +858,6 @@ INSERT INTO refcategory (catid, parent, symlink, name) VALUES
# Make sure the special "System" category is hidden. # Make sure the special "System" category is hidden.
UPDATE refcategory SET hide_dir = 1, hide_search = 1 WHERE catid = 15; UPDATE refcategory SET hide_dir = 1, hide_search = 1 WHERE catid = 15;
# Populate the Features reference table.
INSERT INTO refsigftr (ftr_code, is_default, is_locked, is_hidden, require_read, sequence, min_level,
symbol, name, applet) VALUES
(0, 1, 1, 1, 0, 4900, 0, 'PROF', 'Profile', 'sigprofile'),
(1, 1, 1, 1, 0, 5000, 57000, 'ADMN', 'Administration', 'sigadmin'),
(2, 0, 1, 1, 0, 10000, 63000, 'SYSA', 'System Administration', 'sysadmin'),
(3, 1, 0, 0, 1, 500, 0, 'CONF', 'Conferences', 'confops'),
(4, 1, 1, 0, 1, 4800, 0, 'MEMB', 'Members', 'members');
# Create the initial advertisements (quotes). # Create the initial advertisements (quotes).
INSERT INTO adverts (imagepath) VALUES INSERT INTO adverts (imagepath) VALUES
('images/ads/Brown.gif'), ('images/ads/Brown.gif'),

View File

@ -20,6 +20,7 @@ package com.silverwrist.venice.core;
import java.util.BitSet; import java.util.BitSet;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Set;
import com.silverwrist.venice.except.AccessError; import com.silverwrist.venice.except.AccessError;
import com.silverwrist.venice.except.DataException; import com.silverwrist.venice.except.DataException;
import com.silverwrist.venice.except.EmailException; import com.silverwrist.venice.except.EmailException;
@ -68,13 +69,11 @@ public interface CommunityContext extends SearchMode
public abstract void putContactInfo(ContactInfo ci) throws DataException, AccessError; public abstract void putContactInfo(ContactInfo ci) throws DataException, AccessError;
public abstract BitSet getFeatures(); public abstract Set getServices();
public abstract void setFeatures(BitSet feature_set, BitSet mask) throws DataException, AccessError; public abstract Set getConfiguredServices();
public abstract List getCommunityFeaturesList(); public abstract void setServiceEnable(ServiceToken token, boolean enable) throws AccessError, DataException;
public abstract String getDefaultApplet();
public abstract void setName(String name) throws DataException, AccessError; public abstract void setName(String name) throws DataException, AccessError;
@ -98,9 +97,9 @@ public interface CommunityContext extends SearchMode
public abstract void setMembersOnly(boolean flag) throws DataException, AccessError; public abstract void setMembersOnly(boolean flag) throws DataException, AccessError;
public abstract short getInitialFeatureIndex(); public abstract ServiceToken getDefaultService();
public abstract void setInitialFeatureIndex(short ndx) throws DataException, AccessError; public abstract void setDefaultService(ServiceToken token) throws AccessError, DataException;
public abstract String getJoinKey() throws DataException, AccessError; public abstract String getJoinKey() throws DataException, AccessError;

View File

@ -17,16 +17,14 @@
*/ */
package com.silverwrist.venice.core; package com.silverwrist.venice.core;
public interface CommunityFeature public interface ServiceGroup
{ {
public abstract int getFeatureCode(); public static final int SVCGRP_GLOBAL = 0;
public abstract String getSymbol(); public static final int SVCGRP_COMMUNITY = 1;
public abstract String getName(); public static final int SVCGRP_USER = 2;
public abstract String getApplet(); public static final int NUM_SVCGRPS = 3;
public abstract int getSequence(); } // end interface ServiceGroup
} // end interface CommunityFeature

View File

@ -0,0 +1,110 @@
/*
* 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.core;
public class ServiceToken implements Comparable, ServiceGroup
{
/*--------------------------------------------------------------------------------
* Attributes
*--------------------------------------------------------------------------------
*/
private int group;
private String symbol;
private int index;
/*--------------------------------------------------------------------------------
* Constructor
*--------------------------------------------------------------------------------
*/
protected ServiceToken(int group, String symbol, int index)
{
this.group = group;
this.symbol = symbol;
this.index = index;
} // end constructor
/*--------------------------------------------------------------------------------
* Overrides from class Object
*--------------------------------------------------------------------------------
*/
public boolean equals(Object o)
{
if ((o==null) || !(o instanceof ServiceToken))
return false;
ServiceToken other = (ServiceToken)o;
return ((this.group==other.group) && (this.symbol.equals(other.symbol)));
} // end equals
public int hashCode()
{
return (group << 24) ^ symbol.hashCode();
} // end hashCode
public String toString()
{
return symbol;
} // end toString
/*--------------------------------------------------------------------------------
* Implementations from interface Comparable
*--------------------------------------------------------------------------------
*/
public int compareTo(Object o)
{
if (o==null)
throw new NullPointerException("compareTo null object!");
ServiceToken other = (ServiceToken)o; // may throw ClassCastException
int rc = this.group - other.group;
if (rc!=0)
return rc;
return this.symbol.compareTo(other.symbol);
} // end compareTo
/*--------------------------------------------------------------------------------
* External operations
*--------------------------------------------------------------------------------
*/
public final int getGroup()
{
return group;
} // end getGroup
public final String getSymbol()
{
return symbol;
} // end getSymbol
public final int getIndex()
{
return index;
} // end getIndex
} // end class ServiceToken

View File

@ -27,16 +27,12 @@ import com.silverwrist.venice.except.DataException;
import com.silverwrist.venice.except.EmailException; import com.silverwrist.venice.except.EmailException;
import com.silverwrist.venice.htmlcheck.HTMLChecker; import com.silverwrist.venice.htmlcheck.HTMLChecker;
public interface VeniceEngine extends SearchMode public interface VeniceEngine extends SearchMode, ServiceGroup
{ {
public abstract void initialize(Document config, String app_root) throws ConfigException, DataException; public abstract void initialize(Document config, String app_root) throws ConfigException, DataException;
public abstract void shutdown() throws ConfigException; public abstract void shutdown() throws ConfigException;
public abstract int getNumFeatures();
public abstract BitSet getAllFeaturesMask();
public abstract UserContext createUserContext(String remote_addr) throws DataException; public abstract UserContext createUserContext(String remote_addr) throws DataException;
public abstract String getEmailAddressForUser(String username) throws DataException, AccessError; public abstract String getEmailAddressForUser(String username) throws DataException, AccessError;

View File

@ -28,6 +28,7 @@ import com.silverwrist.venice.core.*;
import com.silverwrist.venice.core.internals.*; import com.silverwrist.venice.core.internals.*;
import com.silverwrist.venice.except.*; import com.silverwrist.venice.except.*;
import com.silverwrist.venice.security.AuditRecord; import com.silverwrist.venice.security.AuditRecord;
import com.silverwrist.venice.svc.*;
class CommunityCoreData implements CommunityData, CommunityDataBackend class CommunityCoreData implements CommunityData, CommunityDataBackend
{ {
@ -94,17 +95,17 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
private boolean hidden_search; // hidden from keyword searches? private boolean hidden_search; // hidden from keyword searches?
private boolean members_only; // only members allowed in this community? private boolean members_only; // only members allowed in this community?
private boolean is_admin; // is this the administrative community? private boolean is_admin; // is this the administrative community?
private short initial_feature; // the "initial" feature to display for this community
private String name; // the name of this community private String name; // the name of this community
private String language; // the default language code private String language; // the default language code
private String synopsis; // the synopsis of the community private String synopsis; // the synopsis of the community
private String rules; // the community "rules" private String rules; // the community "rules"
private String alias; // the community alias value private String alias; // the community alias value
private boolean public_comm; // is this a public community? private boolean public_comm; // is this a public community?
private BitSet features; // set of available features
private ObjectCache conf_objcache = new ObjectCache(new ConferenceCommunityContextImplCreator()); private ObjectCache conf_objcache = new ObjectCache(new ConferenceCommunityContextImplCreator());
private boolean deleted = false; // has this community been deleted? private boolean deleted = false; // has this community been deleted?
private OptionSet flags; // property flags private OptionSet flags; // property flags
private HashSet services; // services for this community
private ServiceToken initial_service; // the initial service
/*-------------------------------------------------------------------------------- /*--------------------------------------------------------------------------------
* Constructor * Constructor
@ -152,13 +153,18 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
} // end while } // end while
// get the community feature set // get the set of community services
services = new HashSet();
sql.setLength(0); sql.setLength(0);
sql.append("SELECT ftr_code FROM sigftrs WHERE sigid = ").append(cid).append(';'); sql.append("SELECT ftr_code FROM sigftrs WHERE sigid = ").append(cid).append(';');
rs = stmt.executeQuery(sql.toString()); rs = stmt.executeQuery(sql.toString());
features = new BitSet();
while (rs.next()) while (rs.next())
features.set(rs.getInt("ftr_code")); { // get the service tokens and return them
ServiceToken token = env.getSCM().getTokenForIndex(ServiceControl.SVCGRP_COMMUNITY,rs.getInt(1));
if (token!=null)
services.add(token);
} // end while
} // end try } // end try
catch (SQLException e) catch (SQLException e)
@ -178,7 +184,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
protected CommunityCoreData(EnvEngine env, int cid, java.util.Date creation, protected CommunityCoreData(EnvEngine env, int cid, java.util.Date creation,
String name, String alias, int host_uid, String language, String synopsis, String name, String alias, int host_uid, String language, String synopsis,
String rules, String joinkey, boolean hide_dir, boolean hide_search, String rules, String joinkey, boolean hide_dir, boolean hide_search,
BitSet features) int[] levels, Set services)
{ {
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
logger.debug("new CommunityCoreData for BRAND NEW COMMUNITY " + cid); logger.debug("new CommunityCoreData for BRAND NEW COMMUNITY " + cid);
@ -188,11 +194,11 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
this.created = creation; this.created = creation;
this.last_access = creation; this.last_access = creation;
this.last_update = creation; this.last_update = creation;
this.read_level = new_env.getDefaultRole("Community.Read").getLevel(); this.read_level = levels[0];
this.write_level = new_env.getDefaultRole("Community.Write").getLevel(); this.write_level = levels[1];
this.create_level = new_env.getDefaultRole("Community.Create").getLevel(); this.create_level = levels[2];
this.delete_level = new_env.getDefaultRole("Community.Delete").getLevel(); this.delete_level = levels[3];
this.join_level = new_env.getDefaultRole("Community.Join").getLevel(); this.join_level = levels[4];
this.contactid = -1; this.contactid = -1;
this.host_uid = host_uid; this.host_uid = host_uid;
this.category_id = 0; this.category_id = 0;
@ -200,15 +206,15 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
this.hidden_search = hide_search; this.hidden_search = hide_search;
this.members_only = true; this.members_only = true;
this.is_admin = false; this.is_admin = false;
this.initial_feature = 0;
this.name = name; this.name = name;
this.language = language; this.language = language;
this.synopsis = synopsis; this.synopsis = synopsis;
this.rules = rules; this.rules = rules;
this.alias = alias; this.alias = alias;
this.public_comm = StringUtil.isStringEmpty(joinkey); this.public_comm = StringUtil.isStringEmpty(joinkey);
this.features = (BitSet)(features.clone());
this.flags = new OptionSet(); this.flags = new OptionSet();
this.services = new HashSet(services);
this.initial_service = env.getSCM().getTokenForIndex(ServiceControl.SVCGRP_COMMUNITY,0);
if (env.getEngine().getParamBoolean(EngineBackend.BP_POSTPICTURES)) if (env.getEngine().getParamBoolean(EngineBackend.BP_POSTPICTURES))
flags.set(BP_POSTPICTURES); flags.set(BP_POSTPICTURES);
@ -237,7 +243,6 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
hidden_search = rs.getBoolean("hide_search"); hidden_search = rs.getBoolean("hide_search");
members_only = rs.getBoolean("membersonly"); members_only = rs.getBoolean("membersonly");
is_admin = rs.getBoolean("is_admin"); is_admin = rs.getBoolean("is_admin");
initial_feature = rs.getShort("init_ftr");
name = rs.getString("signame"); name = rs.getString("signame");
language = rs.getString("language"); language = rs.getString("language");
synopsis = rs.getString("synopsis"); synopsis = rs.getString("synopsis");
@ -251,6 +256,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
else // Admin is NEVER a public community! else // Admin is NEVER a public community!
public_comm = false; public_comm = false;
alias = rs.getString("alias"); alias = rs.getString("alias");
initial_service = env.getSCM().getTokenForIndex(ServiceControl.SVCGRP_COMMUNITY,rs.getShort("init_ftr"));
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
logger.debug("Loaded data for community \"" + name + "\" (ID " + cid + ", alias '" + alias logger.debug("Loaded data for community \"" + name + "\" (ID " + cid + ", alias '" + alias
@ -578,17 +584,53 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
} // end putContactInfo } // end putContactInfo
public BitSet getFeatureSet() public Set getServices()
{ {
return (BitSet)(features.clone()); return Collections.unmodifiableSet((Set)(services.clone()));
} // end getFeatureSet } // end getServices
public synchronized void putFeatureSet(EnvCommunity outer, BitSet set) throws DataException public Set getServices(EnvCommunity outer)
{
HashSet tmp = new HashSet();
Iterator it = services.iterator();
while (it.hasNext())
{ // get the service associated with the token
ServiceToken token = (ServiceToken)(it.next());
CommService svc = (CommService)(env.getSCM().getServiceForToken(token));
// Check the permission first.
String perm = svc.getPermission();
if (perm!=null)
{ // test the permission against the outer environment
if (!(outer.testPermission(perm)))
continue; // permission failed - just go on to the next one
} // end if
if (outer.satisfy(svc.getRole()))
tmp.add(token);
} // end getServices
if (tmp.isEmpty())
return Collections.EMPTY_SET;
else
return Collections.unmodifiableSet(tmp);
} // end getServices
public synchronized void setServiceEnable(EnvCommunity outer, ServiceToken token, boolean enable)
throws DataException
{ {
if (deleted) if (deleted)
throw new DataException("This community has been deleted."); throw new DataException("This community has been deleted.");
if (enable && services.contains(token))
return;
if (!enable && !(services.contains(token)))
return;
Connection conn = null; // database connection Connection conn = null; // database connection
AuditRecord ar = null; // audit record AuditRecord ar = null; // audit record
@ -599,35 +641,26 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
stmt.executeUpdate("LOCK TABLES sigftrs WRITE;"); stmt.executeUpdate("LOCK TABLES sigftrs WRITE;");
try try
{ // first, delete all the old entries { // execute the right statement
StringBuffer sql = new StringBuffer("DELETE FROM sigftrs WHERE sigid = "); StringBuffer sql;
sql.append(cid).append(';'); if (enable)
stmt.executeUpdate(sql.toString()); { // create an INSERT statement
sql = new StringBuffer("INSERT INTO sigftrs (sigid, ftr_code) VALUES (");
// now, add all the new entries sql.append(cid).append(", ").append(token.getIndex()).append(");");
sql.setLength(0);
for (int i=0; i<set.length(); i++)
{ // test all the bits in the new feature set
if (set.get(i))
{ // append the appropriate element to the SQL statement we're building
if (sql.length()==0)
sql.append("INSERT INTO sigftrs (sigid, ftr_code) VALUES ");
else
sql.append(", ");
sql.append('(').append(cid).append(", ").append(i).append(')');
} // end if
} // end for
if (sql.length()>0)
{ // add the features to the database
sql.append(';');
stmt.executeUpdate(sql.toString());
} // end if } // end if
else
{ // create a DELETE statement
sql = new StringBuffer("DELETE FROM sigftrs WHERE sigid = ");
sql.append(cid).append(" AND ftr_code = ").append(token.getIndex()).append(';');
features = set; } // end else
stmt.executeUpdate(sql.toString());
if (enable)
services.add(token);
else
services.remove(token);
} // end try } // end try
finally finally
@ -665,21 +698,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
} // end finally } // end finally
} // end putFeatureSet } // end setServiceEnable
public List getCommunityFeaturesList(int level)
{
return env.getEngine().getCommunityFeatureSet(features,level,canReadCommunitySubObjects(level));
} // end getCommunityFeaturesList
public String getDefaultApplet()
{
StringBuffer buf = new StringBuffer(env.getEngine().getAppletForFeature(initial_feature));
buf.append("?sig=").append(cid);
return buf.toString();
} // end getDefaultApplet
public synchronized void setName(EnvCommunity outer, String name) throws DataException public synchronized void setName(EnvCommunity outer, String name) throws DataException
{ {
@ -1076,13 +1095,13 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
} // end setMembersOnly } // end setMembersOnly
public short getInitialFeatureIndex() public ServiceToken getDefaultService()
{ {
return initial_feature; return initial_service;
} // end getInitialFeatureIndex } // end getDefaultService
public synchronized void setInitialFeatureIndex(short ndx) throws DataException public synchronized void setDefaultService(ServiceToken token) throws DataException
{ {
if (deleted) if (deleted)
throw new DataException("This community has been deleted."); throw new DataException("This community has been deleted.");
@ -1094,11 +1113,11 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); Statement stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("UPDATE sigs SET init_ftr = "); StringBuffer sql = new StringBuffer("UPDATE sigs SET init_ftr = ");
sql.append(ndx).append(", lastupdate = '"); sql.append(token.getIndex()).append(", lastupdate = '");
java.util.Date now = new java.util.Date(); java.util.Date now = new java.util.Date();
sql.append(SQLUtil.encodeDate(now)).append("' WHERE sigid = ").append(cid).append(';'); sql.append(SQLUtil.encodeDate(now)).append("' WHERE sigid = ").append(cid).append(';');
stmt.executeUpdate(sql.toString()); stmt.executeUpdate(sql.toString());
initial_feature = ndx; initial_service = token;
last_update = now; last_update = now;
} // end try } // end try
@ -1114,7 +1133,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
} // end finally } // end finally
} // end setInitialFeatureIndex } // end setDefaultService
public String getJoinKey() throws DataException public String getJoinKey() throws DataException
{ {
@ -1435,17 +1454,13 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
} // end getMemberCount } // end getMemberCount
public boolean isFeaturePresent(String symbol) public boolean hasService(ServiceToken token)
{ {
if (deleted) if (deleted)
return false; return false;
int ndx = env.getEngine().getFeatureIndexBySymbol(symbol); return services.contains(token);
if (ndx>=0)
return features.get(ndx);
else
return false;
} // end isFeaturePresent } // end hasService
public synchronized ConferenceCommunityContext getConferenceDataObject(int confid) throws DataException public synchronized ConferenceCommunityContext getConferenceDataObject(int confid) throws DataException
{ {
@ -1954,12 +1969,11 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
boolean hide_search) throws DataException, AccessError boolean hide_search) throws DataException, AccessError
{ {
Connection conn = null; // database connection Connection conn = null; // database connection
BitSet def_features = env.getEngine().getDefaultFeaturesMask();
int new_cid; // ID of the new community int new_cid; // ID of the new community
java.util.Date creation; // creation date! java.util.Date creation; // creation date!
AuditRecord ar = null; // the audit record AuditRecord ar = null; // the audit record
CommunityCoreData comm; // the new community that gets returned CommunityCoreData comm; // the new community that gets returned
try try
{ // get a database connection and create the appropriate SELECT statement { // get a database connection and create the appropriate SELECT statement
conn = env.getConnection(); conn = env.getConnection();
@ -1981,14 +1995,15 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
+ "rules, joinkey, alias) VALUES ('"); + "rules, joinkey, alias) VALUES ('");
creation = new java.util.Date(); creation = new java.util.Date();
String creation_str = SQLUtil.encodeDate(creation); String creation_str = SQLUtil.encodeDate(creation);
int level_read = env.getCommunityDefaultRole("Community.Read").getLevel(); int[] levels = new int[5];
int level_write = env.getCommunityDefaultRole("Community.Write").getLevel(); levels[0] = env.getCommunityDefaultRole("Community.Read").getLevel();
int level_create = env.getCommunityDefaultRole("Community.Create").getLevel(); levels[1] = env.getCommunityDefaultRole("Community.Write").getLevel();
int level_delete = env.getCommunityDefaultRole("Community.Delete").getLevel(); levels[2] = env.getCommunityDefaultRole("Community.Create").getLevel();
int level_join = env.getCommunityDefaultRole("Community.Join").getLevel(); levels[3] = env.getCommunityDefaultRole("Community.Delete").getLevel();
levels[4] = env.getCommunityDefaultRole("Community.Join").getLevel();
sql.append(creation).append("', '").append(creation).append("', '").append(creation).append("', "); sql.append(creation).append("', '").append(creation).append("', '").append(creation).append("', ");
sql.append(level_read).append(", ").append(level_write).append(", ").append(level_create).append(", "); sql.append(levels[0]).append(", ").append(levels[1]).append(", ").append(levels[2]).append(", ");
sql.append(level_delete).append(", ").append(level_join).append(", ").append(host_uid).append(", "); sql.append(levels[3]).append(", ").append(levels[4]).append(", ").append(host_uid).append(", ");
sql.append(hide_dir ? '1' : '0').append(", ").append(hide_search ? '1' : '0').append(", "); sql.append(hide_dir ? '1' : '0').append(", ").append(hide_search ? '1' : '0').append(", ");
sql.append(SQLUtil.encodeStringArg(name)).append(", ").append(SQLUtil.encodeStringArg(language)); sql.append(SQLUtil.encodeStringArg(name)).append(", ").append(SQLUtil.encodeStringArg(language));
sql.append(", ").append(SQLUtil.encodeStringArg(synopsis)).append(", "); sql.append(", ").append(SQLUtil.encodeStringArg(synopsis)).append(", ");
@ -2011,22 +2026,22 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
} // end else } // end else
if (def_features.length()>0) // Assign the new community the default services for new communities.
{ // need to build the community's defined feature set Set default_service = env.getSCM().getDefaultServices(ServiceControl.SVCGRP_COMMUNITY);
if (default_service.size()>0)
{ // build the communty's defined service set
sql.setLength(0); sql.setLength(0);
for (int i=0; i<def_features.length(); i++) Iterator it = default_service.iterator();
{ // look for set bits in the feature set while (it.hasNext())
if (def_features.get(i)) { // appeand each clause to the string in turn
{ // build up the SQL statement piece by piece ServiceToken token = (ServiceToken)(it.next());
if (sql.length()==0) if (sql.length()==0)
sql.append("INSERT INTO sigftrs (sigid, ftr_code) VALUES "); sql.append("INSERT INTO sigftrs (sigid, ftr_code) VALUES ");
else else
sql.append(", "); sql.append(", ");
sql.append('(').append(new_cid).append(", ").append(i).append(')'); sql.append('(').append(new_cid).append(", ").append(token.getIndex()).append(')');
} // end if } // end while
} // end for
// close out the SQL statement // close out the SQL statement
sql.append(';'); sql.append(';');
@ -2050,7 +2065,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
// Create the CommunityCoreData object representing this community and register it with the engine's // Create the CommunityCoreData object representing this community and register it with the engine's
// community data object cache. // community data object cache.
comm = new CommunityCoreData(env,new_cid,creation,name,alias,host_uid,language,synopsis,rules,joinkey, comm = new CommunityCoreData(env,new_cid,creation,name,alias,host_uid,language,synopsis,rules,joinkey,
hide_dir,hide_search,def_features); hide_dir,hide_search,levels,default_service);
comm.newProperties(conn); comm.newProperties(conn);
} // end try } // end try

View File

@ -27,6 +27,7 @@ import com.silverwrist.venice.db.*;
import com.silverwrist.venice.except.*; import com.silverwrist.venice.except.*;
import com.silverwrist.venice.security.AuditRecord; import com.silverwrist.venice.security.AuditRecord;
import com.silverwrist.venice.security.Role; import com.silverwrist.venice.security.Role;
import com.silverwrist.venice.svc.*;
class CommunityUserContextImpl implements CommunityContext, CommunityBackend class CommunityUserContextImpl implements CommunityContext, CommunityBackend
{ {
@ -82,6 +83,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend
private CommunitySimpleDataCache cache; // cache object for name and alias private CommunitySimpleDataCache cache; // cache object for name and alias
private CommunityData data = null; // the actual community data private CommunityData data = null; // the actual community data
private boolean deleted = false; // has this community been deleted? private boolean deleted = false; // has this community been deleted?
private ServiceToken x_conf_token; // token for Conferences service
/*-------------------------------------------------------------------------------- /*--------------------------------------------------------------------------------
* Constructors * Constructors
@ -97,6 +99,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend
this.cid = cid; this.cid = cid;
setMemberValues(granted_level,true,locked); setMemberValues(granted_level,true,locked);
this.cache = new CommunitySimpleDataCache(name,alias); this.cache = new CommunitySimpleDataCache(name,alias);
this.x_conf_token = env.getSCM().getTokenForSymbol(ServiceControl.SVCGRP_COMMUNITY,"Conference");
} // end constructor } // end constructor
@ -111,6 +114,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend
this.show_admin = false; this.show_admin = false;
this.locked = false; this.locked = false;
this.cache = new CommunitySimpleDataCache(name,alias); this.cache = new CommunitySimpleDataCache(name,alias);
this.x_conf_token = env.getSCM().getTokenForSymbol(ServiceControl.SVCGRP_COMMUNITY,"Conference");
} // end constructor } // end constructor
@ -124,6 +128,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend
this.cache = null; // no cache required - we have the CommunityData this.cache = null; // no cache required - we have the CommunityData
this.data = data; this.data = data;
setMemberValues(new_env.getDefaultRole("Community.Creator").getLevel(),true,true); setMemberValues(new_env.getDefaultRole("Community.Creator").getLevel(),true,true);
this.x_conf_token = env.getSCM().getTokenForSymbol(ServiceControl.SVCGRP_COMMUNITY,"Conference");
} // end constructor } // end constructor
@ -198,7 +203,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend
if (deleted) if (deleted)
throw new DataException("This community has been deleted."); throw new DataException("This community has been deleted.");
if (!(getData().isFeaturePresent("CONF"))) if (!(getData().hasService(x_conf_token)))
{ // the community doesn't use conferencing { // the community doesn't use conferencing
logger.error("the community doesn't use conferencing"); logger.error("the community doesn't use conferencing");
throw new AccessError("This community does not use the conferencing feature."); throw new AccessError("This community does not use the conferencing feature.");
@ -206,7 +211,21 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend
} // end if } // end if
getData().testMembership(level,is_member); getData().testMembership(level,is_member);
if (!(env.getEngine().canAccessFeature("CONF",level,getData().canReadCommunitySubObjects(level)))) CommService svc = (CommService)(env.getSCM().getServiceForToken(x_conf_token));
String perm = svc.getPermission();
if (perm!=null)
{ // test the permission
if (!(env.testPermission(perm)))
{ // you can't access the conferences!
logger.error("user not permitted to read confs from this community");
throw new AccessError("You are not permitted to access this community's conferences.");
} // end if
} // end if
Role r = svc.getRole();
if (!(r.isSatisfiedBy(level)))
{ // you can't access the conferences! { // you can't access the conferences!
logger.error("user not permitted to read confs from this community"); logger.error("user not permitted to read confs from this community");
throw new AccessError("You are not permitted to access this community's conferences."); throw new AccessError("You are not permitted to access this community's conferences.");
@ -479,64 +498,48 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend
} // end putContactInfo } // end putContactInfo
public BitSet getFeatures() public Set getServices()
{ {
CommunityData d = getDataNE(); CommunityData d = getDataNE();
if (d!=null) if (d!=null)
return d.getFeatureSet(); return d.getServices(env);
else else
return null; return null;
} // end getFeatures } // end getServices
public void setFeatures(BitSet feature_set, BitSet mask) throws DataException, AccessError public Set getConfiguredServices()
{ {
CommunityData d = getDataNE();
if (d!=null)
return d.getServices();
else
return null;
} // end getConfiguredServices
public void setServiceEnable(ServiceToken token, boolean enable) throws AccessError, DataException
{
if (token.getGroup()!=ServiceToken.SVCGRP_COMMUNITY)
throw new IllegalArgumentException("Not a community service token.");
Service svc = env.getSCM().getServiceForToken(token);
if (svc==null)
throw new IllegalArgumentException("Invalid service token.");
getData().testMembership(level,is_member); getData().testMembership(level,is_member);
if (!(getData().canModifyCommunityProfile(level))) if (!(getData().canModifyCommunityProfile(level)))
{ // this user can't modify the community feature set { // this user can't modify the community feature set
logger.error("user not permitted to modify the community's feature set"); logger.error("user not permitted to modify the community's information");
throw new AccessError("You are not permitted to modify the community's feature set."); throw new AccessError("You are not permitted to modify the community's information.");
} // end if } // end if
// Adjust the "mask"...this function cannot affect the set of "locked" features. if (svc.isLocked())
BitSet real_mask = (BitSet)(mask.clone()); return; // can't modify the state of a locked service
real_mask.andNot(env.getEngine().getLockedFeaturesMask());
// Figure out which bits are being carried over from the old feature set. getData().setServiceEnable(env,token,enable);
BitSet new_features = getData().getFeatureSet();
new_features.andNot(real_mask);
// Figure out which bits are being set by the new feature set. } // end setServiceEnable
BitSet update_bits = (BitSet)(feature_set.clone());
update_bits.and(real_mask);
// Put the features together to result in the final feature set, which we set down in
// the "back end" class.
new_features.or(update_bits);
getData().putFeatureSet(env,new_features);
} // end setFeatures
public List getCommunityFeaturesList()
{
CommunityData d = getDataNE();
if (d!=null)
return d.getCommunityFeaturesList(level);
else
return null;
} // end getCommunityFeaturesList
public String getDefaultApplet()
{
CommunityData d = getDataNE();
if (d!=null)
return d.getDefaultApplet();
else
return null;
} // end getDefaultApplet
public void setName(String name) throws DataException, AccessError public void setName(String name) throws DataException, AccessError
{ {
@ -710,25 +713,25 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend
} // end setMembersOnly } // end setMembersOnly
public short getInitialFeatureIndex() public ServiceToken getDefaultService()
{ {
CommunityData d = getDataNE(); CommunityData d = getDataNE();
if (d!=null) if (d!=null)
return d.getInitialFeatureIndex(); return d.getDefaultService();
else else
return 0; return null;
} // end getInitialFeatureIndex } // end getDefaultService
public void setInitialFeatureIndex(short ndx) throws DataException, AccessError public void setDefaultService(ServiceToken token) throws AccessError, DataException
{ {
if (!(env.getEngine().isValidInitialFeatureIndex(ndx))) if (token.getGroup()!=ServiceToken.SVCGRP_COMMUNITY)
{ // the mode is not valid throw new IllegalArgumentException("Not a community service token.");
logger.error("feature index value " + String.valueOf(ndx) + " is not valid"); Service svc = env.getSCM().getServiceForToken(token);
throw new IllegalArgumentException("invalid initial feature index"); if (svc==null)
throw new IllegalArgumentException("Invalid service token.");
} // end if if (!(getData().hasService(token)))
throw new DataException("This service is not enabled for this community.");
getData().testMembership(level,is_member); getData().testMembership(level,is_member);
if (!(getData().canModifyCommunityProfile(level))) if (!(getData().canModifyCommunityProfile(level)))
{ // this user can't modify the community feature set { // this user can't modify the community feature set
@ -737,9 +740,9 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend
} // end if } // end if
getData().setInitialFeatureIndex(ndx); getData().setDefaultService(token);
} // end setInitialFeatureIndex } // end setDefaultService
public String getJoinKey() throws DataException, AccessError public String getJoinKey() throws DataException, AccessError
{ {
@ -1056,7 +1059,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend
boolean hide_list) throws DataException, AccessError boolean hide_list) throws DataException, AccessError
{ {
getData().testMembership(level,is_member); getData().testMembership(level,is_member);
if (!(getData().isFeaturePresent("CONF"))) if (!(getData().hasService(x_conf_token)))
{ // we can't create a conference in this community { // we can't create a conference in this community
logger.error("this community does not use conferencing"); logger.error("this community does not use conferencing");
throw new AccessError("You are not permitted to create conferences in this community."); throw new AccessError("You are not permitted to create conferences in this community.");
@ -1085,7 +1088,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend
return false; return false;
if (!(d.checkMembership(level,is_member))) if (!(d.checkMembership(level,is_member)))
return false; return false;
if (d.isFeaturePresent("CONF")) if (d.hasService(x_conf_token))
return d.canCreateCommunitySubObjects(level); return d.canCreateCommunitySubObjects(level);
else else
return false; return false;
@ -1120,7 +1123,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend
return false; return false;
if (!(d.checkMembership(level,is_member))) if (!(d.checkMembership(level,is_member)))
return false; return false;
if (d.isFeaturePresent("CONF")) if (d.hasService(x_conf_token))
return d.canCreateCommunitySubObjects(level); return d.canCreateCommunitySubObjects(level);
else else
return false; return false;

View File

@ -17,17 +17,35 @@
*/ */
package com.silverwrist.venice.core.impl; package com.silverwrist.venice.core.impl;
import java.lang.ref.*;
import java.util.*; import java.util.*;
import org.apache.log4j.*; import org.apache.log4j.*;
import org.w3c.dom.*; import org.w3c.dom.*;
import com.silverwrist.util.*; import com.silverwrist.util.*;
import com.silverwrist.venice.core.ServiceGroup;
import com.silverwrist.venice.core.ServiceToken;
import com.silverwrist.venice.except.*; import com.silverwrist.venice.except.*;
import com.silverwrist.venice.security.*; import com.silverwrist.venice.security.*;
import com.silverwrist.venice.svc.*; import com.silverwrist.venice.svc.*;
import com.silverwrist.venice.util.XMLLoader; import com.silverwrist.venice.util.XMLLoader;
class ServiceControlManager class ServiceControlManager implements ServiceControl
{ {
/*--------------------------------------------------------------------------------
* Internal class implementing ServiceTokens that allows them to be constructed
*--------------------------------------------------------------------------------
*/
static class MyServiceToken extends ServiceToken
{
public MyServiceToken(int group, String symbol, int index)
{
super(group,symbol,index);
} // end constructor
} // end class MyServiceToken
/*-------------------------------------------------------------------------------- /*--------------------------------------------------------------------------------
* Internal "Community Service Site" class * Internal "Community Service Site" class
*-------------------------------------------------------------------------------- *--------------------------------------------------------------------------------
@ -41,6 +59,17 @@ class ServiceControlManager
} // end class MyCommServiceSite } // end class MyCommServiceSite
/*--------------------------------------------------------------------------------
* Internal "Service Predicate" class
*--------------------------------------------------------------------------------
*/
abstract class ServicePredicate
{
public abstract boolean test(Service svc);
} // end class ServicePredicate
/*-------------------------------------------------------------------------------- /*--------------------------------------------------------------------------------
* Static data members * Static data members
*-------------------------------------------------------------------------------- *--------------------------------------------------------------------------------
@ -53,15 +82,17 @@ class ServiceControlManager
*-------------------------------------------------------------------------------- *--------------------------------------------------------------------------------
*/ */
private Map comm_symbol_to_service; private Map[] symbol_to_service = new Map[NUM_SVCGRPS];
private Map comm_index_to_service; private Map[] index_to_service = new Map[NUM_SVCGRPS];
private SoftReference[] list_all_cache = new SoftReference[NUM_SVCGRPS];
private SoftReference[] list_default_cache = new SoftReference[NUM_SVCGRPS];
/*-------------------------------------------------------------------------------- /*--------------------------------------------------------------------------------
* Constructors * Constructors
*-------------------------------------------------------------------------------- *--------------------------------------------------------------------------------
*/ */
ServiceControlManager(Document cfg, SecurityMonitor sm_global, SecurityMonitor sm_comm) ServiceControlManager(Document cfg, SecurityMonitorEnvironment sm_env)
throws ConfigException throws ConfigException
{ {
XMLLoader loader = XMLLoader.get(); XMLLoader loader = XMLLoader.get();
@ -70,12 +101,16 @@ class ServiceControlManager
NodeList nl; NodeList nl;
int i; int i;
symbol_to_service[SVCGRP_GLOBAL] = Collections.EMPTY_MAP;
index_to_service[SVCGRP_GLOBAL] = Collections.EMPTY_MAP;
// Get the "community" section // Get the "community" section
Element sect = root_h.getSubElement("community"); Element sect = root_h.getSubElement("community");
if (sect!=null) if (sect!=null)
{ // load the services for the section { // load the services for the section
HashMap tmp_symbol_to_service = new HashMap(); HashMap tmp_symbol_to_service = new HashMap();
HashMap tmp_index_to_service = new HashMap(); HashMap tmp_index_to_service = new HashMap();
SecurityMonitor sm_comm = sm_env.getMonitor("Community");
nl = sect.getChildNodes(); nl = sect.getChildNodes();
for (i=0; i<nl.getLength(); i++) for (i=0; i<nl.getLength(); i++)
{ // get each element node... { // get each element node...
@ -83,30 +118,40 @@ class ServiceControlManager
if ((n.getNodeType()==Node.ELEMENT_NODE) && (n.getNodeName().equals("service"))) if ((n.getNodeType()==Node.ELEMENT_NODE) && (n.getNodeName().equals("service")))
{ // create the appropriate service settings { // create the appropriate service settings
CommService svc = initCommunityService((Element)n,sm_comm); CommService svc = initCommunityService((Element)n,sm_comm);
tmp_symbol_to_service.put(svc.getSymbol(),svc); tmp_symbol_to_service.put(svc.getToken().getSymbol(),svc);
tmp_index_to_service.put(new Integer(svc.getIndex()),svc); tmp_index_to_service.put(new Integer(svc.getToken().getIndex()),svc);
} // end if } // end if
} // end for } // end for
if (tmp_symbol_to_service.size()>0) if (tmp_symbol_to_service.size()>0)
comm_symbol_to_service = Collections.unmodifiableMap(tmp_symbol_to_service); symbol_to_service[SVCGRP_COMMUNITY] = Collections.unmodifiableMap(tmp_symbol_to_service);
else else
comm_symbol_to_service = Collections.EMPTY_MAP; symbol_to_service[SVCGRP_COMMUNITY] = Collections.EMPTY_MAP;
if (tmp_index_to_service.size()>0) if (tmp_index_to_service.size()>0)
comm_index_to_service = Collections.unmodifiableMap(tmp_index_to_service); index_to_service[SVCGRP_COMMUNITY] = Collections.unmodifiableMap(tmp_index_to_service);
else else
comm_index_to_service = Collections.EMPTY_MAP; index_to_service[SVCGRP_COMMUNITY] = Collections.EMPTY_MAP;
} // end if } // end if
else else
{ // no community services - undo this { // no community services - undo this
comm_symbol_to_service = Collections.EMPTY_MAP; symbol_to_service[SVCGRP_COMMUNITY] = Collections.EMPTY_MAP;
comm_index_to_service = Collections.EMPTY_MAP; index_to_service[SVCGRP_COMMUNITY] = Collections.EMPTY_MAP;
} // end else } // end else
symbol_to_service[SVCGRP_USER] = Collections.EMPTY_MAP;
index_to_service[SVCGRP_USER] = Collections.EMPTY_MAP;
for (i=0; i<NUM_SVCGRPS; i++)
{ // blank out all our cache arrays
list_all_cache[i] = null;
list_default_cache[i] = null;
} // end for
} // end constructor } // end constructor
/*-------------------------------------------------------------------------------- /*--------------------------------------------------------------------------------
@ -114,31 +159,158 @@ class ServiceControlManager
*-------------------------------------------------------------------------------- *--------------------------------------------------------------------------------
*/ */
private CommService initCommunityService(Element root, SecurityMonitor sm) throws ConfigException private static final ServiceToken newToken(int group, Element service) throws ConfigException
{ {
XMLLoader loader = XMLLoader.get();
// Load the symbol and index from the root element.
String symbol = loader.configGetAttribute(service,"id");
int index = loader.configGetAttributeInt(service,"index");
return new MyServiceToken(group,symbol,index);
} // end newToken
private final CommService initCommunityService(Element root, SecurityMonitor sm) throws ConfigException
{
ServiceToken token = newToken(SVCGRP_COMMUNITY,root);
CommService svc; CommService svc;
// FUTURE: do a create of a specific class // FUTURE: do a create of a specific class
svc = new StaticCommService(); svc = new StaticCommService();
svc.initialize(root,sm,new MyCommServiceSite()); svc.initialize(token,root,sm,new MyCommServiceSite());
return svc; return svc;
} // end initCommunityService } // end initCommunityService
private final synchronized Set listServices(int group, ServicePredicate predicate)
{
HashSet tmp = new HashSet();
Iterator it = symbol_to_service[group].values().iterator();
while (it.hasNext())
{ // get each service in turn
Service svc = (Service)(it.next());
if (predicate.test(svc))
tmp.add(svc.getToken());
} // end while
if (tmp.isEmpty())
return Collections.EMPTY_SET;
else
return Collections.unmodifiableSet(tmp);
} // end listCommunities
/*--------------------------------------------------------------------------------
* Implementations from interface ServiceControl
*--------------------------------------------------------------------------------
*/
public Set getAllServices(int group)
{
if ((group<0) || (group>=NUM_SVCGRPS))
throw new IndexOutOfBoundsException("group index not valid");
synchronized (this)
{ // extract the reference
Set rc = null;
if (list_all_cache[group]!=null)
rc = (Set)(list_all_cache[group].get());
if (rc==null)
{ // need to regenerate the set
rc = listServices(group,new ServicePredicate(){
public final boolean test(Service svc) { return true; }
});
// cache the result
list_all_cache[group] = new SoftReference(rc);
} // end if
return rc;
} // end synchronized block
} // end getAllServices
public Set getDefaultServices(int group)
{
if ((group<0) || (group>=NUM_SVCGRPS))
throw new IndexOutOfBoundsException("group index not valid");
synchronized (this)
{ // extract the reference
Set rc = null;
if (list_default_cache[group]!=null)
rc = (Set)(list_default_cache[group].get());
if (rc==null)
{ // need to regenerate the set
rc = listServices(group,new ServicePredicate(){
public final boolean test(Service svc) { return svc.isDefault(); }
});
// cache the result
list_default_cache[group] = new SoftReference(rc);
} // end if
return rc;
} // end synchronized block
} // end getDefaultServices
public Service getServiceForSymbol(int group, String sym)
{
if ((group<0) || (group>=NUM_SVCGRPS))
throw new IndexOutOfBoundsException("group index not valid");
return (Service)(symbol_to_service[group].get(sym));
} // end getServiceForSymbol
public Service getServiceForToken(ServiceToken token)
{
return this.getServiceForSymbol(token.getGroup(),token.getSymbol());
} // end getServiceForToken
public ServiceToken getTokenForIndex(int group, int ndx)
{
if ((group<0) || (group>=NUM_SVCGRPS))
throw new IndexOutOfBoundsException("group index not valid");
Service svc = (Service)(index_to_service[group].get(new Integer(ndx)));
return ((svc==null) ? null : svc.getToken());
} // end getTokenForIndex
public ServiceToken getTokenForSymbol(int group, String sym)
{
Service svc = this.getServiceForSymbol(group,sym);
return ((svc==null) ? null : svc.getToken());
} // end getTokenForSymbol
/*-------------------------------------------------------------------------------- /*--------------------------------------------------------------------------------
* External operations * External operations
*-------------------------------------------------------------------------------- *--------------------------------------------------------------------------------
*/ */
public final void shutdown() public final synchronized void shutdown()
{ {
Iterator it = comm_symbol_to_service.values().iterator(); for (int i=0; i<NUM_SVCGRPS; i++)
while (it.hasNext()) { // shutdown all three lists of services
{ // shut down each service in turn Iterator it = symbol_to_service[i].values().iterator();
CommService svc = (CommService)(it.next()); while (it.hasNext())
svc.shutdown(); { // shut down each service in turn
Service svc = (Service)(it.next());
svc.shutdown();
} // end while } // end while
symbol_to_service[i] = Collections.EMPTY_MAP;
} // end for
} // end shutdown } // end shutdown
} // end class ServiceControlManager } // end class ServiceControlManager

View File

@ -19,10 +19,10 @@ package com.silverwrist.venice.core.impl;
import org.w3c.dom.*; import org.w3c.dom.*;
import com.silverwrist.util.*; import com.silverwrist.util.*;
import com.silverwrist.venice.core.ServiceToken;
import com.silverwrist.venice.except.*; import com.silverwrist.venice.except.*;
import com.silverwrist.venice.security.*; import com.silverwrist.venice.security.*;
import com.silverwrist.venice.svc.*; import com.silverwrist.venice.svc.*;
import com.silverwrist.venice.util.XMLLoader;
class StaticCommService implements CommService class StaticCommService implements CommService
{ {
@ -31,8 +31,7 @@ class StaticCommService implements CommService
*-------------------------------------------------------------------------------- *--------------------------------------------------------------------------------
*/ */
private String symbol; private ServiceToken token;
private int index;
private boolean is_default; private boolean is_default;
private boolean is_locked; private boolean is_locked;
private SecurityMonitor secmon; private SecurityMonitor secmon;
@ -45,21 +44,45 @@ class StaticCommService implements CommService
*/ */
public StaticCommService() public StaticCommService()
{ { // do nothing
} // end constructor } // end constructor
/*--------------------------------------------------------------------------------
* Implementations from interface Service
*--------------------------------------------------------------------------------
*/
public void shutdown()
{ // do nothing
} // end shutdown
public ServiceToken getToken()
{
return token;
} // end getToken
public boolean isDefault()
{
return is_default;
} // end isDefault
public boolean isLocked()
{
return is_locked;
} // end isLocked
/*-------------------------------------------------------------------------------- /*--------------------------------------------------------------------------------
* Implementations from interface CommunityService * Implementations from interface CommunityService
*-------------------------------------------------------------------------------- *--------------------------------------------------------------------------------
*/ */
public void initialize(Element root, SecurityMonitor sm, CommServiceSite site) throws ConfigException public void initialize(ServiceToken token, Element root, SecurityMonitor sm, CommServiceSite site)
throws ConfigException
{ {
XMLLoader loader = XMLLoader.get(); this.token = token;
// Load the symbol and index from the root element.
symbol = loader.configGetAttribute(root,"id");
index = loader.configGetAttributeInt(root,"index");
// Get the setup from the subelement. // Get the setup from the subelement.
DOMElementHelper h = new DOMElementHelper(root); DOMElementHelper h = new DOMElementHelper(root);
@ -116,20 +139,16 @@ class StaticCommService implements CommService
} // end initialize } // end initialize
public void shutdown() public String getPermission()
{ // do nothing
} // end shutdown
public String getSymbol()
{ {
return symbol; return permission;
} // end getSymbol } // end getPermission
public int getIndex() public Role getRole()
{ {
return index; return role;
} // end getIndex } // end getRole
} // end class StaticCommService } // end class StaticCommService

View File

@ -37,100 +37,6 @@ import com.silverwrist.venice.util.XMLLoader;
public class VeniceEngineImpl implements VeniceEngine, EngineBackend public class VeniceEngineImpl implements VeniceEngine, EngineBackend
{ {
/*--------------------------------------------------------------------------------
* Internal class storing feature information.
*--------------------------------------------------------------------------------
*/
class VeniceFeatureDef implements CommunityFeature
{
int code;
String symbol;
String name;
String applet;
boolean is_default;
boolean is_locked;
boolean is_hidden;
boolean requires_read;
int sequence;
int min_level;
VeniceFeatureDef(int code, ResultSet rs) throws SQLException
{
this.code = code;
this.is_default = rs.getBoolean("is_default");
this.is_locked = rs.getBoolean("is_locked");
this.is_hidden = rs.getBoolean("is_hidden");
this.requires_read = rs.getBoolean("require_read");
this.sequence = rs.getInt("sequence");
this.min_level = rs.getInt("min_level");
this.symbol = rs.getString("symbol");
this.name = rs.getString("name");
this.applet = rs.getString("applet");
} // end constructor
public int getFeatureCode()
{
return code;
} // end getFeatureCode
public String getSymbol()
{
return symbol;
} // end getSymbol
public String getName()
{
return name;
} // end getName
public String getApplet()
{
return applet;
} // end getApplet
public int getSequence()
{
return sequence;
} // end getSequence
boolean featureAllowed(int level, boolean has_read)
{
if (level<min_level)
return false;
if (requires_read)
return has_read;
else
return true;
} // end featureAllowed
boolean isVisible()
{
return !is_hidden;
} // end isVisible
boolean isLocked()
{
return is_locked;
} // end isLocked
boolean isDefault()
{
return is_default;
} // end isDefault
} // end class VeniceFeatureDef
/*-------------------------------------------------------------------------------- /*--------------------------------------------------------------------------------
* Internal class storing side box information. * Internal class storing side box information.
*-------------------------------------------------------------------------------- *--------------------------------------------------------------------------------
@ -347,8 +253,6 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend
private javax.mail.Session mailsession = null; // email session object private javax.mail.Session mailsession = null; // email session object
private StockMessages stock_messages = null; // stock messages holder private StockMessages stock_messages = null; // stock messages holder
private ObjectCache comm_objcache = new ObjectCache(new CommunityCoreDataCreator()); private ObjectCache comm_objcache = new ObjectCache(new CommunityCoreDataCreator());
private VeniceFeatureDef[] features; // master feature table
private Hashtable feature_syms = new Hashtable(); // hashtable mapping symbols to features
private ObjectCache conf_objcache = new ObjectCache(new ConferenceCoreDataCreator()); private ObjectCache conf_objcache = new ObjectCache(new ConferenceCoreDataCreator());
private HTMLCheckerConfig[] html_configs; // holder for HTML checker configurations private HTMLCheckerConfig[] html_configs; // holder for HTML checker configurations
private int[] gp_ints; // global integer parameters private int[] gp_ints; // global integer parameters
@ -760,8 +664,7 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend
// Now done with the sidebox config... // Now done with the sidebox config...
// Load the services config file. // Load the services config file.
subdoc = loader.loadConfigDocument(services_config); subdoc = loader.loadConfigDocument(services_config);
// TODO: following needs to use the sm_env scmgr = new ServiceControlManager(subdoc,sm_env);
scmgr = new ServiceControlManager(subdoc,global_security,community_security);
} // end try } // end try
catch (ConfigException ce) catch (ConfigException ce)
@ -773,7 +676,7 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend
} // end catch } // end catch
// Initialize the environment. // Initialize the environment.
env = new EnvEngine(this,datapool); env = new EnvEngine(this,datapool,scmgr);
for (i=0; i<sideboxes.length; i++) // insert sideboxes into hashtable for (i=0; i<sideboxes.length; i++) // insert sideboxes into hashtable
sidebox_ids.put(new Integer(sideboxes[i].getID()),sideboxes[i]); sidebox_ids.put(new Integer(sideboxes[i].getID()),sideboxes[i]);
@ -786,26 +689,7 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend
try try
{ // get a connection from the data pool { // get a connection from the data pool
conn = env.getConnection(); conn = env.getConnection();
// load the master feature table
Statement stmt = conn.createStatement(); Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM refsigftr ORDER BY ftr_code;");
VeniceFeatureDef[] tmp_array = new VeniceFeatureDef[64];
int max_value = -1;
while (rs.next())
{ // store the values as we get them
int ndx = rs.getInt("ftr_code");
tmp_array[ndx] = new VeniceFeatureDef(ndx,rs);
if (ndx>max_value)
max_value = ndx;
} // end while
// store the real feature table as an array
features = new VeniceFeatureDef[++max_value];
System.arraycopy(tmp_array,0,features,0,max_value);
if (logger.isDebugEnabled())
logger.debug(max_value + " features loaded from database");
// load the global defaults // load the global defaults
loadDefaults(stmt); loadDefaults(stmt);
@ -823,9 +707,6 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend
} // end finally } // end finally
for (i=0; i<features.length; i++) // insert feature symbols into hashtable
feature_syms.put(features[i].getSymbol(),features[i]);
// Here is where we create the HTML Checker and all the goodies it relies on. // Here is where we create the HTML Checker and all the goodies it relies on.
// Start by creating some of the subsidiary objects that get added to HTML Checker configs. // Start by creating some of the subsidiary objects that get added to HTML Checker configs.
EmailRewriter email_rewriter = new EmailRewriter(); EmailRewriter email_rewriter = new EmailRewriter();
@ -920,25 +801,6 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend
} // end shutdown } // end shutdown
public int getNumFeatures()
{
checkInitialized();
return features.length;
} // end getNumFeatures
public BitSet getAllFeaturesMask()
{
checkInitialized();
BitSet rc = new BitSet();
for (int i=0; i<features.length; i++)
if (features[i].isVisible())
rc.set(i);
return rc;
} // end getAllFeaturesMask
public UserContext createUserContext(String remote_addr) throws DataException public UserContext createUserContext(String remote_addr) throws DataException
{ {
checkInitialized(); checkInitialized();
@ -1825,84 +1687,6 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend
} // end detachCommunityDataObject } // end detachCommunityDataObject
public BitSet getLockedFeaturesMask()
{
checkInitialized();
BitSet rc = new BitSet();
for (int i=0; i<features.length; i++)
if (features[i].isLocked())
rc.set(i);
return rc;
} // end getLockedFeaturesMask
public List getCommunityFeatureSet(BitSet enabled_features, int level, boolean read_privs)
{
checkInitialized();
ArrayList rc = new ArrayList();
for (int i=0; i<features.length; i++)
if (enabled_features.get(i) && features[i].featureAllowed(level,read_privs))
{ // this feature must be included in the eventual output set
CommunityFeature elt = features[i];
boolean insert_me = true;
for (int j=0; insert_me && (j<rc.size()); j++)
if (elt.getSequence()<((CommunityFeature)(rc.get(j))).getSequence())
{ // put the item in the list
rc.add(j,elt);
insert_me = false;
} // end if and for
if (insert_me) // insert at end by default
rc.add(elt);
} // end if and for
if (logger.isDebugEnabled())
logger.debug("getCommunityFeatureSet() loaded " + rc.size() + " elements");
return Collections.unmodifiableList(rc); // wrap the vector for return
} // end getCommunityFeatureSet
public String getAppletForFeature(int code)
{
checkInitialized();
if ((code<0) || (code>=features.length))
{ // the index is out of bounds!
logger.error("getAppletForFeature(" + code + ") => out of range");
throw new IndexOutOfBoundsException("invalid feature code");
} // end if
String rc = features[code].getApplet();
if (logger.isDebugEnabled())
logger.debug("getAppletForFeature(" + code + ") => \"" + rc + "\"");
return rc;
} // end getAppletForFeature
public boolean isValidInitialFeatureIndex(short ndx)
{
if ((ndx<0) || (ndx>=features.length))
return false;
return features[ndx].isVisible();
} // end isValidInitialFeatureIndex
public BitSet getDefaultFeaturesMask()
{
checkInitialized();
BitSet rc = new BitSet();
for (int i=0; i<features.length; i++)
if (features[i].isDefault())
rc.set(i);
return rc;
} // end getDefaultFeaturesMask
public void registerNewCommunity(CommunityData comm) public void registerNewCommunity(CommunityData comm)
{ {
checkInitialized(); checkInitialized();
@ -1913,26 +1697,6 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend
} // end registerNewCommunity } // end registerNewCommunity
public int getFeatureIndexBySymbol(String symbol)
{
VeniceFeatureDef fd = (VeniceFeatureDef)(feature_syms.get(symbol));
if (fd!=null)
return fd.getFeatureCode();
else
return -1;
} // end getFeatureIndexBySymbol
public boolean canAccessFeature(String symbol, int level, boolean has_read)
{
VeniceFeatureDef fd = (VeniceFeatureDef)(feature_syms.get(symbol));
if (fd!=null)
return fd.featureAllowed(level,has_read);
else
return false;
} // end canAccessFeature
public ConferenceData getConferenceDataObject(int confid) throws DataException public ConferenceData getConferenceDataObject(int confid) throws DataException
{ {
checkInitialized(); checkInitialized();

View File

@ -20,8 +20,10 @@ package com.silverwrist.venice.core.internals;
import java.util.BitSet; import java.util.BitSet;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Set;
import com.silverwrist.venice.core.CommunityProperties; import com.silverwrist.venice.core.CommunityProperties;
import com.silverwrist.venice.core.ContactInfo; import com.silverwrist.venice.core.ContactInfo;
import com.silverwrist.venice.core.ServiceToken;
import com.silverwrist.venice.except.AccessError; import com.silverwrist.venice.except.AccessError;
import com.silverwrist.venice.except.DataException; import com.silverwrist.venice.except.DataException;
@ -69,13 +71,12 @@ public interface CommunityData
public abstract void putContactInfo(EnvCommunity outer, ContactInfo ci) throws DataException; public abstract void putContactInfo(EnvCommunity outer, ContactInfo ci) throws DataException;
public abstract BitSet getFeatureSet(); public abstract Set getServices();
public abstract void putFeatureSet(EnvCommunity outer, BitSet set) throws DataException; public abstract Set getServices(EnvCommunity outer);
public abstract List getCommunityFeaturesList(int level); public abstract void setServiceEnable(EnvCommunity outer, ServiceToken token, boolean enable)
throws DataException;
public abstract String getDefaultApplet();
public abstract void setName(EnvCommunity outer, String name) throws DataException; public abstract void setName(EnvCommunity outer, String name) throws DataException;
@ -102,9 +103,9 @@ public interface CommunityData
public abstract void setMembersOnly(EnvCommunity outer, boolean flag) throws DataException; public abstract void setMembersOnly(EnvCommunity outer, boolean flag) throws DataException;
public abstract short getInitialFeatureIndex(); public abstract ServiceToken getDefaultService();
public abstract void setInitialFeatureIndex(short ndx) throws DataException; public abstract void setDefaultService(ServiceToken token) throws DataException;
public abstract String getJoinKey() throws DataException; public abstract String getJoinKey() throws DataException;
@ -130,7 +131,7 @@ public interface CommunityData
public abstract int getMemberCount(boolean include_hidden) throws DataException; public abstract int getMemberCount(boolean include_hidden) throws DataException;
public abstract boolean isFeaturePresent(String symbol); public abstract boolean hasService(ServiceToken token);
public abstract ConferenceCommunityContext getConferenceDataObject(int confid) throws DataException; public abstract ConferenceCommunityContext getConferenceDataObject(int confid) throws DataException;

View File

@ -71,22 +71,8 @@ public interface EngineBackend
public abstract void detachCommunityDataObject(int cid); public abstract void detachCommunityDataObject(int cid);
public abstract BitSet getLockedFeaturesMask();
public abstract List getCommunityFeatureSet(BitSet enabled_features, int level, boolean read_privs);
public abstract String getAppletForFeature(int code);
public abstract boolean isValidInitialFeatureIndex(short ndx);
public abstract BitSet getDefaultFeaturesMask();
public abstract void registerNewCommunity(CommunityData comm); public abstract void registerNewCommunity(CommunityData comm);
public abstract int getFeatureIndexBySymbol(String symbol);
public abstract boolean canAccessFeature(String symbol, int level, boolean has_read);
public abstract ConferenceData getConferenceDataObject(int confid) throws DataException; public abstract ConferenceData getConferenceDataObject(int confid) throws DataException;
public abstract void detachConferenceDataObject(int confid); public abstract void detachConferenceDataObject(int confid);

View File

@ -136,6 +136,12 @@ public class EnvCommunity extends EnvUser
} // end testPermission } // end testPermission
public boolean satisfy(Role role)
{
return role.isSatisfiedBy(comm.realCommunityLevel());
} // end satisfy
public boolean testPermission(String symbol) public boolean testPermission(String symbol)
{ {
if ( symbol.equals(PERM_READ) || symbol.equals(PERM_WRITE) || symbol.equals(PERM_CREATE) if ( symbol.equals(PERM_READ) || symbol.equals(PERM_WRITE) || symbol.equals(PERM_CREATE)

View File

@ -18,6 +18,7 @@
package com.silverwrist.venice.core.internals; package com.silverwrist.venice.core.internals;
import com.silverwrist.venice.except.AccessError; import com.silverwrist.venice.except.AccessError;
import com.silverwrist.venice.security.Role;
import com.silverwrist.venice.security.SecurityMonitor; import com.silverwrist.venice.security.SecurityMonitor;
public class EnvConference extends EnvCommunity public class EnvConference extends EnvCommunity
@ -92,6 +93,12 @@ public class EnvConference extends EnvCommunity
} // end testPermission } // end testPermission
public boolean satisfy(Role role)
{
return role.isSatisfiedBy(conf.env_getConfLevel());
} // end satisfy
/*-------------------------------------------------------------------------------- /*--------------------------------------------------------------------------------
* External operations * External operations
*-------------------------------------------------------------------------------- *--------------------------------------------------------------------------------

View File

@ -24,6 +24,7 @@ import com.silverwrist.venice.core.SecurityInfo;
import com.silverwrist.venice.db.*; import com.silverwrist.venice.db.*;
import com.silverwrist.venice.except.AccessError; import com.silverwrist.venice.except.AccessError;
import com.silverwrist.venice.security.*; import com.silverwrist.venice.security.*;
import com.silverwrist.venice.svc.ServiceControl;
public class EnvEngine public class EnvEngine
{ {
@ -34,16 +35,18 @@ public class EnvEngine
private EngineBackend engine; // the engine private EngineBackend engine; // the engine
private DataPool datapool; // the database pool private DataPool datapool; // the database pool
private ServiceControl scon; // the service controller
/*-------------------------------------------------------------------------------- /*--------------------------------------------------------------------------------
* Constructors * Constructors
*-------------------------------------------------------------------------------- *--------------------------------------------------------------------------------
*/ */
public EnvEngine(EngineBackend engine, DataPool datapool) public EnvEngine(EngineBackend engine, DataPool datapool, ServiceControl scon)
{ {
this.engine = engine; this.engine = engine;
this.datapool = datapool; this.datapool = datapool;
this.scon = scon;
} // end constructor } // end constructor
@ -51,6 +54,7 @@ public class EnvEngine
{ {
this.engine = other.engine; this.engine = other.engine;
this.datapool = other.datapool; this.datapool = other.datapool;
this.scon = other.scon;
} // end constructor } // end constructor
@ -82,6 +86,12 @@ public class EnvEngine
} // end getDataPool } // end getDataPool
public final ServiceControl getSCM()
{
return scon;
} // end getSCM
public final Connection getConnection() throws SQLException public final Connection getConnection() throws SQLException
{ {
return datapool.getConnection(); return datapool.getConnection();

View File

@ -73,15 +73,45 @@ public class EnvUser extends EnvEngine
} // end constructor } // end constructor
/*-------------------------------------------------------------------------------- /*--------------------------------------------------------------------------------
* Overrides from class EnvEngine * Internal operations
*-------------------------------------------------------------------------------- *--------------------------------------------------------------------------------
*/ */
protected SecurityMonitor getStaticMonitor() protected boolean testPermissionDynamic(String symbol, String errormsg) throws AccessError
{ {
return sm; if (symbol.equals(PERM_CREATECOMMUNITY))
{ // the Create Community permission test
Role r = getEngine().getParamRole(EngineBackend.ROLEP_CREATECOMMUNITY);
if (r.isSatisfiedBy(user.realBaseLevel()))
return true;
logger.error("testPermission() fail for permission " + PERM_CREATECOMMUNITY);
if (errormsg==null)
errormsg = "You are not authorized to create new communities.";
throw new AccessError(errormsg);
} // end getStaticMonitor } // end if
return false;
} // end testPermission
protected boolean testPermissionDynamic(String symbol)
{
if (symbol.equals(PERM_CREATECOMMUNITY))
{ // do the "Create Community" test here
Role r = getEngine().getParamRole(EngineBackend.ROLEP_CREATECOMMUNITY);
return r.isSatisfiedBy(user.realBaseLevel());
} // end if
return false;
} // end testPermission
protected int levelSelf()
{
return user.realBaseLevel();
}
/*-------------------------------------------------------------------------------- /*--------------------------------------------------------------------------------
* External operations * External operations
@ -120,6 +150,8 @@ public class EnvUser extends EnvEngine
public boolean testPermission(String symbol, String errormsg) throws AccessError public boolean testPermission(String symbol, String errormsg) throws AccessError
{ {
if (testPermissionDynamic(symbol,errormsg))
return true;
if (symbol.equals(PERM_CREATECOMMUNITY)) if (symbol.equals(PERM_CREATECOMMUNITY))
{ // the Create Community permission test { // the Create Community permission test
Role r = getEngine().getParamRole(EngineBackend.ROLEP_CREATECOMMUNITY); Role r = getEngine().getParamRole(EngineBackend.ROLEP_CREATECOMMUNITY);
@ -149,6 +181,12 @@ public class EnvUser extends EnvEngine
} // end testPermission } // end testPermission
public boolean satisfy(Role role)
{
return role.isSatisfiedBy(user.realBaseLevel());
} // end satisfy
public final UserBackend getUser() public final UserBackend getUser()
{ {
return user; return user;

View File

@ -20,12 +20,20 @@ package com.silverwrist.venice.servlets;
import java.io.*; import java.io.*;
import javax.servlet.*; import javax.servlet.*;
import javax.servlet.http.*; import javax.servlet.http.*;
import org.apache.log4j.*;
import com.silverwrist.venice.core.*; import com.silverwrist.venice.core.*;
import com.silverwrist.venice.except.*; import com.silverwrist.venice.except.*;
import com.silverwrist.venice.servlets.format.*; import com.silverwrist.venice.servlets.format.*;
public class CommunityFrontEnd extends VeniceServlet public class CommunityFrontEnd extends VeniceServlet
{ {
/*--------------------------------------------------------------------------------
* Static data members
*--------------------------------------------------------------------------------
*/
private static Category logger = Category.getInstance(CommunityFrontEnd.class);
/*-------------------------------------------------------------------------------- /*--------------------------------------------------------------------------------
* Overrides from class HttpServlet * Overrides from class HttpServlet
*-------------------------------------------------------------------------------- *--------------------------------------------------------------------------------
@ -56,7 +64,9 @@ public class CommunityFrontEnd extends VeniceServlet
CommunityContext comm = user.getCommunityContext(alias); CommunityContext comm = user.getCommunityContext(alias);
// get the default servlet from the community context // get the default servlet from the community context
String def_servlet = comm.getDefaultApplet(); String def_servlet = rdat.getDefaultServletAddress(comm);
if (logger.isDebugEnabled())
logger.debug("CommunityFrontEnd bouncing to: " + def_servlet);
if (def_servlet==null) if (def_servlet==null)
{ // return the default servlet { // return the default servlet
changeMenuTop(request); changeMenuTop(request);
@ -65,7 +75,7 @@ public class CommunityFrontEnd extends VeniceServlet
} // end if } // end if
// and go there // and go there
throw new RedirectResult(def_servlet); throw new RedirectResult(def_servlet,true);
} // end try } // end try
catch (DataException de) catch (DataException de)

View File

@ -35,6 +35,7 @@ public class RedirectResult extends ExecuteResult
*/ */
private String target; private String target;
private boolean absolute;
/*-------------------------------------------------------------------------------- /*--------------------------------------------------------------------------------
* Constructor * Constructor
@ -45,6 +46,15 @@ public class RedirectResult extends ExecuteResult
{ {
super(); super();
this.target = target; this.target = target;
this.absolute = false;
} // end constructor
public RedirectResult(String target, boolean absolute)
{
super();
this.target = target;
this.absolute = absolute;
} // end constructor } // end constructor
@ -55,6 +65,13 @@ public class RedirectResult extends ExecuteResult
public void execute(RenderData rdat) throws IOException public void execute(RenderData rdat) throws IOException
{ {
if (absolute)
{ // allow us to explicitly specify absolute redirection
rdat.redirectAbsolute(target);
return;
} // end if
for (int i=0; i<absolute_prefixes.length; i++) for (int i=0; i<absolute_prefixes.length; i++)
if (target.startsWith(absolute_prefixes[i])) if (target.startsWith(absolute_prefixes[i]))
{ // this is an absolute redirection...do it! { // this is an absolute redirection...do it!

View File

@ -579,6 +579,12 @@ public class RenderConfig implements ColorSelectors
} // end createCommunityMenu } // end createCommunityMenu
String getDefaultServletAddress(RenderData rdat, CommunityContext comm)
{
return comm_menu_fact.getDefaultServletAddress(rdat,comm);
} // end getDefaultServletAddress
/*-------------------------------------------------------------------------------- /*--------------------------------------------------------------------------------
* Static operations for use by VeniceServlet * Static operations for use by VeniceServlet
*-------------------------------------------------------------------------------- *--------------------------------------------------------------------------------

View File

@ -25,6 +25,7 @@ import javax.servlet.http.*;
import org.apache.log4j.*; import org.apache.log4j.*;
import com.silverwrist.util.IOUtil; import com.silverwrist.util.IOUtil;
import com.silverwrist.util.StringUtil; import com.silverwrist.util.StringUtil;
import com.silverwrist.venice.core.CommunityContext;
import com.silverwrist.venice.core.IDUtils; import com.silverwrist.venice.core.IDUtils;
import com.silverwrist.venice.core.UserContext; import com.silverwrist.venice.core.UserContext;
import com.silverwrist.venice.core.VeniceEngine; import com.silverwrist.venice.core.VeniceEngine;
@ -334,6 +335,12 @@ public class RenderData implements ColorSelectors
} // end getPhotoNotAvailURL } // end getPhotoNotAvailURL
public String getDefaultServletAddress(CommunityContext comm)
{
return rconf.getDefaultServletAddress(this,comm);
} // end getDefaultServletAddress
public String formatDateForDisplay(Date date) public String formatDateForDisplay(Date date)
{ {
if (display_date==null) if (display_date==null)

View File

@ -23,6 +23,7 @@ import javax.servlet.*;
import javax.servlet.http.*; import javax.servlet.http.*;
import com.silverwrist.venice.core.*; import com.silverwrist.venice.core.*;
import com.silverwrist.venice.except.*; import com.silverwrist.venice.except.*;
import com.silverwrist.venice.security.Role;
public class ViewCommunityMembers implements JSPRender, SearchMode public class ViewCommunityMembers implements JSPRender, SearchMode
{ {
@ -329,4 +330,12 @@ public class ViewCommunityMembers implements JSPRender, SearchMode
} // end getItem } // end getItem
public boolean isCommunityAdmin(UserFound uf)
{
SecurityInfo sinf = comm.getSecurityInfo();
Role r = sinf.getRole("Community.Host");
return r.isSatisfiedBy(uf.getLevel());
} // end isCommunityAdmin
} // end class ViewCommunityMembers } // end class ViewCommunityMembers

View File

@ -20,6 +20,7 @@ package com.silverwrist.venice.servlets.format.menus;
import java.util.Map; import java.util.Map;
import org.w3c.dom.*; import org.w3c.dom.*;
import com.silverwrist.venice.except.*; import com.silverwrist.venice.except.*;
import com.silverwrist.venice.servlets.format.RenderData;
import com.silverwrist.venice.util.XMLLoader; import com.silverwrist.venice.util.XMLLoader;
class CommunityLeftMenuEntry implements Comparable class CommunityLeftMenuEntry implements Comparable
@ -114,4 +115,10 @@ class CommunityLeftMenuEntry implements Comparable
} // end resolveItem } // end resolveItem
final String getServletAddress(RenderData rdat, Map vars)
{
return item.getAddress(rdat,vars);
} // end getServletAddress
} // end class CommunityLeftMenuEntry } // end class CommunityLeftMenuEntry

View File

@ -21,6 +21,7 @@ import java.util.*;
import org.w3c.dom.*; import org.w3c.dom.*;
import com.silverwrist.venice.core.*; import com.silverwrist.venice.core.*;
import com.silverwrist.venice.except.*; import com.silverwrist.venice.except.*;
import com.silverwrist.venice.servlets.format.RenderData;
public class CommunityLeftMenuFactory public class CommunityLeftMenuFactory
{ {
@ -30,6 +31,7 @@ public class CommunityLeftMenuFactory
*/ */
private List entries; private List entries;
private Map map_symbol;
/*-------------------------------------------------------------------------------- /*--------------------------------------------------------------------------------
* Constructor * Constructor
@ -42,6 +44,7 @@ public class CommunityLeftMenuFactory
{ // look for community services { // look for community services
NodeList nl = comm_sect.getChildNodes(); NodeList nl = comm_sect.getChildNodes();
ArrayList tmp_entries = new ArrayList(nl.getLength()); ArrayList tmp_entries = new ArrayList(nl.getLength());
HashMap tmp_map = new HashMap();
for (int i=0; i<nl.getLength(); i++) for (int i=0; i<nl.getLength(); i++)
{ // get each node and see if it's a service node { // get each node and see if it's a service node
Node n = nl.item(i); Node n = nl.item(i);
@ -49,25 +52,35 @@ public class CommunityLeftMenuFactory
{ // create a template LeftMenuEntry and add it { // create a template LeftMenuEntry and add it
CommunityLeftMenuEntry ent = new CommunityLeftMenuEntry((Element)n); CommunityLeftMenuEntry ent = new CommunityLeftMenuEntry((Element)n);
tmp_entries.add(ent); tmp_entries.add(ent);
tmp_map.put(ent.getSymbol(),ent);
} // end if } // end if
} // end for } // end for
if (tmp_entries.isEmpty()) if (tmp_entries.isEmpty())
{ // dummy it all out
entries = Collections.EMPTY_LIST; entries = Collections.EMPTY_LIST;
map_symbol = Collections.EMPTY_MAP;
} // end if
else else
{ // sort the list by sequence before we save it { // sort the list by sequence before we save it
if (tmp_entries.size()>1) if (tmp_entries.size()>1)
Collections.sort(tmp_entries); Collections.sort(tmp_entries);
tmp_entries.trimToSize(); tmp_entries.trimToSize();
entries = Collections.unmodifiableList(tmp_entries); entries = Collections.unmodifiableList(tmp_entries);
map_symbol = Collections.unmodifiableMap(tmp_map);
} // end else } // end else
} // end if } // end if
else // no communty services - initialize to null else
{ // no communty services - initialize to null
entries = Collections.EMPTY_LIST; entries = Collections.EMPTY_LIST;
map_symbol = Collections.EMPTY_MAP;
} // end else
} // end constructor } // end constructor
@ -78,19 +91,15 @@ public class CommunityLeftMenuFactory
public CommunityLeftMenu createMenu(CommunityContext comm) public CommunityLeftMenu createMenu(CommunityContext comm)
{ {
// N.B. This implementation will change once the engine uses the SCM to return the defined
// community services.
List items; List items;
if (entries.size()>0) if (entries.size()>0)
{ // Get the community features list and stash the indexes in a set. { // Get the community services and stash the symbols in a set.
HashSet defined = new HashSet(); HashSet defined = new HashSet();
List ftr_list = comm.getCommunityFeaturesList(); Iterator it = comm.getServices().iterator();
Iterator it = ftr_list.iterator();
while (it.hasNext()) while (it.hasNext())
{ // add each index to the set { // add each symbol to the set
CommunityFeature ftr = (CommunityFeature)(it.next()); ServiceToken token = (ServiceToken)(it.next());
defined.add(new Integer(ftr.getFeatureCode())); defined.add(token.getSymbol());
} // end while } // end while
@ -104,7 +113,7 @@ public class CommunityLeftMenuFactory
while (it.hasNext()) while (it.hasNext())
{ // get this entry and see if there's a match in the set { // get this entry and see if there's a match in the set
CommunityLeftMenuEntry ntry = (CommunityLeftMenuEntry)(it.next()); CommunityLeftMenuEntry ntry = (CommunityLeftMenuEntry)(it.next());
if (defined.contains(new Integer(ntry.getIndex()))) if (defined.contains(ntry.getSymbol()))
tmp_items.add(ntry.resolveItem(vars)); tmp_items.add(ntry.resolveItem(vars));
} // end while } // end while
@ -127,4 +136,21 @@ public class CommunityLeftMenuFactory
} // end createMenu } // end createMenu
public String getDefaultServletAddress(RenderData rdat, CommunityContext comm)
{
ServiceToken token = comm.getDefaultService();
if (token==null)
return null;
CommunityLeftMenuEntry ent = (CommunityLeftMenuEntry)(map_symbol.get(token.getSymbol()));
if (ent==null)
return null;
// Create the map used to replace the variables in the servlet address.
HashMap vars = new HashMap();
vars.put("cid",String.valueOf(comm.getCommunityID()));
return ent.getServletAddress(rdat,vars);
} // end getDefaultServletAddress
} // end class CommunityLeftMenuFactory } // end class CommunityLeftMenuFactory

View File

@ -145,4 +145,23 @@ class LinkItem implements ComponentRender, ColorSelectors
} // end renderHere } // end renderHere
/*--------------------------------------------------------------------------------
* External operations
*--------------------------------------------------------------------------------
*/
final String getAddress(RenderData rdat, Map vars)
{
String s = StringUtil.replaceAllVariables(href,vars);
if (type.equals(ABSOLUTE))
return s;
else if (type.equals(SERVLET))
return rdat.getEncodedServletPath(s);
else if (type.equals(FRAME))
return rdat.getEncodedServletPath("frame/" + s);
else
return null;
} // end getAddress
} // end class LinkItem } // end class LinkItem

View File

@ -18,18 +18,18 @@
package com.silverwrist.venice.svc; package com.silverwrist.venice.svc;
import org.w3c.dom.Element; import org.w3c.dom.Element;
import com.silverwrist.venice.core.ServiceToken;
import com.silverwrist.venice.except.ConfigException; import com.silverwrist.venice.except.ConfigException;
import com.silverwrist.venice.security.Role;
import com.silverwrist.venice.security.SecurityMonitor; import com.silverwrist.venice.security.SecurityMonitor;
public interface CommService public interface CommService extends Service
{ {
public abstract void initialize(Element root, SecurityMonitor sm, CommServiceSite site) public abstract void initialize(ServiceToken token, Element root, SecurityMonitor sm, CommServiceSite site)
throws ConfigException; throws ConfigException;
public abstract void shutdown(); public abstract String getPermission();
public abstract String getSymbol(); public abstract Role getRole();
public abstract int getIndex();
} // end interface CommService } // end interface CommService

View File

@ -0,0 +1,32 @@
/*
* 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.svc;
import com.silverwrist.venice.core.ServiceToken;
public interface Service
{
public abstract void shutdown();
public abstract ServiceToken getToken();
public abstract boolean isDefault();
public abstract boolean isLocked();
} // end interface Service

View File

@ -0,0 +1,38 @@
/*
* 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.svc;
import java.util.Set;
import com.silverwrist.venice.core.ServiceGroup;
import com.silverwrist.venice.core.ServiceToken;
public interface ServiceControl extends ServiceGroup
{
public abstract Set getAllServices(int group);
public abstract Set getDefaultServices(int group);
public abstract Service getServiceForSymbol(int group, String sym);
public abstract Service getServiceForToken(ServiceToken token);
public abstract ServiceToken getTokenForIndex(int group, int ndx);
public abstract ServiceToken getTokenForSymbol(int group, String sym);
} // end interface ServiceControl

View File

@ -18,7 +18,6 @@
<%@ page import = "java.util.*" %> <%@ page import = "java.util.*" %>
<%@ page import = "com.silverwrist.util.StringUtil" %> <%@ page import = "com.silverwrist.util.StringUtil" %>
<%@ page import = "com.silverwrist.venice.core.*" %> <%@ page import = "com.silverwrist.venice.core.*" %>
<%@ page import = "com.silverwrist.venice.security.Capability" %>
<%@ page import = "com.silverwrist.venice.servlets.Variables" %> <%@ page import = "com.silverwrist.venice.servlets.Variables" %>
<%@ page import = "com.silverwrist.venice.servlets.format.*" %> <%@ page import = "com.silverwrist.venice.servlets.format.*" %>
<% <%
@ -129,7 +128,7 @@
<%= StringUtil.encodeHTML(uf.getGivenName()) %> <%= StringUtil.encodeHTML(uf.getFamilyName()) %>, <%= StringUtil.encodeHTML(uf.getGivenName()) %> <%= StringUtil.encodeHTML(uf.getFamilyName()) %>,
from <%= StringUtil.encodeHTML(uf.getLocality()) %>, <%= StringUtil.encodeHTML(uf.getRegion()) %> from <%= StringUtil.encodeHTML(uf.getLocality()) %>, <%= StringUtil.encodeHTML(uf.getRegion()) %>
<%= uf.getCountry() %> <%= uf.getCountry() %>
<% if (Capability.isCommunityAdmin(uf.getLevel())) { %> <% if (data.isCommunityAdmin(uf)) { %>
<IMG SRC="<%= rdat.getFullImagePath("tag_host.gif") %>" ALT="Host!" HSPACE=2 VSPACE=0 BORDER=0 <IMG SRC="<%= rdat.getFullImagePath("tag_host.gif") %>" ALT="Host!" HSPACE=2 VSPACE=0 BORDER=0
WIDTH=40 HEIGHT=20 ALIGN=BOTTOM> WIDTH=40 HEIGHT=20 ALIGN=BOTTOM>
<% } // end if %> <% } // end if %>