Skip to content

Commit 471656b

Browse files
committed
[bugfix] Repair JMXservlet for ipv6 addresses.
1 parent 8ce0844 commit 471656b

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

exist-core/src/main/java/org/exist/management/client/JMXServlet.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.io.OutputStream;
2727
import java.io.OutputStreamWriter;
2828
import java.io.Writer;
29+
import java.net.Inet6Address;
2930
import java.net.InetAddress;
3031
import java.net.UnknownHostException;
3132
import java.nio.charset.StandardCharsets;
@@ -230,7 +231,15 @@ void registerLocalHostAddresses() {
230231
localhostAddresses.add(address.getHostAddress());
231232
}
232233
} catch (UnknownHostException ex) {
233-
LOG.warn("Unable to retrieve ipaddresses for localhost: {}", ex.getMessage());
234+
LOG.warn("Unable to retrieve ipaddresses (v4) for localhost: {}", ex.getMessage());
235+
}
236+
237+
try {
238+
for (InetAddress address : Inet6Address.getAllByName("localhost") ){
239+
localhostAddresses.add(address.getHostAddress());
240+
}
241+
} catch (UnknownHostException ex) {
242+
LOG.warn("Unable to retrieve ipaddresses (v6) for localhost: {}", ex.getMessage());
234243
}
235244

236245
if (localhostAddresses.isEmpty()) {
@@ -245,7 +254,9 @@ void registerLocalHostAddresses() {
245254
* @return TRUE if request is from LOCALHOST otherwise FALSE
246255
*/
247256
boolean isFromLocalHost(HttpServletRequest request) {
248-
return localhostAddresses.contains(request.getRemoteAddr());
257+
String remoteAddr = request.getRemoteAddr();
258+
remoteAddr = remoteAddr.startsWith("[") ? remoteAddr.substring(1, remoteAddr.length() - 1) : remoteAddr;
259+
return localhostAddresses.contains(remoteAddr);
249260
}
250261

251262
/**

0 commit comments

Comments
 (0)