You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by bu...@apache.org on 2014/04/24 02:53:12 UTC

[Bug 56451] New: JNDI lookups under java:comp/Resources do not access resources

https://issues.apache.org/bugzilla/show_bug.cgi?id=56451

            Bug ID: 56451
           Summary: JNDI lookups under java:comp/Resources do not access
                    <Context aliases> resources
           Product: Tomcat 7
           Version: 7.0.47
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: minor
          Priority: P2
         Component: Catalina
          Assignee: dev@tomcat.apache.org
          Reporter: daniel.mojoli@idea.com.py

1. Using JNDI lookup to access resources

Given a resource accessible as

request.getServletContext().getResourceAsStream("/some/path/myResource");

it can also be accessed via JNDI (return type is different but equally useful)

ic.lookup("java:comp/Resources/some/path/myResource")


2. JNDI lookups ignores aliased resources

Given a <Context aliases="/someAlias=/any/path" .../>, its resources are
accessible

request.getServletContext().getResourceAsStream("/someAlias/myOtherResource");

BUT, the lookup 

ic.lookup("java:comp/Resources/someAlias/myOtherResource")

fails throwing org.apache.naming.resources.ImmutableNameNotFoundException.

Listing the java:comp/Resources context shows someAlias is NOT bound.

3. Expected behavior

Tomcat exposes resources under the java:comp/Resources JNDI context. Aliases
should also apply to this alternate access interface.

-- 
You are receiving this mail because:
You are the assignee for the bug.

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


[Bug 56451] JNDI lookups under java:comp/Resources do not access resources

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=56451

Mark Thomas <ma...@apache.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #5 from Mark Thomas <ma...@apache.org> ---
Alternative fix applied for 7.0.54.

-- 
You are receiving this mail because:
You are the assignee for the bug.

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


[Bug 56451] JNDI lookups under java:comp/Resources do not access resources

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=56451

Mark Thomas <ma...@apache.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #2 from Mark Thomas <ma...@apache.org> ---
This has been fixed in trunk for 7.0.54 onwards.

Note: A JNDI name with a leading '/' should be interpreted as having any empty
first name part which never makes sense in this case. Therefore, I opted to
remove / from the alias path before adding to the aliases map.

-- 
You are receiving this mail because:
You are the assignee for the bug.

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


[Bug 56451] JNDI lookups under java:comp/Resources do not access resources

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=56451

Konstantin Kolinko <kn...@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|FIXED                       |---

--- Comment #3 from Konstantin Kolinko <kn...@gmail.com> ---
Re r1592052

I am sure that that is not enough.

There are calls to ProxyDirContext.lookupCache(str) in DefaultServlet,
WebdavSevlet.

There are calls to contextVersion.resources.lookup(str) in Mapper.

All they are using Servlet resource path (starting with '/') instead of JNDI
name, and I think they are now broken.

-- 
You are receiving this mail because:
You are the assignee for the bug.

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


[Bug 56451] JNDI lookups under java:comp/Resources do not access resources

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=56451

--- Comment #4 from Mark Thomas <ma...@apache.org> ---
I'm looking at this now. It appears that directory listings aren't handled
correctly for aliases either (and don't appear to have been correct before
r1592052 either.

-- 
You are receiving this mail because:
You are the assignee for the bug.

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


[Bug 56451] JNDI lookups under java:comp/Resources do not access resources

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=56451

--- Comment #1 from Konstantin Kolinko <kn...@gmail.com> ---
1. Note that this API is not available in Tomcat 8,
but you can call

> ic.lookup("java:comp/Resources")

which will return StandardRoot.

2. Debugging Tomcat 7, the cause for this issue is different from what I
expected.

> ic.lookup("java:comp/Resources")

In Tomcat 7 is an instance of ProxyDirContext.

If use the OP way,
- The string name is parsed into CompositeName.
- There is a series of lookups, each obtaining a
org.apache.naming.NamingContext and looking up the name with first component
removed.  See NamingContext.lookup(Name, boolean resolveLinks:= true)
{ ... return ((Context) entry.value).lookup(name.getSuffix(1)) }
- It goes into ProxyDirContext.lookup(Name)
- It does cacheLookup(name.toString())
- The cacheLookup method creates CacheEntry and calls cacheLoad() to fill it.
- The cacheLoad method calls dirContext.getAttributes(entry.name).

The problem is that
1) name.toString() looks like "some/path/myResource"
2) when you call resource lookup the name will be "/some/path/myResource" with
leading "/".

This results in
- Aliases in BaseDirContext/FileDirContext do not work, as all aliases start
with leading "/".
- Inconsistency in cache keys in ProxyDirContext.

I wonder whether this is better be fixed by consistently adding '/' to the
start of the string, or by consistently removing starting '/'
from names and aliases.

The latter will be more effective (substring is cheaper that string
concatenation), and more correct from JNDI API point of view,
but it may be easy to miss some use case.


It is also possible to say that this is unsupported API and close as wontfix.

Note that the following works correctly:
((Context)
ic.lookup("java:comp/Resources").lookup("/someAlias/myOtherResource")

Note leading "/" in "/someAlias".

-- 
You are receiving this mail because:
You are the assignee for the bug.

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