This is an automated email from the ASF dual-hosted git repository.
remm pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/main by this push:
new bde3d2b701 Dissociate ignoreAnnotations from metadata-complete
bde3d2b701 is described below
commit bde3d2b70113dfd5ed7b2848d0fe5f2242f5166a
Author: remm <[email protected]>
AuthorDate: Fri Nov 25 11:48:03 2022 +0100
Dissociate ignoreAnnotations from metadata-complete
metadata-complete should mostly be about annotations such as
@WebServlet, which add to metadata, rather than everything. As a result,
the ignoreAnnotations flag is refocused on ignoring all annotations.
As this changes behavior, I have no plans to backport.
---
java/org/apache/catalina/Context.java | 20 +++++++++
java/org/apache/catalina/core/StandardContext.java | 21 ++++++++++
.../org/apache/catalina/startup/ContextConfig.java | 2 +-
.../org/apache/catalina/startup/FailedContext.java | 5 +++
.../apache/catalina/startup/WebAnnotationSet.java | 48 ++++++++++++----------
.../catalina/storeconfig/server-registry.xml | 2 +-
test/org/apache/tomcat/unittest/TesterContext.java | 6 +++
webapps/docs/META-INF/context.xml | 2 +-
webapps/docs/changelog.xml | 4 ++
webapps/docs/config/context.xml | 7 ++++
webapps/examples/META-INF/context.xml | 2 +-
webapps/host-manager/META-INF/context.xml | 2 +-
webapps/manager/META-INF/context.xml | 2 +-
13 files changed, 95 insertions(+), 28 deletions(-)
diff --git a/java/org/apache/catalina/Context.java
b/java/org/apache/catalina/Context.java
index cf940fad3f..1d7bc4ab9f 100644
--- a/java/org/apache/catalina/Context.java
+++ b/java/org/apache/catalina/Context.java
@@ -440,6 +440,26 @@ public interface Context extends Container, ContextBind {
public void setIgnoreAnnotations(boolean ignoreAnnotations);
+ /**
+ * Determine if the matadata of the application is complete. This typically
+ * means annotations which add to the application metadata will be
+ * ignored.
+ *
+ * @return {@code true} if metadata is complete for this web
+ * application
+ */
+ public boolean getMetadataComplete();
+
+
+ /**
+ * Set the boolean on the metadata complete flag for this web
+ * application.
+ *
+ * @param metadataComplete The boolean on the metadata complete flag
+ */
+ public void setMetadataComplete(boolean metadataComplete);
+
+
/**
* @return the login configuration descriptor for this web application.
*/
diff --git a/java/org/apache/catalina/core/StandardContext.java
b/java/org/apache/catalina/core/StandardContext.java
index db4ac5f51a..752778ce03 100644
--- a/java/org/apache/catalina/core/StandardContext.java
+++ b/java/org/apache/catalina/core/StandardContext.java
@@ -399,6 +399,12 @@ public class StandardContext extends ContainerBase
private boolean ignoreAnnotations = false;
+ /**
+ * Ignore annotations.
+ */
+ private boolean metadataComplete = false;
+
+
/**
* The Loader implementation with which this Container is associated.
*/
@@ -2020,6 +2026,21 @@ public class StandardContext extends ContainerBase
}
+ @Override
+ public boolean getMetadataComplete() {
+ return this.metadataComplete;
+ }
+
+
+ @Override
+ public void setMetadataComplete(boolean metadataComplete) {
+ boolean oldMetadataComplete = this.metadataComplete;
+ this.metadataComplete = metadataComplete;
+ support.firePropertyChange("metadataComplete", oldMetadataComplete,
+ this.metadataComplete);
+ }
+
+
/**
* @return the login configuration descriptor for this web application.
*/
diff --git a/java/org/apache/catalina/startup/ContextConfig.java
b/java/org/apache/catalina/startup/ContextConfig.java
index ea164cfb6b..3dcf9fa95f 100644
--- a/java/org/apache/catalina/startup/ContextConfig.java
+++ b/java/org/apache/catalina/startup/ContextConfig.java
@@ -1473,7 +1473,7 @@ public class ContextConfig implements LifecycleListener {
// messageDestinations were ignored in Tomcat 6, so ignore here
- context.setIgnoreAnnotations(webxml.isMetadataComplete());
+ context.setMetadataComplete(webxml.isMetadataComplete());
for (Entry<String, String> entry :
webxml.getMimeMappings().entrySet()) {
context.addMimeMapping(entry.getKey(), entry.getValue());
diff --git a/java/org/apache/catalina/startup/FailedContext.java
b/java/org/apache/catalina/startup/FailedContext.java
index 3234eed0cd..d24dfd135b 100644
--- a/java/org/apache/catalina/startup/FailedContext.java
+++ b/java/org/apache/catalina/startup/FailedContext.java
@@ -396,6 +396,11 @@ public class FailedContext extends LifecycleMBeanBase
implements Context {
@Override
public void setIgnoreAnnotations(boolean ignoreAnnotations) { /* NO-OP */ }
+ @Override
+ public boolean getMetadataComplete() { return false; }
+ @Override
+ public void setMetadataComplete(boolean metadataComplete) { /* NO-OP */ }
+
@Override
public LoginConfig getLoginConfig() { return null; }
@Override
diff --git a/java/org/apache/catalina/startup/WebAnnotationSet.java
b/java/org/apache/catalina/startup/WebAnnotationSet.java
index 8d0073b7b3..feba189271 100644
--- a/java/org/apache/catalina/startup/WebAnnotationSet.java
+++ b/java/org/apache/catalina/startup/WebAnnotationSet.java
@@ -137,21 +137,23 @@ public class WebAnnotationSet {
loadFieldsAnnotation(context, clazz);
loadMethodsAnnotation(context, clazz);
- /* Process RunAs annotation which can be only on servlets.
- * Ref JSR 250, equivalent to the run-as element in
- * the deployment descriptor
- */
- RunAs runAs = clazz.getAnnotation(RunAs.class);
- if (runAs != null) {
- wrapper.setRunAs(runAs.value());
- }
+ if (!context.getMetadataComplete()) {
+ /* Process RunAs annotation which can be only on servlets.
+ * Ref JSR 250, equivalent to the run-as element in
+ * the deployment descriptor
+ */
+ RunAs runAs = clazz.getAnnotation(RunAs.class);
+ if (runAs != null) {
+ wrapper.setRunAs(runAs.value());
+ }
- // Process ServletSecurity annotation
- ServletSecurity servletSecurity =
clazz.getAnnotation(ServletSecurity.class);
- if (servletSecurity != null) {
- context.addServletSecurity(
- new ApplicationServletRegistration(wrapper,
context),
- new ServletSecurityElement(servletSecurity));
+ // Process ServletSecurity annotation
+ ServletSecurity servletSecurity =
clazz.getAnnotation(ServletSecurity.class);
+ if (servletSecurity != null) {
+ context.addServletSecurity(
+ new ApplicationServletRegistration(wrapper,
context),
+ new ServletSecurityElement(servletSecurity));
+ }
}
}
}
@@ -251,14 +253,16 @@ public class WebAnnotationSet {
}
}
*/
- /* Process DeclareRoles annotation.
- * Ref JSR 250, equivalent to the security-role element in
- * the deployment descriptor
- */
- DeclareRoles declareRolesAnnotation =
clazz.getAnnotation(DeclareRoles.class);
- if (declareRolesAnnotation != null && declareRolesAnnotation.value()
!= null) {
- for (String role : declareRolesAnnotation.value()) {
- context.addSecurityRole(role);
+ if (!context.getMetadataComplete()) {
+ /* Process DeclareRoles annotation.
+ * Ref JSR 250, equivalent to the security-role element in
+ * the deployment descriptor
+ */
+ DeclareRoles declareRolesAnnotation =
clazz.getAnnotation(DeclareRoles.class);
+ if (declareRolesAnnotation != null &&
declareRolesAnnotation.value() != null) {
+ for (String role : declareRolesAnnotation.value()) {
+ context.addSecurityRole(role);
+ }
}
}
}
diff --git a/java/org/apache/catalina/storeconfig/server-registry.xml
b/java/org/apache/catalina/storeconfig/server-registry.xml
index 4dd7ddec70..856e6f2195 100644
--- a/java/org/apache/catalina/storeconfig/server-registry.xml
+++ b/java/org/apache/catalina/storeconfig/server-registry.xml
@@ -79,7 +79,7 @@
<TransientAttribute>effectiveMajorVersion</TransientAttribute>
<TransientAttribute>effectiveMinorVersion</TransientAttribute>
<TransientAttribute>webappVersion</TransientAttribute>
- <TransientAttribute>ignoreAnnotations</TransientAttribute>
+ <TransientAttribute>metadataComplete</TransientAttribute>
</Description>
<Description
id="org.apache.catalina.deploy.NamingResourcesImpl.[GlobalNamingResources]"
diff --git a/test/org/apache/tomcat/unittest/TesterContext.java
b/test/org/apache/tomcat/unittest/TesterContext.java
index 8ee05598c7..16c22425fc 100644
--- a/test/org/apache/tomcat/unittest/TesterContext.java
+++ b/test/org/apache/tomcat/unittest/TesterContext.java
@@ -1305,4 +1305,10 @@ public class TesterContext implements Context {
public boolean getParallelAnnotationScanning() { return false; }
@Override
public void setParallelAnnotationScanning(boolean
parallelAnnotationScanning) {}
+
+ @Override
+ public boolean getMetadataComplete() { return false; }
+ @Override
+ public void setMetadataComplete(boolean metadataComplete) { /* NO-OP */ }
+
}
diff --git a/webapps/docs/META-INF/context.xml
b/webapps/docs/META-INF/context.xml
index 28ae2ddce0..b605411ce6 100644
--- a/webapps/docs/META-INF/context.xml
+++ b/webapps/docs/META-INF/context.xml
@@ -15,4 +15,4 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-<Context antiResourceLocking="false" />
+<Context antiResourceLocking="false" ignoreAnnotations="true"/>
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 0780339626..00e820c824 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -175,6 +175,10 @@
Add support for the new attribute for error dispatches
<code>jakarta.servlet.error.query_string</code>. (markt)
</add>
+ <update>
+ Update <code>ignoreAnnotation</code> attribute on <code>Context</code>
+ to dissociate it from <code>metadata-complete</code>. (remm)
+ </update>
</changelog>
</subsection>
<subsection name="Coyote">
diff --git a/webapps/docs/config/context.xml b/webapps/docs/config/context.xml
index fa4ec3599f..e5aa73f86d 100644
--- a/webapps/docs/config/context.xml
+++ b/webapps/docs/config/context.xml
@@ -426,6 +426,13 @@
used.</p>
</attribute>
+ <attribute name="ignoreAnnotations" required="false">
+ <p>Set to <code>true</code> to have Tomcat ignore all annotations
+ present on classes.</p>
+ <p>If not specified, the default value of <code>false</code> is
+ used.</p>
+ </attribute>
+
<attribute name="logEffectiveWebXml" required="false">
<p>Set to <code>true</code> if you want the effective web.xml used for
a
web application to be logged (at INFO level) when the application
diff --git a/webapps/examples/META-INF/context.xml
b/webapps/examples/META-INF/context.xml
index b6c932da14..31e7fb601e 100644
--- a/webapps/examples/META-INF/context.xml
+++ b/webapps/examples/META-INF/context.xml
@@ -15,7 +15,7 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-<Context>
+<Context ignoreAnnotations="true">
<CookieProcessor
className="org.apache.tomcat.util.http.Rfc6265CookieProcessor"
sameSiteCookies="strict" />
</Context>
diff --git a/webapps/host-manager/META-INF/context.xml
b/webapps/host-manager/META-INF/context.xml
index 1fa3a5ae8d..6074c87a5e 100644
--- a/webapps/host-manager/META-INF/context.xml
+++ b/webapps/host-manager/META-INF/context.xml
@@ -15,7 +15,7 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-<Context antiResourceLocking="false" privileged="true" >
+<Context antiResourceLocking="false" privileged="true"
ignoreAnnotations="true">
<CookieProcessor
className="org.apache.tomcat.util.http.Rfc6265CookieProcessor"
sameSiteCookies="strict" />
<Valve className="org.apache.catalina.valves.RemoteAddrValve"
diff --git a/webapps/manager/META-INF/context.xml
b/webapps/manager/META-INF/context.xml
index 120b7ab61a..e88e00d485 100644
--- a/webapps/manager/META-INF/context.xml
+++ b/webapps/manager/META-INF/context.xml
@@ -15,7 +15,7 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-<Context antiResourceLocking="false" privileged="true" >
+<Context antiResourceLocking="false" privileged="true"
ignoreAnnotations="true">
<CookieProcessor
className="org.apache.tomcat.util.http.Rfc6265CookieProcessor"
sameSiteCookies="strict" />
<Valve className="org.apache.catalina.valves.RemoteAddrValve"
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]