From 85518ca0d52f0412f8c78b83851f83a6601786af Mon Sep 17 00:00:00 2001 From: "Eric J. Bowersox" Date: Wed, 21 Nov 2001 20:22:47 +0000 Subject: [PATCH] Move to a slightly better implementation... --- .../venice/core/impl/VeniceEngineImpl.java | 7 +- .../security/StaticSecurityMonitor.java | 17 ++-- .../svc/SecurityMonitorEnvironment.java | 80 +++++++++++++++++++ 3 files changed, 92 insertions(+), 12 deletions(-) create mode 100644 src/com/silverwrist/venice/svc/SecurityMonitorEnvironment.java diff --git a/src/com/silverwrist/venice/core/impl/VeniceEngineImpl.java b/src/com/silverwrist/venice/core/impl/VeniceEngineImpl.java index a1189d7..5187b71 100644 --- a/src/com/silverwrist/venice/core/impl/VeniceEngineImpl.java +++ b/src/com/silverwrist/venice/core/impl/VeniceEngineImpl.java @@ -32,6 +32,7 @@ import com.silverwrist.venice.htmlcheck.*; import com.silverwrist.venice.htmlcheck.dict.*; import com.silverwrist.venice.htmlcheck.filters.*; import com.silverwrist.venice.security.*; +import com.silverwrist.venice.svc.*; import com.silverwrist.venice.util.XMLLoader; public class VeniceEngineImpl implements VeniceEngine, EngineBackend @@ -666,14 +667,14 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend sect = loader.configGetSubSection(root_h,"security"); // Load the security monitors. - HashMap known_monitors = new HashMap(); + SecurityMonitorEnvironment sm_env = new SecurityMonitorEnvironment(); NodeList nl = sect.getChildNodes(); for (i=0; iSecurityMonitor which is configured by means of XML data, supplied by means of a Venice @@ -110,12 +111,12 @@ public class StaticSecurityMonitor implements SecurityMonitor * * @param cfg The root element of the security monitor configuration, which must be a * <security-definition/> element. - * @param previous A mapping of all previously-known security monitors. This one will be added to - * it on success. + * @param env A mapping of all previously-known security monitors. This one will be added to + * it on success. * @exception com.silverwrist.venice.except.ConfigException The XML configuration data was incorrect in * some fashion. */ - public StaticSecurityMonitor(Element cfg, Map previous) throws ConfigException + public StaticSecurityMonitor(Element cfg, SecurityMonitorEnvironment env) throws ConfigException { boolean set_root_monitor = false; @@ -139,7 +140,7 @@ public class StaticSecurityMonitor implements SecurityMonitor if (logger.isDebugEnabled()) logger.debug("defining new StaticSecurityMonitor with id=" + id); - if (previous.containsKey(id)) + if (env.isMonitorDefined(id)) { // the monitor with this ID has already been defined! logger.fatal("security monitor with id=" + id + " is already defined!"); throw new ConfigException("security monitor id=" + id + " is already defined!"); @@ -149,7 +150,7 @@ public class StaticSecurityMonitor implements SecurityMonitor if (root_h.hasAttribute("parent")) { // find our parent String parent_id = cfg.getAttribute("parent"); - parent = (SecurityMonitor)(previous.get(parent_id)); + parent = env.getMonitor(parent_id); if (parent==null) { // no parent! that's bogus! logger.fatal("parent security monitor with id=" + parent_id + " does not exist!"); @@ -193,7 +194,7 @@ public class StaticSecurityMonitor implements SecurityMonitor } // end if else { // this must be the root security monitor! - if (root_monitor!=null) + if (env.isRootMonitorDefined()) { // but we already have a root - can't be two roots! logger.fatal("trying to define root security monitor but we already have one"); throw new ConfigException("root security monitor is already defined!"); @@ -345,9 +346,7 @@ public class StaticSecurityMonitor implements SecurityMonitor dynamic_permissions = Collections.EMPTY_SET; // Finish up by adding ourselves to the known monitors list. - previous.put(id,this); - if (set_root_monitor) - root_monitor = this; + env.storeMonitor(this,set_root_monitor); } // end constructor diff --git a/src/com/silverwrist/venice/svc/SecurityMonitorEnvironment.java b/src/com/silverwrist/venice/svc/SecurityMonitorEnvironment.java new file mode 100644 index 0000000..d61f0e6 --- /dev/null +++ b/src/com/silverwrist/venice/svc/SecurityMonitorEnvironment.java @@ -0,0 +1,80 @@ +/* + * 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 . + * + * 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 , + * 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.*; +import com.silverwrist.venice.security.SecurityMonitor; + +public final class SecurityMonitorEnvironment +{ + /*-------------------------------------------------------------------------------- + * Attributes + *-------------------------------------------------------------------------------- + */ + + private HashMap map = new HashMap(); + private SecurityMonitor root = null; + + /*-------------------------------------------------------------------------------- + * Constructor + *-------------------------------------------------------------------------------- + */ + + public SecurityMonitorEnvironment() + { // do nothing + } // end constructor + + /*-------------------------------------------------------------------------------- + * External operations + *-------------------------------------------------------------------------------- + */ + + public final boolean isMonitorDefined(String id) + { + return map.containsKey(id); + + } // end isMonitorDefined + + public final boolean isRootMonitorDefined() + { + return (root!=null); + + } // end isRootMonitorDefined + + public final SecurityMonitor getMonitor(String id) + { + return (SecurityMonitor)(map.get(id)); + + } // end getMonitor + + public final void storeMonitor(SecurityMonitor sm, boolean set_root) + { + if (map.put(sm.getID(),sm)!=null) + throw new RuntimeException("SecurityMonitorEnvironment: double monitor defininition!"); + if (set_root) + { // set the root monitor as well + if (root==null) + root = sm; + else + throw new RuntimeException("SecurityMonitorEnvironment: double root definition!"); + + } // end if + + } // end storeMonitor + +} // end class SecurityMonitorEnvironment