Skip to content

Commit 72f20e8

Browse files
committed
Polishing
1 parent 87375fe commit 72f20e8

File tree

5 files changed

+42
-28
lines changed

5 files changed

+42
-28
lines changed

spring-web/src/main/java/org/springframework/http/server/reactive/AbstractServerHttpRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ public SslInfo getSslInfo() {
166166

167167
/**
168168
* Obtain SSL session information from the underlying "native" request.
169-
* @return the SSL information or {@code null} if not available
169+
* @return the session information, or {@code null} if none available
170170
* @since 5.0.2
171171
*/
172172
@Nullable

spring-web/src/main/java/org/springframework/http/server/reactive/DefaultSslInfo.java

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,23 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package org.springframework.http.server.reactive;
1718

1819
import java.security.cert.Certificate;
1920
import java.security.cert.X509Certificate;
2021
import java.util.ArrayList;
2122
import java.util.List;
22-
2323
import javax.net.ssl.SSLSession;
2424

2525
import org.springframework.lang.Nullable;
2626
import org.springframework.util.Assert;
2727

2828
/**
29+
* The default holder for SSL session information.
2930
*
3031
* @author Rossen Stoyanchev
31-
* @since 5.0
32+
* @since 5.0.2
3233
*/
3334
final class DefaultSslInfo implements SslInfo {
3435

@@ -50,12 +51,26 @@ final class DefaultSslInfo implements SslInfo {
5051
this.peerCertificates = initCertificates(session);
5152
}
5253

54+
55+
@Override
56+
@Nullable
57+
public String getSessionId() {
58+
return this.sessionId;
59+
}
60+
61+
@Override
62+
public X509Certificate[] getPeerCertificates() {
63+
return this.peerCertificates;
64+
}
65+
66+
5367
@Nullable
5468
private static String initSessionId(SSLSession session) {
5569
byte [] bytes = session.getId();
5670
if (bytes == null) {
5771
return null;
5872
}
73+
5974
StringBuilder sb = new StringBuilder();
6075
for (byte b : bytes) {
6176
String digit = Integer.toHexString(b);
@@ -78,6 +93,7 @@ private static X509Certificate[] initCertificates(SSLSession session) {
7893
catch (Throwable ex) {
7994
throw new IllegalStateException("Failed to get SSL certificates", ex);
8095
}
96+
8197
List<X509Certificate> result = new ArrayList<>(certificates.length);
8298
for (Certificate certificate : certificates) {
8399
if (certificate instanceof X509Certificate) {
@@ -87,16 +103,4 @@ private static X509Certificate[] initCertificates(SSLSession session) {
87103
return result.toArray(new X509Certificate[result.size()]);
88104
}
89105

90-
91-
@Override
92-
@Nullable
93-
public String getSessionId() {
94-
return this.sessionId;
95-
}
96-
97-
@Override
98-
public X509Certificate[] getPeerCertificates() {
99-
return this.peerCertificates;
100-
}
101-
102106
}

spring-web/src/main/java/org/springframework/http/server/reactive/ServerHttpRequest.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,20 @@ public interface ServerHttpRequest extends HttpRequest, ReactiveHttpInputMessage
5959
* Return the remote address where this request is connected to, if available.
6060
*/
6161
@Nullable
62-
InetSocketAddress getRemoteAddress();
62+
default InetSocketAddress getRemoteAddress() {
63+
return null;
64+
}
6365

6466
/**
6567
* Return the SSL session information if the request has been transmitted
6668
* over a secure protocol including SSL certificates, if available.
67-
* @return the session information or {@code null}
69+
* @return the session information, or {@code null} if none available
6870
* @since 5.0.2
6971
*/
7072
@Nullable
71-
SslInfo getSslInfo();
73+
default SslInfo getSslInfo() {
74+
return null;
75+
}
7276

7377
/**
7478
* Return a builder to mutate properties of this request by wrapping it

spring-web/src/main/java/org/springframework/http/server/reactive/SslInfo.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,30 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package org.springframework.http.server.reactive;
1718

1819
import java.security.cert.X509Certificate;
1920

2021
import org.springframework.lang.Nullable;
2122

2223
/**
24+
* A holder for SSL session information.
2325
*
2426
* @author Rossen Stoyanchev
2527
* @since 5.0.2
2628
*/
2729
public interface SslInfo {
2830

31+
/**
32+
* Return the SSL session id, if any
33+
*/
2934
@Nullable
3035
String getSessionId();
3136

37+
/**
38+
* Return the associated SSL certificates.
39+
*/
3240
X509Certificate[] getPeerCertificates();
3341

3442
}

spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ResourceHandlerRegistry.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,11 @@ public ResourceHandlerRegistry(ApplicationContext applicationContext, ServletCon
9393
/**
9494
* A variant of
9595
* {@link #ResourceHandlerRegistry(ApplicationContext, ServletContext, ContentNegotiationManager)}
96-
* that also accepts the {@link UrlPathHelper} used for mapping requests
97-
* to static resources.
96+
* that also accepts the {@link UrlPathHelper} used for mapping requests to static resources.
9897
* @since 4.3.13
9998
*/
10099
public ResourceHandlerRegistry(ApplicationContext applicationContext, ServletContext servletContext,
101-
ContentNegotiationManager contentNegotiationManager, @Nullable UrlPathHelper pathHelper) {
100+
@Nullable ContentNegotiationManager contentNegotiationManager, @Nullable UrlPathHelper pathHelper) {
102101

103102
Assert.notNull(applicationContext, "ApplicationContext is required");
104103
this.applicationContext = applicationContext;
@@ -109,13 +108,12 @@ public ResourceHandlerRegistry(ApplicationContext applicationContext, ServletCon
109108

110109

111110
/**
112-
* Add a resource handler for serving static resources based on the specified URL path
113-
* patterns. The handler will be invoked for every incoming request that matches to
114-
* one of the specified path patterns.
115-
* <p>Patterns like {@code "/static/**"} or {@code "/css/{filename:\\w+\\.css}"}
116-
* are allowed. See {@link org.springframework.util.AntPathMatcher} for more details on the
117-
* syntax.
118-
* @return A {@link ResourceHandlerRegistration} to use to further configure the
111+
* Add a resource handler for serving static resources based on the specified URL path patterns.
112+
* The handler will be invoked for every incoming request that matches to one of the specified
113+
* path patterns.
114+
* <p>Patterns like {@code "/static/**"} or {@code "/css/{filename:\\w+\\.css}"} are allowed.
115+
* See {@link org.springframework.util.AntPathMatcher} for more details on the syntax.
116+
* @return a {@link ResourceHandlerRegistration} to use to further configure the
119117
* registered resource handler
120118
*/
121119
public ResourceHandlerRegistration addResourceHandler(String... pathPatterns) {

0 commit comments

Comments
 (0)