<br><tt><font size=2>Some feedback from an observer which may help:</font></tt>
<br>
<br><tt><font size=2>&gt; Bryan misses the need for extender model to load
internal impl classes ala <br>
&gt; Bundle.loadClass in OSGi.<br>
&gt; <br>
&gt; You do not want to have to export the service impl class from a module.
<br>
&gt; You want to hide the class from others' casual loading. However an
<br>
&gt; extender bundle (e.g. ServiceLoader) will need to be able to load
that <br>
&gt; class to make it instances of it available to others under the service
<br>
&gt; interface class.</font></tt>
<br><font size=2 face="sans-serif"><br>
Glyn</font>
<br>
<br><font size=1 face="sans-serif"><b>Bryan Atsatt &lt;bryan.atsatt@ORACLE.COM&gt;</b></font><tt><font size=2>
wrote on 30/05/2007 21:21:36:<br>
<br>
&gt; I've been assuming that Module private resources should not be visible<br>
&gt; to *any* class outside of the module. Including ResourceBundle, or
any<br>
&gt; other existing framework classes that do resource lookups (e.g.<br>
&gt; ServiceLoader, JSF, etc). If resources need to be visible to these<br>
&gt; existing classes, they must be exported. The very simple check I<br>
&gt; proposed (immediate caller) is sufficient to make this assertion.<br>
&gt; <br>
&gt; I believe your point is that if we used the permission model instead,
it<br>
&gt; would become possible for a module to invoke an external class (e.g.<br>
&gt; ResourceBundle.getBundle()) and enable *it* to successfully load a<br>
&gt; private resource from the module.<br>
&gt; <br>
&gt; Aside from the permission *grant* mechanism this model would rely
on, it<br>
&gt; is an entirely different model than that used for classes! (Though
we<br>
&gt; haven't explicitly defined this in 294, it seems extremely unlikely
that<br>
&gt; we will rely on permissions--none of the other access modes do so.)
Such<br>
&gt; asymmetry is very disconcerting to me, and, I believe, just plain
wrong...<br>
&gt; <br>
&gt; Consider that you could grant the ServiceLoader, for example, access
to<br>
&gt; a resource that names a class that it could not instantiate. That
class<br>
&gt; would have to be exported. I believe the resource should be as well.<br>
&gt; <br>
&gt; // Bryan<br>
&gt; <br>
&gt; <br>
&gt; <br>
&gt; <br>
&gt; Stanley M. Ho wrote:<br>
&gt; &gt; Hi Bryan,<br>
&gt; &gt;<br>
&gt; &gt; Those resource-related methods in ClassLoader can be called by
anyone,<br>
&gt; &gt; including code that is part of the module, code that is from
other<br>
&gt; &gt; modules, or code that is part of the platform libraries (e.g.<br>
&gt; &gt; ResourceBundle). The approach you described would require walking
the<br>
&gt; &gt; stack to get the caller's Module, but the real issue is that
it is<br>
&gt; &gt; difficult to determine who the actual caller is from the stack.<br>
&gt; &gt;<br>
&gt; &gt; Treating the immediate caller on the stack as the actual caller
wouldn't<br>
&gt; &gt; be sufficient because the immediate caller could be called by
someone<br>
&gt; &gt; else who is the one actually making the call. On the other hand,<br>
&gt; &gt; treating the originated caller on the stack as the actual caller
would<br>
&gt; &gt; be the right semantic, but this is basically the same as the
security<br>
&gt; &gt; permission approach.<br>
&gt; &gt;<br>
&gt; &gt; - Stanley<br>
&gt; &gt;<br>
&gt; &gt;<br>
&gt; &gt; Bryan Atsatt wrote:<br>
&gt; &gt;&gt; Both solutions require stack walking (unless there is some
new<br>
&gt; &gt;&gt; implementation of the java security model I've not yet seen!).<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; The permission check does much more work than is necessary
here. Take a<br>
&gt; &gt;&gt; look at AccessController.checkPermission() to see what I
mean.<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; And actually there is a very simple API to get the stack,
which I've<br>
&gt; &gt;&gt; used for years:<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; &nbsp; private static class StackAccessor extends SecurityManager
{<br>
&gt; &gt;&gt; &nbsp; &nbsp; &nbsp; public Class[] getStack() {<br>
&gt; &gt;&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return getClassContext();<br>
&gt; &gt;&gt; &nbsp; &nbsp; &nbsp; }<br>
&gt; &gt;&gt; &nbsp; }<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; &nbsp; private static final STACK_ACCESSOR = new StackAccessor();<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; Now the enclosing class can simply call STACK_ACCESSOR.getStack().<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; // Bryan<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; Stanley M. Ho wrote:<br>
&gt; &gt;&gt;&gt; Hi Bryan,<br>
&gt; &gt;&gt;&gt;<br>
&gt; &gt;&gt;&gt; Bryan Atsatt wrote:<br>
&gt; &gt;&gt;&gt;&gt; 1. Definitely agree that resource search order should
be identical to<br>
&gt; &gt;&gt;&gt;&gt; class search order.<br>
&gt; &gt;&gt;&gt;<br>
&gt; &gt;&gt;&gt; Glad to hear!<br>
&gt; &gt;&gt;&gt;<br>
&gt; &gt;&gt;&gt;&gt; 2. Using permissions to limit access to private resources
seems like<br>
&gt; &gt;&gt;&gt;&gt; overkill to me. The prototype implemented this in
a very simple<br>
&gt; &gt;&gt;&gt;&gt; fashion:<br>
&gt; &gt;&gt;&gt;&gt;<br>
&gt; &gt;&gt;&gt;&gt; a. If resource is exported, return it, else<br>
&gt; &gt;&gt;&gt;&gt; a. Get the caller's Module (get class from stack,
get module from it)<br>
&gt; &gt;&gt;&gt;&gt; b. If callerModule == this, return resource, else
return null.<br>
&gt; &gt;&gt;&gt;<br>
&gt; &gt;&gt;&gt; The issue is that this approach still requires stack
walking and there<br>
&gt; &gt;&gt;&gt; is no public API in the SE platform that let you implement
this.<br>
&gt; &gt;&gt;&gt;<br>
&gt; &gt;&gt;&gt; If stack walking is required for the check anyway, I
think the security<br>
&gt; &gt;&gt;&gt; permission approach is better that it is implementable
with the existing<br>
&gt; &gt;&gt;&gt; API in the SE platform.<br>
&gt; &gt;&gt;&gt;<br>
&gt; &gt;&gt;&gt; - Stanley<br>
&gt; &gt;&gt;&gt;<br>
&gt; &gt;<br>
</font></tt><font size=3 face="sans-serif"><br>
</font>
<br><font size=3 face="sans-serif"><br>
</font>
<hr><font size=2 face="sans-serif"><br>
<i><br>
</i></font>
<p><font size=2 face="sans-serif"><i>Unless stated otherwise above:<br>
IBM United Kingdom Limited - Registered in England and Wales with number
741598. <br>
Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6
3AU</i></font>
<p><font size=2 face="sans-serif"><br>
</font><font size=3 face="sans-serif"><br>
</font>
<br>
<br><font size=3 face="sans-serif"><br>
</font>