You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Filip Hanik - Dev Lists <de...@hanik.com> on 2009/12/17 00:42:05 UTC

Access GlobalNamingResources using javax.naming

Is there a way to get hold of the GlobalNamingResources JNDI tree 
directly using the InitialContext?

I see that components like DataSourceRealm go to 
ServerFactory.getServer().getGlobalNamingResources(), but I would like a 
way to do it using standard JNDI APIs

best
Filip



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: Access GlobalNamingResources using javax.naming

Posted by Filip Hanik - Dev Lists <de...@hanik.com>.
On 12/18/2009 11:38 AM, Konstantin Kolinko wrote:
> 2009/12/17 Filip Hanik - Dev Lists<de...@hanik.com>:
>    
>> On 12/16/2009 07:37 PM, Konstantin Kolinko wrote:
>>      
>>> I think, that in JNDI there is no such way
>>>        
>> ok, maybe we can add in a namespace for that, such as
>> InitialContext.lookup("global:");
>> and then have a config attribute allowGlobalLookup="true|false" to be
>> backwards compatible
>>
>>      
> Why using<ResourceLink>  does not satisfy you?
>    
cause I'm hard to please ;)
resourcelinks get tied up using thread bindings or class loader 
bindings. This makes java:comp/env/ not work for a background thread 
that was not loaded from web-inf/lib

also, building custom tomcat components, that you define in server.xml, 
you may want to access through regular jndi and not have to import 
org.apache.catalina.Server to get to the global context

> I would like all access to the global resources to be explicit. If you
> need it, just add a<ResourceLink>, as documented.
> http://tomcat.apache.org/tomcat-6.0-doc/jndi-resources-howto.html
>
>    
>> and then have a config attribute allowGlobalLookup="true|false" to be
>> backwards compatible
>>      
> How is that from Security stand point?
>
> I mean, it must be allowGlobalLookup="false" by default.
>    
that is correct. Default behavior should be backwards compatible.
on top of that, one can add in a new java.security permission to further 
control access using the security manager
>
> Best regards,
> Konstantin Kolinko
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: dev-help@tomcat.apache.org
>
>
>    


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: Access GlobalNamingResources using javax.naming

Posted by Konstantin Kolinko <kn...@gmail.com>.
2009/12/17 Filip Hanik - Dev Lists <de...@hanik.com>:
> On 12/16/2009 07:37 PM, Konstantin Kolinko wrote:
>>
>> I think, that in JNDI there is no such way
>
> ok, maybe we can add in a namespace for that, such as
> InitialContext.lookup("global:");
> and then have a config attribute allowGlobalLookup="true|false" to be
> backwards compatible
>

Why using <ResourceLink> does not satisfy you?

I would like all access to the global resources to be explicit. If you
need it, just add a <ResourceLink>, as documented.
http://tomcat.apache.org/tomcat-6.0-doc/jndi-resources-howto.html

> and then have a config attribute allowGlobalLookup="true|false" to be
> backwards compatible

How is that from Security stand point?

I mean, it must be allowGlobalLookup="false" by default.


Best regards,
Konstantin Kolinko

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: Access GlobalNamingResources using javax.naming

Posted by Filip Hanik - Dev Lists <de...@hanik.com>.
On 12/16/2009 07:37 PM, Konstantin Kolinko wrote:
> I think, that in JNDI there is no such way
ok, maybe we can add in a namespace for that, such as 
InitialContext.lookup("global:");
and then have a config attribute allowGlobalLookup="true|false" to be 
backwards compatible


Filip


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: Access GlobalNamingResources using javax.naming

Posted by Konstantin Kolinko <kn...@gmail.com>.
2009/12/17 Filip Hanik - Dev Lists <de...@hanik.com>:
> Is there a way to get hold of the GlobalNamingResources JNDI tree directly
> using the InitialContext?
>
> I see that components like DataSourceRealm go to
> ServerFactory.getServer().getGlobalNamingResources(), but I would like a way
> to do it using standard JNDI APIs
>

I think, that in JNDI there is no such way, unless you have
<ResourceLink> in your context.xml file for the name that you are
trying to access.


Regarding <ResourceLink> implementation,
I do not know whether you would be interested how it works,
but as I've spent some time reviewing it, here is a quick summary

1. <ResourceLink> element -> ContextRuleSet rules create a
ContextResourceLink class instance from it
2. ContextRuleSet is placed into NamingResources class instance
3. NamingContextListener class is where JNDI context is created and
populated. It acts as a listener for the NamingContext. See
NamingContextListener#addResourceLink() -> ResourceLinkRef class
instance is created there and is bound to the JNDI context.

4. ResourceLinkRef is an instance of javax.naming.Reference,  so
o.a.naming.NamingContext.lookup()  uses
NamingManager.getObjectInstance() to resolve a NamingEntry.REFERENCE.

5. The ObjectFactory used to resolve the reference is actually the
o.a.naming.factory.ResourceLinkFactory.
(as ResourceLinkRef#getFactoryClassName() returns that name).

6. ResourceLinkFactory holds a static reference to the global context
and looks the name there.  The global context reference is passed
there by NamingContextListener when it initializes the global context.


> I see that components like DataSourceRealm go to
> ServerFactory.getServer().getGlobalNamingResources(), but I would like a way
> to do it using standard JNDI APIs

I think that ContextBindings.getClassLoader().lookup("comp/env") that
DataSourceRealm does is effectively the same as (new
InitialContext()).lookup("comp/env").

I see ServerFactory.getServer().getGlobalNamingContext() call there,
but do you need to be able to configure your component in the same way
as you do for DataSourceRealm?   I mean, using
DataSourceRealm.localDataSource=false is a bit of a trick.

I think that you can either require that <ResourceLink> be created by
a user, or use RealmBase#container to access the Server. The latter is
how TC 7 DataSourceRealm does it, as there is no ServerFactory in TC
7.


Best regards,
Konstantin Kolinko

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org