Polishing
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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<X509Certificate> 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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();
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user