TOMEE-4654 - Make the component naming context read-only by default#2846
TOMEE-4654 - Make the component naming context read-only by default#2846jungm wants to merge 1 commit into
Conversation
The Enterprise Beans spec (10.4.4) and EE.5.3.4 require java:comp and its subcontexts to be read-only inside a deployed application: write attempts must not take effect. The IvmContext read-only machinery already existed but was gated behind openejb.forceReadOnlyAppNamingContext, which defaulted to false, so every deployed application received a fully writable ENC. Flip that default to true (retained as an explicit opt-out for backward compatibility) and extend the enforcement to the web and app contexts. Servlets and JSF managed beans resolve java:comp/java:module/java:app through the WebContext and AppContext rather than a BeanContext, so marking only the BeanContexts read-only left the web tier writable. Adds JavaCompReadOnlyTest, which deploys a real application and asserts that bind/rebind/rename/unbind/createSubcontext/destroySubcontext are all refused on java:comp and java:app, and inverts AppNamingReadOnlyTest, whose former testAppNamingContextWritableByDefault asserted the exact behaviour being fixed.
|
The underlying bug is real and worth fixing — the read-only machinery has been there since I can't approve as-is though — the marking happens at the wrong point in the lifecycle, and it Container-internal binds can now fail. I probed this directly in openejb-core: with the patch applied, after And the same modules never get marked. The flip side: Both problems have one shape of fix: record the read-only intent on the Other things:
|
What
Makes the
java:compcomponent naming context read-only by default, as the Enterprise Beans spec (10.4.4) and EE.5.3.4 require: write attempts against a deployed application's ENC must not take effect.Why
The
IvmContextread-only enforcement already existed and was correct —checkReadOnly()throwsOperationNotSupportedExceptionandsetReadOnly()cascades through the whole name tree. But nothing ever turned it on:openejb.forceReadOnlyAppNamingContextdefaulted tofalse, so every deployed application got a fully writablejava:comp, lettingbind/rebind/renamethrough where the spec requires them refused.Changes
Assembler: defaultopenejb.forceReadOnlyAppNamingContexttotrue(kept as an explicit opt-out for anyone depending on the old writable behaviour).Assembler.setAppNamingContextReadOnly: also mark theWebContextandAppContextnaming contexts read-only. Servlets and JSF managed beans resolvejava:comp/java:module/java:appthrough those contexts rather than through aBeanContext, so marking only theBeanContexts left the web tier writable. The one late write to the app context (app/BeanManager) happens before this point, so it is unaffected.JavaCompReadOnlyTest(new): deploys a real application and assertsbind/rebind/rename/unbind/createSubcontext/destroySubcontextare all refused onjava:compandjava:app, that nothing written becomes observable, and that pre-existing bindings survive.AppNamingReadOnlyTest: invertedtestAppNamingContextWritableByDefault(it asserted the exact bug) into a read-only-by-default test, plus a separate test for the opt-out path.Verification
openejb-corefull suite: 4093 tests, the only 6 failures are pre-existing security-test failures reproduced on a cleanmain(unrelated to this change).enterprise-beans-30partition against a freshly built Plume distribution: thenaming/contextwrite assertions now pass in both the EJB and web (servlet / filtered-servlet / JSF) vehicles.Reviewer notes
apache/tomee-tckrepo and is not part of this PR.org.apache.naming.NamingContextinstead ofIvmContext, sojava:comp/envlists extracomp/moduleentries andclose()fails. It is orthogonal to this read-only fix and not addressed here.🤖 Generated with Claude Code