Skip to content

Commit 45f09df

Browse files
committed
Merge branch '3.2.x'
Closes gh-40996
2 parents 935ce87 + d4e9f45 commit 45f09df

File tree

3 files changed

+300
-158
lines changed

3 files changed

+300
-158
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/JettyServletWebServerFactory.java

Lines changed: 0 additions & 158 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,18 @@
1717
package org.springframework.boot.web.embedded.jetty;
1818

1919
import java.io.File;
20-
import java.io.IOException;
21-
import java.io.InputStream;
2220
import java.net.InetSocketAddress;
23-
import java.net.URI;
2421
import java.net.URL;
25-
import java.nio.channels.ReadableByteChannel;
26-
import java.nio.file.Path;
2722
import java.time.Duration;
28-
import java.time.Instant;
2923
import java.util.ArrayList;
3024
import java.util.Arrays;
3125
import java.util.Collection;
3226
import java.util.EventListener;
33-
import java.util.Iterator;
3427
import java.util.LinkedHashSet;
3528
import java.util.List;
3629
import java.util.Objects;
3730
import java.util.Set;
38-
import java.util.Spliterator;
3931
import java.util.UUID;
40-
import java.util.function.Consumer;
4132

4233
import jakarta.servlet.http.Cookie;
4334
import org.eclipse.jetty.ee10.servlet.ErrorHandler;
@@ -79,7 +70,6 @@
7970
import org.eclipse.jetty.session.FileSessionDataStore;
8071
import org.eclipse.jetty.session.SessionConfig;
8172
import org.eclipse.jetty.util.Callback;
82-
import org.eclipse.jetty.util.resource.CombinedResource;
8373
import org.eclipse.jetty.util.resource.Resource;
8474
import org.eclipse.jetty.util.resource.ResourceFactory;
8575
import org.eclipse.jetty.util.resource.URLResourceFactory;
@@ -594,154 +584,6 @@ private void addJettyErrorPages(ErrorHandler errorHandler, Collection<ErrorPage>
594584
}
595585
}
596586

