Package org.jivesoftware.openfire.net
Class VirtualConnection
- java.lang.Object
-
- org.jivesoftware.openfire.net.AbstractConnection
-
- org.jivesoftware.openfire.net.VirtualConnection
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Connection
- Direct Known Subclasses:
ClientSessionConnection
,HttpSession.HttpVirtualConnection
,WebSocketConnection
public abstract class VirtualConnection extends AbstractConnection
Abstract implementation of the Connection interface that models abstract connections. Abstract connections are connections that don't have a physical connection counterpart. Instead they can be seen as conceptual or just 'abstract' connections.Default values and common behavior of virtual connections are modeled in this class. Subclasses should just need to specify how packets are delivered and what means closing the connection.
- Author:
- Gaston Dombiak
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.jivesoftware.openfire.Connection
Connection.ClientAuth, Connection.CompressionPolicy, Connection.State, Connection.TLSPolicy
-
-
Field Summary
-
Fields inherited from class org.jivesoftware.openfire.net.AbstractConnection
closeListeners, session
-
-
Constructor Summary
Constructors Constructor Description VirtualConnection()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addCompression()
Adds the compression filter to the connection but only filter incoming traffic.void
close(org.xmpp.packet.StreamError error, boolean networkInterruption)
Closes the session, the virtual connection and notifies listeners that the connection has been closed.abstract void
closeVirtualConnection(org.xmpp.packet.StreamError error)
Closes the virtual connection.Certificate[]
getLocalCertificates()
Returns the local underlyingX509Certificate
chain for the connection.PacketDeliverer
getPacketDeliverer()
Returns the packet deliverer to use when delivering a packet over the socket fails.Certificate[]
getPeerCertificates()
Returns the underlyingX509Certificate
for the connection of the peer.boolean
isClosed()
Returns true if the connection/session is closed.boolean
isCompressed()
Returns true if the connection is using compression.boolean
isEncrypted()
Returns true if this connection is encrypted.boolean
isInitialized()
Checks if the connection has finished initialization.boolean
isSecure()
Deprecated.boolean
isUsingSelfSignedCertificate()
Returns true if the other peer of this session presented a self-signed certificate.void
setUsingSelfSignedCertificate(boolean isSelfSigned)
Keeps track if the other peer of this session presented a self-signed certificate.void
startCompression()
Start compressing outgoing traffic for this connection.void
startTLS(boolean clientMode, boolean directTLS)
Encrypts the plain connection by negotiating TLS with the other peer.boolean
validate()
Verifies that the connection is still live.-
Methods inherited from class org.jivesoftware.openfire.net.AbstractConnection
getAdditionalNamespaces, getMajorXMPPVersion, getMinorXMPPVersion, getSession, init, notifyCloseListeners, registerCloseListener, reinit, removeCloseListener, setAdditionalNamespaces, setXMPPVersion
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.jivesoftware.openfire.Connection
close, close, deliver, deliverRawText, getAddress, getCipherSuiteName, getConfiguration, getHostAddress, getHostName, getTLSProtocolName, systemShutdown
-
-
-
-
Method Detail
-
getLocalCertificates
public Certificate[] getLocalCertificates()
Description copied from interface:Connection
Returns the local underlyingX509Certificate
chain for the connection.- Returns:
- an ordered array of certificates, with the local certificate
first followed by any certificate authorities. If no certificates
is present for the connection, then
null
is returned.
-
getPeerCertificates
public Certificate[] getPeerCertificates()
Description copied from interface:Connection
Returns the underlyingX509Certificate
for the connection of the peer.- Returns:
- an ordered array of peer certificates, with the peer's own certificate first followed by any certificate authorities.
-
setUsingSelfSignedCertificate
public void setUsingSelfSignedCertificate(boolean isSelfSigned)
Description copied from interface:Connection
Keeps track if the other peer of this session presented a self-signed certificate. When using self-signed certificate for server-2-server sessions then SASL EXTERNAL will not be used and instead server-dialback will be preferred for vcerifying the identify of the remote server.- Parameters:
isSelfSigned
- true if the other peer presented a self-signed certificate.
-
isUsingSelfSignedCertificate
public boolean isUsingSelfSignedCertificate()
Description copied from interface:Connection
Returns true if the other peer of this session presented a self-signed certificate. When using self-signed certificate for server-2-server sessions then SASL EXTERNAL will not be used and instead server-dialback will be preferred for vcerifying the identify of the remote server.- Returns:
- true if the other peer of this session presented a self-signed certificate.
-
isClosed
public boolean isClosed()
Description copied from interface:Connection
Returns true if the connection/session is closed.- Returns:
- true if the connection is closed.
-
isCompressed
public boolean isCompressed()
Description copied from interface:Connection
Returns true if the connection is using compression.- Returns:
- true if the connection is using compression.
-
getPacketDeliverer
@Nullable public PacketDeliverer getPacketDeliverer()
Description copied from interface:Connection
Returns the packet deliverer to use when delivering a packet over the socket fails. The packet deliverer will retry to send the packet using some other connection or will store the packet offline for later retrieval. When null, packets will just be dropped.- Returns:
- the packet deliverer to use when delivering a packet over the socket fails.
-
startTLS
public void startTLS(boolean clientMode, boolean directTLS) throws Exception
Description copied from interface:Connection
Encrypts the plain connection by negotiating TLS with the other peer. In a server-2-server connection the server requesting the TLS negotiation will be the client and the other server will be the server during the TLS negotiation. Therefore, the server requesting the TLS negotiation must passtrue
in theclientMode
parameter and the server receiving the TLS request must passfalse
in theclientMode
parameter.In the case of client-2-server the XMPP server must pass
false
in theclientMode
parameter since it will behave as the server in the TLS negotiation.- Parameters:
clientMode
- boolean indicating if this entity is a client or a server in the TLS negotiation.directTLS
- boolean indicating if the negotiation is directTLS (true) or startTLS (false).- Throws:
Exception
- if an error occurred while encrypting the connection.
-
addCompression
public void addCompression()
Description copied from interface:Connection
Adds the compression filter to the connection but only filter incoming traffic. Do not filter outgoing traffic since we still need to send an uncompressed stanza to the client indicating that he can start compressing the traffic. After we sent the uncompresses stanza we can start compression outgoing traffic as well.
-
startCompression
public void startCompression()
Description copied from interface:Connection
Start compressing outgoing traffic for this connection. Compression will only be available after TLS has been negotiated. This means that a connection can never be using compression before TLS. However, it is possible to use compression without TLS.
-
isSecure
@Deprecated public boolean isSecure()
Deprecated.Description copied from interface:Connection
Returns true if this connection is secure.- Returns:
- true if the connection is secure (e.g. TLS)
-
isEncrypted
public boolean isEncrypted()
Description copied from interface:Connection
Returns true if this connection is encrypted.- Returns:
- true if the connection is encrypted (e.g. uses TLS)
-
validate
public boolean validate()
Description copied from interface:Connection
Verifies that the connection is still live. Typically, this is done by sending a whitespace character between packets.- Returns:
- true if the socket remains valid, false otherwise.
-
isInitialized
public boolean isInitialized()
Description copied from interface:Connection
Checks if the connection has finished initialization.- Returns:
- true if connection has finished initialization.
-
close
public void close(@Nullable org.xmpp.packet.StreamError error, boolean networkInterruption)
Closes the session, the virtual connection and notifies listeners that the connection has been closed.- Parameters:
error
- If non-null, the end-stream tag will be preceded with this error.
-
closeVirtualConnection
public abstract void closeVirtualConnection(@Nullable org.xmpp.packet.StreamError error)
Closes the virtual connection. Subclasses should indicate what closing a virtual connection means. At this point the session has a CLOSED state.- Parameters:
error
- If non-null, this error will be sent to the peer before the connection is disconnected.
-
-