[Helma-user] Best way of extending HopObject functions
Daniel Ruthardt
daniel.ruthardt at dowee.com
Wed Jul 30 13:48:24 CEST 2008
Hi list,
first of all: feels good to be back (for those who still remember me) (-:
I am looking for the best way of extending predefined HopObject
functions like get(), getById(), and so on. I need to extend these
functions because I want to implement a security layer, which should
control access to HopObjects and properties. Yes, even getting and
setting properties. This is important to me, as with lots of generic
macros, the allow or not allow macro paradigm of Helma is not enough
anymore, and implementing security checks in each macro is a no go too.
I have two working solutions, but I feel like there are better ways to
do it.
Approach 1:
I changed the helma source and added calls to JS callback functions
(HopObject.canGet(), HopObject.canAdd(), HopObject.canWrite(),
HopObject.canRead(), ...). This way the predefined HopObject functions
are not overridden, but extended in their Java implementation. Works
fine, even for getting and setting generic properties, but touches the
helma source.
Approach2:
My second approach is JS based only and does not touch the helma source.
I simplified things below.
-----global/functions.js-----
function get(id) {
// do some security checks and eventually return something
// ...
return this._get(id);
}
-----Test/functions.js-----
function Test() {
this._get = this.get;
this.get = get;
}
The overriding get() function is defined in the global space as I only
need it once for all prototypes. The constructor of Test does only set
one new reference variable per instance. I would however prefer to set
the function reference on the prototype, but I did not find a way to do
this for Helma prototypes.
I also failed to implement generic getter / setter functions in JS. I
managed to implement specific ones, but not generic ones.
Anyone aware of how to improve the second approach?
Kind regards,
Daniel
More information about the Helma-user
mailing list