Browse Source

Polishing

pull/1578/merge
Juergen Hoeller 8 years ago
parent
commit
72f20e8d4f
  1. 2
      spring-web/src/main/java/org/springframework/http/server/reactive/AbstractServerHttpRequest.java
  2. 32
      spring-web/src/main/java/org/springframework/http/server/reactive/DefaultSslInfo.java
  3. 10
      spring-web/src/main/java/org/springframework/http/server/reactive/ServerHttpRequest.java
  4. 8
      spring-web/src/main/java/org/springframework/http/server/reactive/SslInfo.java
  5. 18
      spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ResourceHandlerRegistry.java

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

@ -166,7 +166,7 @@ public abstract class AbstractServerHttpRequest implements ServerHttpRequest { @@ -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

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

@ -13,22 +13,23 @@ @@ -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 { @@ -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 { @@ -78,6 +93,7 @@ final class DefaultSslInfo implements SslInfo {
catch (Throwable ex) {
throw new IllegalStateException("Failed to get SSL certificates", ex);
}
List<X509Certificate> result = new ArrayList<>(certificates.length);
for (Certificate certificate : certificates) {
if (certificate instanceof X509Certificate) {
@ -87,16 +103,4 @@ final class DefaultSslInfo implements SslInfo { @@ -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;
}
}

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

@ -59,16 +59,20 @@ public interface ServerHttpRequest extends HttpRequest, ReactiveHttpInputMessage @@ -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

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

@ -13,6 +13,7 @@ @@ -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; @@ -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();
}

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

@ -93,12 +93,11 @@ public class ResourceHandlerRegistry { @@ -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 { @@ -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.
* <p>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.
* <p>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) {

Loading…
Cancel
Save