Move to a slightly better implementation...
This commit is contained in:
parent
8fe7abdf60
commit
85518ca0d5
|
@ -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; i<nl.getLength(); i++)
|
||||
{ // scan through and find security monitors to initialize
|
||||
Node n = nl.item(i);
|
||||
if ((n.getNodeType()==Node.ELEMENT_NODE) && (n.getNodeName().equals("security-definition")))
|
||||
{ // load one of the initial security definitions
|
||||
SecurityMonitor sm = new StaticSecurityMonitor((Element)n,known_monitors);
|
||||
SecurityMonitor sm = new StaticSecurityMonitor((Element)n,sm_env);
|
||||
if (sm.getID().equals("Global"))
|
||||
global_security = sm;
|
||||
else if (sm.getID().equals("Community"))
|
||||
|
@ -759,7 +760,7 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend
|
|||
// Now done with the sidebox config...
|
||||
// Load the services config file.
|
||||
subdoc = loader.loadConfigDocument(services_config);
|
||||
// TODO: following needs to use the known_monitors mapping
|
||||
// TODO: following needs to use the sm_env
|
||||
scmgr = new ServiceControlManager(subdoc,global_security,community_security);
|
||||
|
||||
} // end try
|
||||
|
|
|
@ -23,6 +23,7 @@ import org.w3c.dom.*;
|
|||
import com.silverwrist.util.DOMElementHelper;
|
||||
import com.silverwrist.venice.except.AccessError;
|
||||
import com.silverwrist.venice.except.ConfigException;
|
||||
import com.silverwrist.venice.svc.SecurityMonitorEnvironment;
|
||||
|
||||
/**
|
||||
* A <CODE>SecurityMonitor</CODE> 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
|
||||
* <CODE><security-definition/></CODE> 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
|
||||
|
||||
|
|
|
@ -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 <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.*;
|
||||
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
|
Loading…
Reference in New Issue
Block a user