8338380: Update TLSCommon/interop/AbstractServer to specify an interface to listen for connections

Reviewed-by: rhalade
This commit is contained in:
Matthew Donovan 2024-08-22 17:58:08 +00:00
parent 6041c936d6
commit 0b5c8870e5
2 changed files with 17 additions and 3 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -22,6 +22,8 @@
*/
import java.io.IOException;
import java.net.InetAddress;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
@ -52,11 +54,21 @@ public abstract class AbstractServer extends AbstractPeer implements Server {
public static abstract class Builder extends AbstractPeer.Builder {
private InetAddress listenInterface = InetAddress.getLoopbackAddress();
private int port;
// Indicates if requires client authentication.
private boolean clientAuth = true;
public InetAddress getListenInterface() {
return listenInterface;
}
public Builder setListenInterface(InetAddress listenInterface) {
this.listenInterface = listenInterface;
return this;
}
public int getPort() {
return port;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -22,6 +22,7 @@
*/
import java.io.IOException;
import java.net.InetAddress;
import java.net.SocketException;
import java.util.ArrayList;
import java.util.List;
@ -53,7 +54,8 @@ public class JdkServer extends AbstractServer {
context = Utilities.createSSLContext(builder.getCertTuple());
SSLServerSocketFactory serverFactory = context.getServerSocketFactory();
serverSocket
= (SSLServerSocket) serverFactory.createServerSocket(builder.getPort());
= (SSLServerSocket) serverFactory.createServerSocket(builder.getPort(),
0, builder.getListenInterface());
configServerSocket(builder);
}