commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mark Struberg <>
Subject [privilizer] new idea to improve usability
Date Sun, 30 Dec 2012 17:05:53 GMT

Not sure if this is worth doing, but could be nice from a usability pov.

Usually projects have a lot of blocks which need doPrivileged copied over from one class to
the other.
Using @Privileged makes this a lot easier. But you still need to add private methods to all
your classes...

Now imagine you have a public class SecurityUtil with methods having the annotation as in
the example: 
public static @PrivilizerBlueprint ClassLoader getClassLoader() {..}

and on your other class where you like to use it you annotate the whole class with 

public class MyOtherClass {
 public void doSomething() {
    ClassLoader cl = SecurityUtil.getClassLoader();

It would already be easy with the weaver to find all the classes which have a @UsingPrilizerBlueprint
annotation. And it is also pretty easy to scan the bytecode and create private 'inlined' methods
for all the @PrivilizerBlueprint methods (effectively copy over the bytecode for the whole
method from the util class to the using class plus do the doPrivileged around it) and change
the invocation from SecurityUtil.getClassLoader to this.privilized_getClassLoader()

In the afterWeave all the SecurityUtil methods which are just @PrivilizerBlueprint methods
will get changed to Modifier private.

That would effectively reduce the need to manually add private methods to all your classes
but instead maintain all those helper functions in a single well maintainable place.

If the weaver is disabled you would just use the SecurityUtil. Of course, from a debugging
pov this is not that perfect, but from a writer/user pov it's a big benefit imo.

wdyt? worth trying?


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message