From 72f20e8d4f6ce1000bc59662ba235ab56094b0e4 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Sat, 11 Nov 2017 00:37:50 +0100 Subject: [PATCH] Polishing --- .../reactive/AbstractServerHttpRequest.java | 2 +- .../http/server/reactive/DefaultSslInfo.java | 32 +++++++++++-------- .../server/reactive/ServerHttpRequest.java | 10 ++++-- .../http/server/reactive/SslInfo.java | 8 +++++ .../annotation/ResourceHandlerRegistry.java | 18 +++++------ 5 files changed, 42 insertions(+), 28 deletions(-) diff --git a/spring-web/src/main/java/org/springframework/http/server/reactive/AbstractServerHttpRequest.java b/spring-web/src/main/java/org/springframework/http/server/reactive/AbstractServerHttpRequest.java index a7fd365918e..454900d8588 100644 --- a/spring-web/src/main/java/org/springframework/http/server/reactive/AbstractServerHttpRequest.java +++ b/spring-web/src/main/java/org/springframework/http/server/reactive/AbstractServerHttpRequest.java @@ -166,7 +166,7 @@ public abstract class AbstractServerHttpRequest implements ServerHttpRequest { /** * Obtain SSL session information from the underlying "native" request. - * @return the SSL information or {@code null} if not available + * @return the session information, or {@code null} if none available * @since 5.0.2 */ @Nullable diff --git a/spring-web/src/main/java/org/springframework/http/server/reactive/DefaultSslInfo.java b/spring-web/src/main/java/org/springframework/http/server/reactive/DefaultSslInfo.java index 02b34ef93cc..f63dfc486c4 100644 --- a/spring-web/src/main/java/org/springframework/http/server/reactive/DefaultSslInfo.java +++ b/spring-web/src/main/java/org/springframework/http/server/reactive/DefaultSslInfo.java @@ -13,22 +13,23 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.http.server.reactive; import java.security.cert.Certificate; import java.security.cert.X509Certificate; import java.util.ArrayList; import java.util.List; - import javax.net.ssl.SSLSession; import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** + * The default holder for SSL session information. * * @author Rossen Stoyanchev - * @since 5.0 + * @since 5.0.2 */ final class DefaultSslInfo implements SslInfo { @@ -50,12 +51,26 @@ final class DefaultSslInfo implements SslInfo { this.peerCertificates = initCertificates(session); } + + @Override + @Nullable + public String getSessionId() { + return this.sessionId; + } + + @Override + public X509Certificate[] getPeerCertificates() { + return this.peerCertificates; + } + + @Nullable private static String initSessionId(SSLSession session) { byte [] bytes = session.getId(); if (bytes == null) { return null; } + StringBuilder sb = new StringBuilder(); for (byte b : bytes) { String digit = Integer.toHexString(b); @@ -78,6 +93,7 @@ final class DefaultSslInfo implements SslInfo { catch (Throwable ex) { throw new IllegalStateException("Failed to get SSL certificates", ex); } + List result = new ArrayList<>(certificates.length); for (Certificate certificate : certificates) { if (certificate instanceof X509Certificate) { @@ -87,16 +103,4 @@ final class DefaultSslInfo implements SslInfo { return result.toArray(new X509Certificate[result.size()]); } - - @Override - @Nullable - public String getSessionId() { - return this.sessionId; - } - - @Override - public X509Certificate[] getPeerCertificates() { - return this.peerCertificates; - } - } diff --git a/spring-web/src/main/java/org/springframework/http/server/reactive/ServerHttpRequest.java b/spring-web/src/main/java/org/springframework/http/server/reactive/ServerHttpRequest.java index 85370a960f2..426ae7eb7e5 100644 --- a/spring-web/src/main/java/org/springframework/http/server/reactive/ServerHttpRequest.java +++ b/spring-web/src/main/java/org/springframework/http/server/reactive/ServerHttpRequest.java @@ -59,16 +59,20 @@ public interface ServerHttpRequest extends HttpRequest, ReactiveHttpInputMessage * Return the remote address where this request is connected to, if available. */ @Nullable - InetSocketAddress getRemoteAddress(); + default InetSocketAddress getRemoteAddress() { + return null; + } /** * Return the SSL session information if the request has been transmitted * over a secure protocol including SSL certificates, if available. - * @return the session information or {@code null} + * @return the session information, or {@code null} if none available * @since 5.0.2 */ @Nullable - SslInfo getSslInfo(); + default SslInfo getSslInfo() { + return null; + } /** * Return a builder to mutate properties of this request by wrapping it diff --git a/spring-web/src/main/java/org/springframework/http/server/reactive/SslInfo.java b/spring-web/src/main/java/org/springframework/http/server/reactive/SslInfo.java index 58eeee2ab5e..d14881babed 100644 --- a/spring-web/src/main/java/org/springframework/http/server/reactive/SslInfo.java +++ b/spring-web/src/main/java/org/springframework/http/server/reactive/SslInfo.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.http.server.reactive; import java.security.cert.X509Certificate; @@ -20,15 +21,22 @@ import java.security.cert.X509Certificate; import org.springframework.lang.Nullable; /** + * A holder for SSL session information. * * @author Rossen Stoyanchev * @since 5.0.2 */ public interface SslInfo { + /** + * Return the SSL session id, if any + */ @Nullable String getSessionId(); + /** + * Return the associated SSL certificates. + */ X509Certificate[] getPeerCertificates(); } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ResourceHandlerRegistry.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ResourceHandlerRegistry.java index 6ba5272f560..47638889b7d 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ResourceHandlerRegistry.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ResourceHandlerRegistry.java @@ -93,12 +93,11 @@ public class ResourceHandlerRegistry { /** * A variant of * {@link #ResourceHandlerRegistry(ApplicationContext, ServletContext, ContentNegotiationManager)} - * that also accepts the {@link UrlPathHelper} used for mapping requests - * to static resources. + * that also accepts the {@link UrlPathHelper} used for mapping requests to static resources. * @since 4.3.13 */ public ResourceHandlerRegistry(ApplicationContext applicationContext, ServletContext servletContext, - ContentNegotiationManager contentNegotiationManager, @Nullable UrlPathHelper pathHelper) { + @Nullable ContentNegotiationManager contentNegotiationManager, @Nullable UrlPathHelper pathHelper) { Assert.notNull(applicationContext, "ApplicationContext is required"); this.applicationContext = applicationContext; @@ -109,13 +108,12 @@ public class ResourceHandlerRegistry { /** - * Add a resource handler for serving static resources based on the specified URL path - * patterns. The handler will be invoked for every incoming request that matches to - * one of the specified path patterns. - *

Patterns like {@code "/static/**"} or {@code "/css/{filename:\\w+\\.css}"} - * are allowed. See {@link org.springframework.util.AntPathMatcher} for more details on the - * syntax. - * @return A {@link ResourceHandlerRegistration} to use to further configure the + * Add a resource handler for serving static resources based on the specified URL path patterns. + * The handler will be invoked for every incoming request that matches to one of the specified + * path patterns. + *

Patterns like {@code "/static/**"} or {@code "/css/{filename:\\w+\\.css}"} are allowed. + * See {@link org.springframework.util.AntPathMatcher} for more details on the syntax. + * @return a {@link ResourceHandlerRegistration} to use to further configure the * registered resource handler */ public ResourceHandlerRegistration addResourceHandler(String... pathPatterns) {