New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JNDI.lookup not handling unknown JNDI variables elegantly #141

Closed
wfsaxton opened this Issue Jun 30, 2015 · 8 comments

Comments

Projects
None yet
3 participants
@wfsaxton

wfsaxton commented Jun 30, 2015

It looks like the lookup method tries to be helpful by returning null for unknown JNDI variables:

try {
    context = new InitialContext();
    return (T) context.lookup(name);
} catch (NameNotFoundException e) {
    return null;
} catch (NamingException e) {
    throw new IllegalStateException(e);

But in my case, when I run the following:

# swr/devLoginEnabled is undefined
Boolean devLoginEnabled = JNDI.lookup("swr/devLoginEnabled");

I get:
java.lang.IllegalStateException: javax.naming.NamingException: Lookup failed for 'swr/devLoginEnabled' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NameNotFoundException: devLoginEnabled not found]
at org.omnifaces.util.JNDI.lookup(JNDI.java:92)

Shouldn't JNDI.lookup be returning null if the JNDI variable does not exist?

@BalusC

This comment has been minimized.

Show comment
Hide comment
@BalusC

BalusC Jul 1, 2015

Member

Yes it should. As per the stack trace it looks like the NameNotFoundException of interest is being wrapped in a NamingException. What environment is this running in? GlassFish? Which version?

Member

BalusC commented Jul 1, 2015

Yes it should. As per the stack trace it looks like the NameNotFoundException of interest is being wrapped in a NamingException. What environment is this running in? GlassFish? Which version?

@arjantijms

This comment has been minimized.

Show comment
Hide comment
@arjantijms

arjantijms Jul 1, 2015

Member

It looks a bit strange that NameNotFoundException is wrapped in NamingException. Perhaps we could do an unwind of the Exception hierarchy and see if any of the wrapped exceptions is NameNotFoundException, if so, don't throw.

I wonder how common this is though.

Member

arjantijms commented Jul 1, 2015

It looks a bit strange that NameNotFoundException is wrapped in NamingException. Perhaps we could do an unwind of the Exception hierarchy and see if any of the wrapped exceptions is NameNotFoundException, if so, don't throw.

I wonder how common this is though.

@wfsaxton

This comment has been minimized.

Show comment
Hide comment
@wfsaxton

wfsaxton Jul 1, 2015

GlassFish Server Open Source Edition 4.1 (build 13)

Here is the full stack trace:

Warning: StandardWrapperValve[Faces Servlet]: Servlet.service() for servlet Faces Servlet threw exception
java.lang.IllegalStateException: javax.naming.NamingException: Lookup failed for 'devLoginEnabled' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NameNotFoundException: devLoginEnabled not found]
at org.omnifaces.util.JNDI.lookup(JNDI.java:92)
at com.example.escrow.web.SecurityFilter.isDevLoginEnabled(SecurityFilter.java:101)
at com.example.escrow.web.SecurityFilter.getUserEmail(SecurityFilter.java:87)
at com.example.escrow.web.SecurityFilter.getCurrentUser(SecurityFilter.java:83)
at com.example.escrow.web.SecurityFilter.doFilter(SecurityFilter.java:50)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at org.omnifaces.facesviews.FacesViewsForwardingFilter.filterExtensionLess(FacesViewsForwardingFilter.java:128)
at org.omnifaces.facesviews.FacesViewsForwardingFilter.doFilter(FacesViewsForwardingFilter.java:89)
at org.omnifaces.filter.HttpFilter.doFilter(HttpFilter.java:108)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:316)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:415)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:282)
at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:201)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:175)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:561)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:565)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545)
at java.lang.Thread.run(Thread.java:745)
Caused by: javax.naming.NamingException: Lookup failed for 'devLoginEnabled' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NameNotFoundException: devLoginEnabled not found]
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:491)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:438)
at javax.naming.InitialContext.lookup(InitialContext.java:417)
at javax.naming.InitialContext.lookup(InitialContext.java:417)
at org.omnifaces.util.JNDI.lookup(JNDI.java:88)
... 38 more
Caused by: javax.naming.NameNotFoundException: devLoginEnabled not found
at com.sun.enterprise.naming.impl.TransientContext.doLookup(TransientContext.java:237)
at com.sun.enterprise.naming.impl.TransientContext.lookup(TransientContext.java:204)
at com.sun.enterprise.naming.impl.SerialContextProviderImpl.lookup(SerialContextProviderImpl.java:66)
at com.sun.enterprise.naming.impl.LocalSerialContextProviderImpl.lookup(LocalSerialContextProviderImpl.java:114)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:478)
... 42 more

wfsaxton commented Jul 1, 2015

GlassFish Server Open Source Edition 4.1 (build 13)

Here is the full stack trace:

