From 0f6f185be79e50ec832ff7d8bcd75d2a98162d43 Mon Sep 17 00:00:00 2001 From: Milan Tyagi Date: Fri, 27 Mar 2026 14:45:24 +0530 Subject: [PATCH 1/2] OF-1927: Show TCP port for server-to-server (S2S) connections in admin console Display the remote TCP port in the incoming and outgoing S2S session tables on the admin console, allowing administrators to distinguish standard S2S (port 5269) from direct TLS (port 5270) connections. - Added Session#getRemotePort() delegating to Connection#getRemotePort() - Implemented in LocalSession, RemoteSession, and RemoteSessionTask - Appended new enum constant at the end of RemoteSessionTask.Operation to preserve ordinal compatibility in mixed-version clusters - Standardized naming from hostPort to remotePort across all layers - Added port column to S2S session detail tables (reusing ports.port i18n key) - Render blank instead of 0 when port is unavailable - Improved Javadocs to document the 0-when-unavailable contract --- .../org/jivesoftware/openfire/Connection.java | 16 ++++++++++++---- .../openfire/net/SocketConnection.java | 9 +++++++-- .../openfire/nio/NettyConnection.java | 9 +++++++++ .../session/IncomingServerSessionTask.java | 2 ++ .../openfire/session/LocalSession.java | 9 +++++++++ .../openfire/session/RemoteSession.java | 12 ++++++++++++ .../openfire/session/RemoteSessionTask.java | 10 +++++++++- .../jivesoftware/openfire/session/Session.java | 9 +++++++++ .../src/main/webapp/server-session-details.jsp | 18 ++++++++++++++++++ 9 files changed, 87 insertions(+), 7 deletions(-) diff --git a/xmppserver/src/main/java/org/jivesoftware/openfire/Connection.java b/xmppserver/src/main/java/org/jivesoftware/openfire/Connection.java index 20103f04eb..b31cf19daf 100644 --- a/xmppserver/src/main/java/org/jivesoftware/openfire/Connection.java +++ b/xmppserver/src/main/java/org/jivesoftware/openfire/Connection.java @@ -137,10 +137,18 @@ public interface Connection extends Closeable { Certificate[] getPeerCertificates(); /** - * 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 verifying the identify of the remote - * server. + * Returns the remote port used by the connection. + * + * @return the remote port, or 0 when unavailable. + */ + default int getRemotePort() { + return 0; + } + + /** + * Keeps track of whether the other peer of this session presented a self-signed certificate. When + * using a self-signed certificate for server-to-server sessions, SASL EXTERNAL will not be + * used and instead server dialback will be preferred for verifying the identity of the remote * * @param isSelfSigned true if the other peer presented a self-signed certificate. */ diff --git a/xmppserver/src/main/java/org/jivesoftware/openfire/net/SocketConnection.java b/xmppserver/src/main/java/org/jivesoftware/openfire/net/SocketConnection.java index 748ba2e507..722139c309 100644 --- a/xmppserver/src/main/java/org/jivesoftware/openfire/net/SocketConnection.java +++ b/xmppserver/src/main/java/org/jivesoftware/openfire/net/SocketConnection.java @@ -263,14 +263,19 @@ public String getHostName() throws UnknownHostException { } /** - * Returns the port that the connection uses. + * Returns the remote port used by the connection. * - * @return the port that the connection uses. + * @return the remote port, or 0 when unavailable. */ public int getPort() { return socket.getPort(); } + @Override + public int getRemotePort() { + return getPort(); + } + /** * Returns the Writer used to send data to the connection. The writer should be * used with caution. In the majority of cases, the {@link #deliver(Packet)} diff --git a/xmppserver/src/main/java/org/jivesoftware/openfire/nio/NettyConnection.java b/xmppserver/src/main/java/org/jivesoftware/openfire/nio/NettyConnection.java index d17504411a..b26bf09665 100644 --- a/xmppserver/src/main/java/org/jivesoftware/openfire/nio/NettyConnection.java +++ b/xmppserver/src/main/java/org/jivesoftware/openfire/nio/NettyConnection.java @@ -120,6 +120,15 @@ public String getHostAddress() throws UnknownHostException { return inetAddress.getHostAddress(); } + @Override + public int getRemotePort() { + final SocketAddress remoteAddress = channelHandlerContext.channel().remoteAddress(); + if (remoteAddress != null && remoteAddress instanceof InetSocketAddress) { + return ((InetSocketAddress) remoteAddress).getPort(); + } + return 0; + } + @Override public String getHostName() throws UnknownHostException { final SocketAddress remoteAddress = channelHandlerContext.channel().remoteAddress(); diff --git a/xmppserver/src/main/java/org/jivesoftware/openfire/session/IncomingServerSessionTask.java b/xmppserver/src/main/java/org/jivesoftware/openfire/session/IncomingServerSessionTask.java index 58688cd1da..0302167bff 100644 --- a/xmppserver/src/main/java/org/jivesoftware/openfire/session/IncomingServerSessionTask.java +++ b/xmppserver/src/main/java/org/jivesoftware/openfire/session/IncomingServerSessionTask.java @@ -66,6 +66,8 @@ public void run() { case getValidatedDomains: result = ((IncomingServerSession) getSession()).getValidatedDomains(); break; + default: + break; } } diff --git a/xmppserver/src/main/java/org/jivesoftware/openfire/session/LocalSession.java b/xmppserver/src/main/java/org/jivesoftware/openfire/session/LocalSession.java index d907248ecf..bb3a28b238 100644 --- a/xmppserver/src/main/java/org/jivesoftware/openfire/session/LocalSession.java +++ b/xmppserver/src/main/java/org/jivesoftware/openfire/session/LocalSession.java @@ -504,6 +504,15 @@ public String getHostAddress() throws UnknownHostException { return connection.getHostAddress(); } + @Override + public int getRemotePort() { + Connection connection = conn; + if (connection == null) { + return 0; + } + return connection.getRemotePort(); + } + @Override public String getHostName() throws UnknownHostException { Connection connection = conn; diff --git a/xmppserver/src/main/java/org/jivesoftware/openfire/session/RemoteSession.java b/xmppserver/src/main/java/org/jivesoftware/openfire/session/RemoteSession.java index 567cfc2896..1aa020923e 100644 --- a/xmppserver/src/main/java/org/jivesoftware/openfire/session/RemoteSession.java +++ b/xmppserver/src/main/java/org/jivesoftware/openfire/session/RemoteSession.java @@ -51,6 +51,7 @@ public abstract class RemoteSession implements Session { private String serverName; private String hostAddress; private String hostName; + private int remotePort = -1; public RemoteSession(byte[] nodeID, JID address) { this.nodeID = nodeID; @@ -180,6 +181,17 @@ public String getHostName() throws UnknownHostException { return hostName; } + @Override + public int getRemotePort() { + if (remotePort == -1) { + ClusterTask task = getRemoteSessionTask(RemoteSessionTask.Operation.getRemotePort); + Object result = doSynchronousClusterTask(task); + remotePort = result == null ? 0 : (Integer) result; + } + return remotePort; + } + + public void deliverRawText(String text) { doClusterTask(getDeliverRawTextTask(text)); } diff --git a/xmppserver/src/main/java/org/jivesoftware/openfire/session/RemoteSessionTask.java b/xmppserver/src/main/java/org/jivesoftware/openfire/session/RemoteSessionTask.java index 201b87b1f9..859b405b86 100644 --- a/xmppserver/src/main/java/org/jivesoftware/openfire/session/RemoteSessionTask.java +++ b/xmppserver/src/main/java/org/jivesoftware/openfire/session/RemoteSessionTask.java @@ -143,6 +143,13 @@ else if (operation == Operation.getHostName) { Log.error("Error getting address of session: {}", getSession(), e); } } + else if (operation == Operation.getRemotePort) { + if (getSession().isDetached()) { + Log.debug("Unable to get remote port of detached session: {}", getSession()); + } else { + result = getSession().getRemotePort(); + } + } else if (operation == Operation.validate) { result = getSession().validate(); } @@ -246,6 +253,7 @@ public enum Operation { */ getLocalDomain, getAddress, - getValidatedDomains + getValidatedDomains, + getRemotePort } } diff --git a/xmppserver/src/main/java/org/jivesoftware/openfire/session/Session.java b/xmppserver/src/main/java/org/jivesoftware/openfire/session/Session.java index 2e0f0a3ecb..8684046862 100644 --- a/xmppserver/src/main/java/org/jivesoftware/openfire/session/Session.java +++ b/xmppserver/src/main/java/org/jivesoftware/openfire/session/Session.java @@ -195,6 +195,15 @@ default boolean isAuthenticated() { * @throws java.net.UnknownHostException if IP address of host could not be determined. */ String getHostAddress() throws UnknownHostException; + + /** + * Returns the remote port used by the connection. + * + * @return the remote port, or 0 when unavailable. + */ + default int getRemotePort() { + return 0; + } /** * Gets the host name for this IP address. diff --git a/xmppserver/src/main/webapp/server-session-details.jsp b/xmppserver/src/main/webapp/server-session-details.jsp index 0476135415..313d3a9500 100644 --- a/xmppserver/src/main/webapp/server-session-details.jsp +++ b/xmppserver/src/main/webapp/server-session-details.jsp @@ -268,6 +268,7 @@ + @@ -313,6 +314,14 @@ + + + + + +   + + @@ -333,6 +342,7 @@ + @@ -378,6 +388,14 @@ + + + + + +   + + From f81470613590e7aa1bf5e29ad5a31e7807f84321 Mon Sep 17 00:00:00 2001 From: Milan Tyagi Date: Sat, 9 May 2026 17:14:08 +0530 Subject: [PATCH 2/2] fix year, remove defualt break and use deprecated in socketconnection in getport() --- .../org/jivesoftware/openfire/net/SocketConnection.java | 6 ++++-- .../openfire/session/IncomingServerSessionTask.java | 4 +--- .../org/jivesoftware/openfire/session/LocalSession.java | 2 +- .../org/jivesoftware/openfire/session/RemoteSession.java | 2 +- .../jivesoftware/openfire/session/RemoteSessionTask.java | 2 +- .../java/org/jivesoftware/openfire/session/Session.java | 2 +- xmppserver/src/main/webapp/server-session-details.jsp | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/xmppserver/src/main/java/org/jivesoftware/openfire/net/SocketConnection.java b/xmppserver/src/main/java/org/jivesoftware/openfire/net/SocketConnection.java index 722139c309..bcbae337ee 100644 --- a/xmppserver/src/main/java/org/jivesoftware/openfire/net/SocketConnection.java +++ b/xmppserver/src/main/java/org/jivesoftware/openfire/net/SocketConnection.java @@ -266,14 +266,16 @@ public String getHostName() throws UnknownHostException { * Returns the remote port used by the connection. * * @return the remote port, or 0 when unavailable. + * @deprecated This method is replaced by {@link #getRemotePort()} */ + @Deprecated(forRemoval = true, since = "5.1.0") // Remove in or after Openfire 5.2.0. public int getPort() { - return socket.getPort(); + return getRemotePort(); } @Override public int getRemotePort() { - return getPort(); + return socket.getPort(); } /** diff --git a/xmppserver/src/main/java/org/jivesoftware/openfire/session/IncomingServerSessionTask.java b/xmppserver/src/main/java/org/jivesoftware/openfire/session/IncomingServerSessionTask.java index 0302167bff..5870a851a1 100644 --- a/xmppserver/src/main/java/org/jivesoftware/openfire/session/IncomingServerSessionTask.java +++ b/xmppserver/src/main/java/org/jivesoftware/openfire/session/IncomingServerSessionTask.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2007-2009 Jive Software, 2021-2023 Ignite Realtime Foundation. All rights reserved. + * Copyright (C) 2007-2009 Jive Software, 2021-2026 Ignite Realtime Foundation. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -66,8 +66,6 @@ public void run() { case getValidatedDomains: result = ((IncomingServerSession) getSession()).getValidatedDomains(); break; - default: - break; } } diff --git a/xmppserver/src/main/java/org/jivesoftware/openfire/session/LocalSession.java b/xmppserver/src/main/java/org/jivesoftware/openfire/session/LocalSession.java index bb3a28b238..29468b44cb 100644 --- a/xmppserver/src/main/java/org/jivesoftware/openfire/session/LocalSession.java +++ b/xmppserver/src/main/java/org/jivesoftware/openfire/session/LocalSession.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2004-2009 Jive Software, 2017-2025 Ignite Realtime Foundation. All rights reserved. + * Copyright (C) 2004-2009 Jive Software, 2017-2026 Ignite Realtime Foundation. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/xmppserver/src/main/java/org/jivesoftware/openfire/session/RemoteSession.java b/xmppserver/src/main/java/org/jivesoftware/openfire/session/RemoteSession.java index 1aa020923e..81b519dcba 100644 --- a/xmppserver/src/main/java/org/jivesoftware/openfire/session/RemoteSession.java +++ b/xmppserver/src/main/java/org/jivesoftware/openfire/session/RemoteSession.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2007-2009 Jive Software, 2021-2025 Ignite Realtime Foundation. All rights reserved. + * Copyright (C) 2007-2009 Jive Software, 2021-2026 Ignite Realtime Foundation. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/xmppserver/src/main/java/org/jivesoftware/openfire/session/RemoteSessionTask.java b/xmppserver/src/main/java/org/jivesoftware/openfire/session/RemoteSessionTask.java index 859b405b86..81cba3c331 100644 --- a/xmppserver/src/main/java/org/jivesoftware/openfire/session/RemoteSessionTask.java +++ b/xmppserver/src/main/java/org/jivesoftware/openfire/session/RemoteSessionTask.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2007-2009 Jive Software, 2021-2025 Ignite Realtime Foundation. All rights reserved. + * Copyright (C) 2007-2009 Jive Software, 2021-2026 Ignite Realtime Foundation. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/xmppserver/src/main/java/org/jivesoftware/openfire/session/Session.java b/xmppserver/src/main/java/org/jivesoftware/openfire/session/Session.java index 8684046862..62e76d7a6b 100644 --- a/xmppserver/src/main/java/org/jivesoftware/openfire/session/Session.java +++ b/xmppserver/src/main/java/org/jivesoftware/openfire/session/Session.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2008 Jive Software, 2017-2025 Ignite Realtime Foundation. All rights reserved. + * Copyright (C) 2005-2008 Jive Software, 2017-2026 Ignite Realtime Foundation. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/xmppserver/src/main/webapp/server-session-details.jsp b/xmppserver/src/main/webapp/server-session-details.jsp index 313d3a9500..a52d45cc31 100644 --- a/xmppserver/src/main/webapp/server-session-details.jsp +++ b/xmppserver/src/main/webapp/server-session-details.jsp @@ -1,7 +1,7 @@ <%@ page contentType="text/html; charset=UTF-8" %> <%-- - - - Copyright (C) 2004-2008 Jive Software, 2017-2025 Ignite Realtime Foundation. All rights reserved. + - Copyright (C) 2004-2008 Jive Software, 2017-2026 Ignite Realtime Foundation. All rights reserved. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License.