From 87ee2ddaa7a933c69dc828944553da875dfa3a58 Mon Sep 17 00:00:00 2001 From: Jan Bartel Date: Wed, 30 Sep 2020 15:50:26 +0200 Subject: [PATCH] Issue #5360 Add more origin info to quickstart-web.xml elements Signed-off-by: Jan Bartel --- .../DeclareRolesAnnotationHandler.java | 1 + .../annotations/WebFilterAnnotation.java | 4 +-- .../annotations/WebServletAnnotation.java | 4 ++- .../QuickStartGeneratorConfiguration.java | 9 ++--- .../webapp/StandardDescriptorProcessor.java | 36 +++++++++++-------- 5 files changed, 32 insertions(+), 22 deletions(-) diff --git a/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/DeclareRolesAnnotationHandler.java b/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/DeclareRolesAnnotationHandler.java index 72604d851ce1..78197f9e9df5 100644 --- a/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/DeclareRolesAnnotationHandler.java +++ b/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/DeclareRolesAnnotationHandler.java @@ -63,6 +63,7 @@ public void doHandle(Class clazz) for (String r : roles) { ((ConstraintSecurityHandler)_context.getSecurityHandler()).addRole(r); + _context.getMetaData().setOrigin("security-role." + r, declareRoles, clazz); } } } diff --git a/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/WebFilterAnnotation.java b/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/WebFilterAnnotation.java index bbad4bfadb7b..6754053c7f7b 100644 --- a/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/WebFilterAnnotation.java +++ b/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/WebFilterAnnotation.java @@ -108,7 +108,7 @@ public void apply() FilterMapping mapping = new FilterMapping(); mapping.setFilterName(holder.getName()); - + metaData.setOrigin(name + ".filter.mapping." + mapping.hashCode(), filterAnnotation, clazz); if (urlPatterns.length > 0) { ArrayList paths = new ArrayList(); @@ -179,7 +179,7 @@ public void apply() { FilterMapping mapping = new FilterMapping(); mapping.setFilterName(holder.getName()); - + metaData.setOrigin(holder.getName() + ".filter.mapping." + mapping.hashCode(), filterAnnotation, clazz); if (urlPatterns.length > 0) { ArrayList paths = new ArrayList(); diff --git a/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/WebServletAnnotation.java b/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/WebServletAnnotation.java index 22d639a4645d..25a79c2de05a 100644 --- a/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/WebServletAnnotation.java +++ b/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/WebServletAnnotation.java @@ -154,6 +154,7 @@ public void apply() mapping = new ServletMapping(source); mapping.setServletName(holder.getName()); mapping.setPathSpecs(LazyList.toStringArray(urlPatternList)); + _context.getMetaData().setOrigin(servletName + ".servlet.mapping." + mapping.hashCode(), annotation, clazz); } else { @@ -190,6 +191,7 @@ public void apply() mapping = new ServletMapping(new Source(Source.Origin.ANNOTATION, clazz.getName())); mapping.setServletName(servletName); mapping.setPathSpecs(LazyList.toStringArray(urlPatternList)); + _context.getMetaData().setOrigin(servletName + ".servlet.mapping." + mapping.hashCode(), annotation, clazz); } } @@ -228,7 +230,7 @@ public void apply() LOG.debug("Removed path {} from mapping {} from defaults descriptor ", p, existingMapping); } } - _context.getMetaData().setOrigin(servletName + ".servlet.mapping." + p, annotation, clazz); + _context.getMetaData().setOrigin(servletName + ".servlet.mapping.url" + p, annotation, clazz); } allMappings.add(mapping); _context.getServletHandler().setServletMappings(allMappings.toArray(new ServletMapping[allMappings.size()])); diff --git a/jetty-quickstart/src/main/java/org/eclipse/jetty/quickstart/QuickStartGeneratorConfiguration.java b/jetty-quickstart/src/main/java/org/eclipse/jetty/quickstart/QuickStartGeneratorConfiguration.java index 2ab4c033c686..2324cd119168 100644 --- a/jetty-quickstart/src/main/java/org/eclipse/jetty/quickstart/QuickStartGeneratorConfiguration.java +++ b/jetty-quickstart/src/main/java/org/eclipse/jetty/quickstart/QuickStartGeneratorConfiguration.java @@ -241,7 +241,7 @@ public void generateQuickStartWebXml(WebAppContext context, OutputStream stream) if (f != null && f.getSource() == Source.EMBEDDED) continue; - out.openTag("filter-mapping"); + out.openTag("filter-mapping", origin(md, mapping.getFilterName() + ".filter.mapping." + mapping.hashCode())); out.tag("filter-name", mapping.getFilterName()); if (mapping.getPathSpecs() != null) for (String s : mapping.getPathSpecs()) @@ -289,7 +289,7 @@ public void generateQuickStartWebXml(WebAppContext context, OutputStream stream) if (sh != null && sh.getSource() == Source.EMBEDDED) continue; - out.openTag("servlet-mapping", origin(md, mapping.getServletName() + ".servlet.mappings")); + out.openTag("servlet-mapping", origin(md, mapping.getServletName() + ".servlet.mapping." + mapping.hashCode())); out.tag("servlet-name", mapping.getServletName()); if (mapping.getPathSpecs() != null) for (String s : mapping.getPathSpecs()) @@ -327,7 +327,7 @@ public void generateQuickStartWebXml(WebAppContext context, OutputStream stream) ConstraintAware ca = (ConstraintAware)security; for (String r : ca.getRoles()) { - out.openTag("security-role") + out.openTag("security-role", origin(md, "security-role." + r)) .tag("role-name", r) .closeTag(); } @@ -398,7 +398,7 @@ public void generateQuickStartWebXml(WebAppContext context, OutputStream stream) out.openTag("welcome-file-list"); for (String welcomeFile : context.getWelcomeFiles()) { - out.tag("welcome-file", welcomeFile); + out.tag("welcome-file", origin(md, "welcome-file." + welcomeFile), welcomeFile); } out.closeTag(); } @@ -429,6 +429,7 @@ public void generateQuickStartWebXml(WebAppContext context, OutputStream stream) if (cookieConfig != null) { out.openTag("cookie-config"); + if (cookieConfig.getName() != null) out.tag("name", origin(md, "cookie-config.name"), cookieConfig.getName()); diff --git a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/StandardDescriptorProcessor.java b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/StandardDescriptorProcessor.java index 09f8a8653989..19373374eeb8 100644 --- a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/StandardDescriptorProcessor.java +++ b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/StandardDescriptorProcessor.java @@ -663,6 +663,7 @@ public void visitSessionConfig(WebAppContext context, Descriptor descriptor, Xml if (TimeUnit.MINUTES.toSeconds(mins) > Integer.MAX_VALUE) throw new IllegalStateException("Max session-timeout in minutes is " + TimeUnit.SECONDS.toMinutes(Integer.MAX_VALUE)); context.getServletContext().setSessionTimeout((int)mins); + context.getMetaData().setOrigin("session.timeout", descriptor); } //Servlet Spec 3.0 @@ -672,7 +673,7 @@ public void visitSessionConfig(WebAppContext context, Descriptor descriptor, Xml if (iter.hasNext()) { Set modes = null; - Origin o = context.getMetaData().getOrigin("session.tracking-mode"); + Origin o = context.getMetaData().getOrigin("session.tracking-modes"); switch (o) { case NotSet://not previously set, starting fresh @@ -680,7 +681,7 @@ public void visitSessionConfig(WebAppContext context, Descriptor descriptor, Xml { modes = new HashSet(); - context.getMetaData().setOrigin("session.tracking-mode", descriptor); + context.getMetaData().setOrigin("session.tracking-modes", descriptor); break; } case WebXml: @@ -692,7 +693,7 @@ public void visitSessionConfig(WebAppContext context, Descriptor descriptor, Xml modes = new HashSet(); else modes = new HashSet(context.getSessionHandler().getEffectiveSessionTrackingModes()); - context.getMetaData().setOrigin("session.tracking-mode", descriptor); + context.getMetaData().setOrigin("session.tracking-modes", descriptor); break; } default: @@ -703,7 +704,9 @@ public void visitSessionConfig(WebAppContext context, Descriptor descriptor, Xml { XmlParser.Node mNode = (XmlParser.Node)iter.next(); String trackMode = mNode.toString(false, true); - modes.add(SessionTrackingMode.valueOf(trackMode)); + SessionTrackingMode mode = SessionTrackingMode.valueOf(trackMode); + modes.add(mode); + context.getMetaData().setOrigin("session.tracking-mode." + mode, descriptor); } context.getSessionHandler().setSessionTrackingModes(modes); } @@ -1035,13 +1038,13 @@ public void visitWelcomeFileList(WebAppContext context, Descriptor descriptor, X case NotSet: { context.getMetaData().setOrigin("welcome-file-list", descriptor); - addWelcomeFiles(context, node); + addWelcomeFiles(context, node, descriptor); break; } case WebXml: { //web.xml set the welcome-file-list, all other descriptors then just merge in - addWelcomeFiles(context, node); + addWelcomeFiles(context, node, descriptor); break; } case WebDefaults: @@ -1052,19 +1055,19 @@ public void visitWelcomeFileList(WebAppContext context, Descriptor descriptor, X { context.setWelcomeFiles(new String[0]); } - addWelcomeFiles(context, node); + addWelcomeFiles(context, node, descriptor); break; } case WebOverride: { //web-override set the list, all other descriptors just merge in - addWelcomeFiles(context, node); + addWelcomeFiles(context, node, descriptor); break; } case WebFragment: { //A web-fragment first set the welcome-file-list. Other descriptors just add. - addWelcomeFiles(context, node); + addWelcomeFiles(context, node, descriptor); break; } default: @@ -1182,14 +1185,14 @@ public void visitErrorPage(WebAppContext context, Descriptor descriptor, XmlPars } } - public void addWelcomeFiles(WebAppContext context, XmlParser.Node node) + public void addWelcomeFiles(WebAppContext context, XmlParser.Node node, Descriptor descriptor) { Iterator iter = node.iterator("welcome-file"); while (iter.hasNext()) { XmlParser.Node indexNode = (XmlParser.Node)iter.next(); String welcome = indexNode.toString(false, true); - + context.getMetaData().setOrigin("welcome-file." + welcome, descriptor); //Servlet Spec 3.0 p. 74 welcome files are additive if (welcome != null && welcome.trim().length() > 0) context.setWelcomeFiles((String[])ArrayUtil.addToArray(context.getWelcomeFiles(), welcome, String.class)); @@ -1201,7 +1204,8 @@ public ServletMapping addServletMapping(String servletName, XmlParser.Node node, ServletMapping mapping = new ServletMapping(new Source(Source.Origin.DESCRIPTOR, descriptor.getResource().toString())); mapping.setServletName(servletName); mapping.setFromDefaultDescriptor(descriptor instanceof DefaultsDescriptor); - + context.getMetaData().setOrigin(servletName + ".servlet.mapping." + mapping.hashCode(), descriptor); + List paths = new ArrayList(); Iterator iter = node.iterator("url-pattern"); while (iter.hasNext()) @@ -1255,7 +1259,7 @@ public ServletMapping addServletMapping(String servletName, XmlParser.Node node, } paths.add(p); - context.getMetaData().setOrigin(servletName + ".servlet.mapping." + p, descriptor); + context.getMetaData().setOrigin(servletName + ".servlet.mapping.url" + p, descriptor); } mapping.setPathSpecs((String[])paths.toArray(new String[paths.size()])); @@ -1269,7 +1273,7 @@ public void addFilterMapping(String filterName, XmlParser.Node node, WebAppConte { FilterMapping mapping = new FilterMapping(); mapping.setFilterName(filterName); - + context.getMetaData().setOrigin(filterName + ".filter.mapping." + mapping.hashCode(), descriptor); List paths = new ArrayList(); Iterator iter = node.iterator("url-pattern"); while (iter.hasNext()) @@ -1277,7 +1281,7 @@ public void addFilterMapping(String filterName, XmlParser.Node node, WebAppConte String p = iter.next().toString(false, true); p = ServletPathSpec.normalize(p); paths.add(p); - context.getMetaData().setOrigin(filterName + ".filter.mapping." + p, descriptor); + context.getMetaData().setOrigin(filterName + ".filter.mapping.url" + p, descriptor); } mapping.setPathSpecs((String[])paths.toArray(new String[paths.size()])); @@ -1286,6 +1290,7 @@ public void addFilterMapping(String filterName, XmlParser.Node node, WebAppConte while (iter.hasNext()) { String n = ((XmlParser.Node)iter.next()).toString(false, true); + context.getMetaData().setOrigin(filterName + ".filter.mapping.servlet" + n, descriptor); names.add(n); } mapping.setServletNames((String[])names.toArray(new String[names.size()])); @@ -1741,6 +1746,7 @@ public void visitSecurityRole(WebAppContext context, Descriptor descriptor, XmlP XmlParser.Node roleNode = node.get("role-name"); String role = roleNode.toString(false, true); ((ConstraintAware)context.getSecurityHandler()).addRole(role); + context.getMetaData().setOrigin("security-role." + role, descriptor); } public void visitFilter(WebAppContext context, Descriptor descriptor, XmlParser.Node node)