597-
private static final class LoaderHidingResource extends Resource {
598-
599-
private static final String LOADER_RESOURCE_PATH_PREFIX = "/org/springframework/boot/";
600-
601-
private final Resource base;
602-
603-
private final Resource delegate;
604-
605-
private LoaderHidingResource(Resource base, Resource delegate) {
606-
this.base = base;
607-
this.delegate = delegate;
608-
}
609-
610-
@Override
611-
public void forEach(Consumer<? super Resource> action) {
612-
this.delegate.forEach(action);
613-
}
614-
615-
@Override
616-
public Path getPath() {
617-
return this.delegate.getPath();
618-
}
619-
620-
@Override
621-
public boolean isContainedIn(Resource r) {
622-
return this.delegate.isContainedIn(r);
623-
}
624-
625-
@Override
626-
public Iterator<Resource> iterator() {
627-
if (this.delegate instanceof CombinedResource) {
628-
return list().iterator();
629-
}
630-
return List.<Resource>of(this).iterator();
631-
}
632-
633-
@Override
634-
public boolean equals(Object obj) {
635-
return this.delegate.equals(obj);
636-
}
637-
638-
@Override
639-
public int hashCode() {
640-
return this.delegate.hashCode();
641-
}
642-
643-
@Override
644-
public boolean exists() {
645-
return this.delegate.exists();
646-
}
647-
648-
@Override
649-
public Spliterator<Resource> spliterator() {
650-
return this.delegate.spliterator();
651-
}
652-
653-
@Override
654-
public boolean isDirectory() {
655-
return this.delegate.isDirectory();
656-
}
657-
658-
@Override
659-
public boolean isReadable() {
660-
return this.delegate.isReadable();
661-
}
662-
663-
@Override
664-
public Instant lastModified() {
665-
return this.delegate.lastModified();
666-
}
667-
668-
@Override
669-
public long length() {
670-
return this.delegate.length();
671-
}
672-
673-
@Override
674-
public URI getURI() {
675-
return this.delegate.getURI();
676-
}
677-
678-
@Override
679-
public String getName() {
680-
return this.delegate.getName();
681-
}
682-
683-
@Override
684-
public String getFileName() {
685-
return this.delegate.getFileName();
686-
}
687-
688-
@Override
689-
public InputStream newInputStream() throws IOException {
690-
return this.delegate.newInputStream();
691-
}
692-
693-
@Override
694-
@SuppressWarnings({ "deprecation", "removal" })
695-
public ReadableByteChannel newReadableByteChannel() throws IOException {
696-
return this.delegate.newReadableByteChannel();
697-
}
698-
699-
@Override
700-
public List<Resource> list() {
701-
return this.delegate.list().stream().filter(this::nonLoaderResource).toList();
702-
}
703-
704-
private boolean nonLoaderResource(Resource resource) {
705-
Path prefix = this.base.getPath().resolve(Path.of("org", "springframework", "boot"));
706-
return !resource.getPath().startsWith(prefix);
707-
}
708-
709-
@Override
710-
public Resource resolve(String subUriPath) {
711-
if (subUriPath.startsWith(LOADER_RESOURCE_PATH_PREFIX)) {
712-
return null;
713-
}
714-
Resource resolved = this.delegate.resolve(subUriPath);
715-
return (resolved != null) ? new LoaderHidingResource(this.base, resolved) : null;
716-
}
717-
718-
@Override
719-
public boolean isAlias() {
720-
return this.delegate.isAlias();
721-
}
722-
723-
@Override
724-
public URI getRealURI() {
725-
return this.delegate.getRealURI();
726-
}
727-
728-
@Override
729-
public void copyTo(Path destination) throws IOException {
730-
this.delegate.copyTo(destination);
731-
}
732-
733-
@Override
734-
public Collection<Resource> getAllResources() {
735-
return this.delegate.getAllResources().stream().filter(this::nonLoaderResource).toList();
736-
}
737-
738-
@Override
739-
public String toString() {
740-
return this.delegate.toString();
741-
}
742-
743-
}
744-
745587
/**
746588
* {@link AbstractConfiguration} to apply {@code @WebListener} classes.
747589
*/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
/*
2+
* Copyright 2012-2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.web.embedded.jetty;
18+
19+
import java.io.IOException;
20+
import java.io.InputStream;
21+
import java.net.URI;
22+
import java.nio.channels.ReadableByteChannel;
23+
import java.nio.file.Path;
24+
import java.time.Instant;
25+
import java.util.Collection;
26+
import java.util.Iterator;
27+
import java.util.List;
28+
import java.util.Spliterator;
29+
import java.util.function.Consumer;
30+
31+
import org.eclipse.jetty.util.resource.CombinedResource;
32+
import org.eclipse.jetty.util.resource.Resource;
33+
34+
/**
35+
* A custom {@link Resource} that hides Spring Boot's loader classes, preventing them from
36+
* being served over HTTP.
37+
*
38+
* @author Andy Wilkinson
39+
*/
40+
final class LoaderHidingResource extends Resource {
41+
42+
private static final String LOADER_RESOURCE_PATH_PREFIX = "/org/springframework/boot/";
43+
44+
private final Path loaderBasePath;
45+
46+
private final Resource base;
47+
48+
private final Resource delegate;
49+
50+
LoaderHidingResource(Resource base, Resource delegate) {
51+
this.base = base;
52+
this.delegate = delegate;
53+
this.loaderBasePath = base.getPath().getFileSystem().getPath("/", "org", "springframework", "boot");
54+
}
55+
56+
@Override
57+
public void forEach(Consumer<? super Resource> action) {
58+
this.delegate.forEach(action);
59+
}
60+
61+
@Override
62+
public Path getPath() {
63+
return this.delegate.getPath();
64+
}
65+
66+
@Override
67+
public boolean isContainedIn(Resource r) {
68+
return this.delegate.isContainedIn(r);
69+
}
70+
71+
@Override
72+
public Iterator<Resource> iterator() {
73+
if (this.delegate instanceof CombinedResource) {
74+
return list().iterator();
75+
}
76+
return List.<Resource>of(this).iterator();
77+
}
78+
79+
@Override
80+
public boolean equals(Object obj) {
81+
return this.delegate.equals(obj);
82+
}
83+
84+
@Override
85+
public int hashCode() {
86+
return this.delegate.hashCode();
87+
}
88+
89+
@Override
90+
public boolean exists() {
91+
return this.delegate.exists();
92+
}
93+
94+
@Override
95+
public Spliterator<Resource> spliterator() {
96+
return this.delegate.spliterator();
97+
}
98+
99+
@Override
100+
public boolean isDirectory() {
101+
return this.delegate.isDirectory();
102+
}
103+
104+
@Override
105+
public boolean isReadable() {
106+
return this.delegate.isReadable();
107+
}
108+
109+
@Override
110+
public Instant lastModified() {
111+
return this.delegate.lastModified();
112+
}
113+
114+
@Override
115+
public long length() {
116+
return this.delegate.length();
117+
}
118+
119+
@Override
120+
public URI getURI() {
121+
return this.delegate.getURI();
122+
}
123+
124+
@Override
125+
public String getName() {
126+
return this.delegate.getName();
127+
}
128+
129+
@Override
130+
public String getFileName() {
131+
return this.delegate.getFileName();
132+
}
133+
134+
@Override
135+
public InputStream newInputStream() throws IOException {
136+
return this.delegate.newInputStream();
137+
}
138+
139+
@Override
140+
@SuppressWarnings({ "deprecation", "removal" })
141+
public ReadableByteChannel newReadableByteChannel() throws IOException {
142+
return this.delegate.newReadableByteChannel();
143+
}
144+
145+
@Override
146+
public List<Resource> list() {
147+
return asLoaderHidingResources(this.delegate.list());
148+
}
149+
150+
private boolean nonLoaderResource(Resource resource) {
151+
return !resource.getPath().startsWith(this.loaderBasePath);
152+
}
153+
154+
private List<Resource> asLoaderHidingResources(Collection<Resource> resources) {
155+
return resources.stream().filter(this::nonLoaderResource).map(this::asLoaderHidingResource).toList();
156+
}
157+
158+
private Resource asLoaderHidingResource(Resource resource) {
159+
return (resource instanceof LoaderHidingResource) ? resource : new LoaderHidingResource(this.base, resource);
160+
}
161+
162+
@Override
163+
public Resource resolve(String subUriPath) {
164+
if (subUriPath.startsWith(LOADER_RESOURCE_PATH_PREFIX)) {
165+
return null;
166+
}
167+
Resource resolved = this.delegate.resolve(subUriPath);
168+
return (resolved != null) ? new LoaderHidingResource(this.base, resolved) : null;
169+
}
170+
171+
@Override
172+
public boolean isAlias() {
173+
return this.delegate.isAlias();
174+
}
175+
176+
@Override
177+
public URI getRealURI() {
178+
return this.delegate.getRealURI();
179+
}
180+
181+
@Override
182+
public void copyTo(Path destination) throws IOException {
183+
this.delegate.copyTo(destination);
184+
}
185+
186+
@Override
187+
public Collection<Resource> getAllResources() {
188+
return asLoaderHidingResources(this.delegate.getAllResources());
189+
}
190+
191+
@Override
192+
public String toString() {
193+
return this.delegate.toString();
194+
}
195+
196+
}

0 commit comments

Comments
 (0)