Warning: StandardWrapperValve[Faces Servlet]: Servlet.service() for servlet Faces Servlet threw exception
java.lang.IllegalStateException: javax.naming.NamingException: Lookup failed for 'devLoginEnabled' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NameNotFoundException: devLoginEnabled not found]
at org.omnifaces.util.JNDI.lookup(JNDI.java:92)
at com.example.escrow.web.SecurityFilter.isDevLoginEnabled(SecurityFilter.java:101)
at com.example.escrow.web.SecurityFilter.getUserEmail(SecurityFilter.java:87)
at com.example.escrow.web.SecurityFilter.getCurrentUser(SecurityFilter.java:83)
at com.example.escrow.web.SecurityFilter.doFilter(SecurityFilter.java:50)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at org.omnifaces.facesviews.FacesViewsForwardingFilter.filterExtensionLess(FacesViewsForwardingFilter.java:128)
at org.omnifaces.facesviews.FacesViewsForwardingFilter.doFilter(FacesViewsForwardingFilter.java:89)
at org.omnifaces.filter.HttpFilter.doFilter(HttpFilter.java:108)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:316)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:415)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:282)
at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:201)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:175)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:561)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:565)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545)
at java.lang.Thread.run(Thread.java:745)
Caused by: javax.naming.NamingException: Lookup failed for 'devLoginEnabled' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NameNotFoundException: devLoginEnabled not found]
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:491)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:438)
at javax.naming.InitialContext.lookup(InitialContext.java:417)
at javax.naming.InitialContext.lookup(InitialContext.java:417)
at org.omnifaces.util.JNDI.lookup(JNDI.java:88)
... 38 more
Caused by: javax.naming.NameNotFoundException: devLoginEnabled not found
at com.sun.enterprise.naming.impl.TransientContext.doLookup(TransientContext.java:237)
at com.sun.enterprise.naming.impl.TransientContext.lookup(TransientContext.java:204)
at com.sun.enterprise.naming.impl.SerialContextProviderImpl.lookup(SerialContextProviderImpl.java:66)
at com.sun.enterprise.naming.impl.LocalSerialContextProviderImpl.lookup(LocalSerialContextProviderImpl.java:114)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:478)
... 42 more

@BalusC BalusC closed this in ff948cb Jul 1, 2015

@BalusC

This comment has been minimized.

Show comment
Hide comment
@BalusC

BalusC Jul 1, 2015

Member

Fix is available in today's 2.2-SNAPSHOT. Give it a try and let us know if that does it for you.

Member

BalusC commented Jul 1, 2015

Fix is available in today's 2.2-SNAPSHOT. Give it a try and let us know if that does it for you.

@wfsaxton

This comment has been minimized.

Show comment
Hide comment
@wfsaxton

wfsaxton Jul 1, 2015

Thanks for the quick fix. Will test it today.

Stupid question though: what do I put in my Maven pom.xml to access this? (Sorry, I'm fairly new to maven and I just use my IDE to search for the libraries I need and I only see Omnifaces 2.1 available).

Or is 2.2 full release becoming available soon?

wfsaxton commented Jul 1, 2015

Thanks for the quick fix. Will test it today.

Stupid question though: what do I put in my Maven pom.xml to access this? (Sorry, I'm fairly new to maven and I just use my IDE to search for the libraries I need and I only see Omnifaces 2.1 available).

Or is 2.2 full release becoming available soon?

@BalusC

This comment has been minimized.

Show comment
Hide comment
@BalusC

BalusC Jul 1, 2015

Member

A "snapshot" is just the current/latest build. It's far from a release. To enable snapshots from a certain Maven repo (OSS in our case), add it as <repository> to either ~/.m2/settings.xml (global) or pom.xml (project-specific). See also a.o. http://stackoverflow.com/q/5901378/157882

We may make code changes and create snapshots so now and then before 2.2 release. Those changes will then get reflected in your project if you use the snapshot version in pom. It will generally work just fine, but imagine if we make some mistake and notice it only a few days or weeks later, or are trying to test something which may not necessarily work in all environments, then your project may be affected. That's why it's advisable to not use snapshots of 3rd party libraries in production, unless you have your own build system which can "lock" a specific snapshot version, or closely track (and understand) any changes in the codebase.

Member

BalusC commented Jul 1, 2015

A "snapshot" is just the current/latest build. It's far from a release. To enable snapshots from a certain Maven repo (OSS in our case), add it as <repository> to either ~/.m2/settings.xml (global) or pom.xml (project-specific). See also a.o. http://stackoverflow.com/q/5901378/157882

We may make code changes and create snapshots so now and then before 2.2 release. Those changes will then get reflected in your project if you use the snapshot version in pom. It will generally work just fine, but imagine if we make some mistake and notice it only a few days or weeks later, or are trying to test something which may not necessarily work in all environments, then your project may be affected. That's why it's advisable to not use snapshots of 3rd party libraries in production, unless you have your own build system which can "lock" a specific snapshot version, or closely track (and understand) any changes in the codebase.

@wfsaxton

This comment has been minimized.

Show comment
Hide comment
@wfsaxton

wfsaxton Jul 1, 2015

Thanks for the info. I went ahead and temporarily installed the snapshot to test the fix and I verified it worked.

Will use a workaround until 2.2 gets released.

wfsaxton commented Jul 1, 2015

Thanks for the info. I went ahead and temporarily installed the snapshot to test the fix and I verified it worked.

Will use a workaround until 2.2 gets released.

@BalusC

This comment has been minimized.

Show comment
Hide comment
@BalusC

BalusC Jul 1, 2015

Member

Great. Thank you for helping to improve OmniFaces.

Member

BalusC commented Jul 1, 2015

Great. Thank you for helping to improve OmniFaces.

@BalusC BalusC added the bug label Oct 3, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment