From 4a3879b0ee992e2282f6f1ebd86bf8e4c5ce6ea5 Mon Sep 17 00:00:00 2001 From: hns Date: Mon, 25 Feb 2002 14:48:11 +0000 Subject: [PATCH] Check for readonly flag in putProperty method so that write protected properties can't be modified from script code. Deleted stuff that was permanently commented out: * setNode() method * readonly check for created and lastmodified props --- src/helma/scripting/fesi/ESNode.java | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/src/helma/scripting/fesi/ESNode.java b/src/helma/scripting/fesi/ESNode.java index 790fad6e..9f1474d6 100644 --- a/src/helma/scripting/fesi/ESNode.java +++ b/src/helma/scripting/fesi/ESNode.java @@ -89,21 +89,6 @@ public class ESNode extends ObjectPrototype { return node; } - /* public void setNode (INode node) { - if (node != null) { - this.node = node; - // set node handle to wrapped node - if (node instanceof helma.objectmodel.db.Node) - handle = ((helma.objectmodel.db.Node) node).getHandle (); - else - handle = null; - eval.objectcache.put (node, this); - // reset cache Node - will be reinitialized when needed - cache = null; - cacheWrapper = null; - } - } */ - public void setPrototype (String protoName) { checkNode (); node.setPrototype (protoName); @@ -240,8 +225,7 @@ public class ESNode extends ObjectPrototype { public void putProperty(String propertyName, ESValue propertyValue, int hash) throws EcmaScriptException { checkNode (); // eval.app.logEvent ("put property called: "+propertyName+", "+propertyValue.getClass()); - if (/* "lastmodified".equalsIgnoreCase (propertyName) || "created".equalsIgnoreCase (propertyName) || */ - "cache".equalsIgnoreCase (propertyName)) + if ("cache".equalsIgnoreCase (propertyName)) throw new EcmaScriptException ("Can't modify read-only property \""+propertyName+"\"."); if ("subnodeRelation".equalsIgnoreCase (propertyName)) { @@ -249,6 +233,14 @@ public class ESNode extends ObjectPrototype { return; } + // check if the property is write protected, i.e. the type.property file describes it as [readonly] + DbMapping dbm = node.getDbMapping (); + if (dbm != null) { + Relation rel = dbm.getPropertyRelation (propertyName); + if (rel != null && rel.isReadonly ()) + return; + } + if (propertyValue instanceof ESNull || propertyValue instanceof ESUndefined) node.unset (propertyName); else if (propertyValue instanceof ESString)