Class SSLServerSocket
- java.lang.Object
-
- java.net.ServerSocket
-
- javax.net.ssl.SSLServerSocket
-
- All Implemented Interfaces:
Closeable,AutoCloseable
public abstract class SSLServerSocket extends ServerSocket
This class extendsServerSockets and provides secure server sockets using protocols such as the Secure Sockets Layer (SSL) or Transport Layer Security (TLS) protocols.Instances of this class are generally created using a
SSLServerSocketFactory. The primary function ofSSLServerSockets is to createSSLSockets byaccepting connections.SSLServerSockets contain several pieces of state data which are inherited by theSSLSocketat socket creation. These include the enabled cipher suites and protocols, whether client authentication is necessary, and whether created sockets should begin handshaking in client or server mode. The state inherited by the createdSSLSocketcan be overriden by calling the appropriate methods.- Since:
- 1.4
- See Also:
ServerSocket,SSLSocket
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedSSLServerSocket()Used only by subclasses.protectedSSLServerSocket(int port)Used only by subclasses.protectedSSLServerSocket(int port, int backlog)Used only by subclasses.protectedSSLServerSocket(int port, int backlog, InetAddress address)Used only by subclasses.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description abstract booleangetNeedClientAuth()Returns true if client authentication will be required on newlyaccepted server-modeSSLSockets.abstract booleangetUseClientMode()Returns true if accepted connections will be in SSL client mode.abstract voidsetNeedClientAuth(boolean need)Controls whetheraccepted server-modeSSLSocketswill be initially configured to require client authentication.abstract voidsetUseClientMode(boolean mode)Controls whether accepted connections are in the (default) SSL server mode, or the SSL client mode.-
Methods inherited from class java.net.ServerSocket
accept, bind, bind, close, getInetAddress, getLocalPort, getLocalSocketAddress, getReceiveBufferSize, getReuseAddress, getSoTimeout, isBound, isClosed, setReceiveBufferSize, setReuseAddress, setSoTimeout, toString
-
-
-
-
Constructor Detail
-
SSLServerSocket
protected SSLServerSocket() throws IOExceptionUsed only by subclasses.Create an unbound TCP server socket using the default authentication context.
- Throws:
IOException- if an I/O error occurs when creating the socket
-
SSLServerSocket
protected SSLServerSocket(int port) throws IOExceptionUsed only by subclasses.Create a TCP server socket on a port, using the default authentication context. The connection backlog defaults to fifty connections queued up before the system starts to reject new connection requests.
A port number of
0creates a socket on any free port.If there is a security manager, its
checkListenmethod is called with theportargument as its argument to ensure the operation is allowed. This could result in a SecurityException.- Parameters:
port- the port on which to listen- Throws:
IOException- if an I/O error occurs when creating the socketSecurityException- if a security manager exists and itscheckListenmethod doesn't allow the operation.IllegalArgumentException- if the port parameter is outside the specified range of valid port values, which is between 0 and 65535, inclusive.
-
SSLServerSocket
protected SSLServerSocket(int port, int backlog) throws IOExceptionUsed only by subclasses.Create a TCP server socket on a port, using the default authentication context and a specified backlog of connections.
A port number of
0creates a socket on any free port.The
backlogargument is the requested maximum number of pending connections on the socket. Its exact semantics are implementation specific. In particular, an implementation may impose a maximum length or may choose to ignore the parameter altogther. The value provided should be greater than0. If it is less than or equal to0, then an implementation specific default will be used.If there is a security manager, its
checkListenmethod is called with theportargument as its argument to ensure the operation is allowed. This could result in a SecurityException.- Parameters:
port- the port on which to listenbacklog- requested maximum length of the queue of incoming connections.- Throws:
IOException- if an I/O error occurs when creating the socketSecurityException- if a security manager exists and itscheckListenmethod doesn't allow the operation.IllegalArgumentException- if the port parameter is outside the specified range of valid port values, which is between 0 and 65535, inclusive.
-
SSLServerSocket
protected SSLServerSocket(int port, int backlog, @Nullable InetAddress address) throws IOExceptionUsed only by subclasses.Create a TCP server socket on a port, using the default authentication context and a specified backlog of connections as well as a particular specified network interface. This constructor is used on multihomed hosts, such as those used for firewalls or as routers, to control through which interface a network service is provided.
If there is a security manager, its
checkListenmethod is called with theportargument as its argument to ensure the operation is allowed. This could result in a SecurityException.A port number of
0creates a socket on any free port.The
backlogargument is the requested maximum number of pending connections on the socket. Its exact semantics are implementation specific. In particular, an implementation may impose a maximum length or may choose to ignore the parameter altogther. The value provided should be greater than0. If it is less than or equal to0, then an implementation specific default will be used.If address is null, it will default accepting connections on any/all local addresses.
- Parameters:
port- the port on which to listenbacklog- requested maximum length of the queue of incoming connections.address- the address of the network interface through which connections will be accepted- Throws:
IOException- if an I/O error occurs when creating the socketSecurityException- if a security manager exists and itscheckListenmethod doesn't allow the operation.IllegalArgumentException- if the port parameter is outside the specified range of valid port values, which is between 0 and 65535, inclusive.
-
-
Method Detail
-
setNeedClientAuth
public abstract void setNeedClientAuth(boolean need)
Controls whetheraccepted server-modeSSLSocketswill be initially configured to require client authentication.A socket's client authentication setting is one of the following:
- client authentication required
- client authentication requested
- no client authentication desired
If the accepted socket's option is set and the client chooses not to provide authentication information about itself, the negotiations will stop and the connection will be dropped.
The initial inherited setting may be overridden by calling
SSLSocket.setNeedClientAuth(boolean)- Parameters:
need- set to true if client authentication is required, or false if no client authentication is desired.- See Also:
getNeedClientAuth(),setUseClientMode(boolean)
-
getNeedClientAuth
public abstract boolean getNeedClientAuth()
Returns true if client authentication will be required on newlyaccepted server-modeSSLSockets.The initial inherited setting may be overridden by calling
SSLSocket.setNeedClientAuth(boolean)- Returns:
- true if client authentication is required, or false if no client authentication is desired.
- See Also:
setNeedClientAuth(boolean),setUseClientMode(boolean)
-
setUseClientMode
public abstract void setUseClientMode(boolean mode)
Controls whether accepted connections are in the (default) SSL server mode, or the SSL client mode.Servers normally authenticate themselves, and clients are not required to do so.
In rare cases, TCP servers need to act in the SSL client mode on newly accepted connections. For example, FTP clients acquire server sockets and listen there for reverse connections from the server. An FTP client would use an SSLServerSocket in "client" mode to accept the reverse connection while the FTP server uses an SSLSocket with "client" mode disabled to initiate the connection. During the resulting handshake, existing SSL sessions may be reused.
SSLSockets returned fromaccept()inherit this setting.- Parameters:
mode- true if newly accepted connections should use SSL client mode.- See Also:
getUseClientMode()
-
getUseClientMode
public abstract boolean getUseClientMode()
Returns true if accepted connections will be in SSL client mode.- Returns:
- true if the connection should use SSL client mode.
- See Also:
setUseClientMode(boolean)
-
-