[java-identity-provider] branch main updated: JJETTY-26 Installer make a method 'api' again

Rod Widdowson rdw at steadingsoftware.com
Wed Nov 12 16:55:42 UTC 2025


This is an automated email from the git hooks/post-receive script.

rdw pushed a commit to branch main
in repository java-identity-provider.

View the commit online:
https://git.shibboleth.net/view/?p=java-identity-provider.git;a=commit;h=79e003ea044c2a4c84e2905fc8cd3af6d403eee6

The following commit(s) were added to refs/heads/main by this push:
     new 79e003ea0 JJETTY-26 Installer make a method 'api' again
79e003ea0 is described below

commit 79e003ea044c2a4c84e2905fc8cd3af6d403eee6
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Wed Nov 12 16:38:16 2025 +0000

    JJETTY-26 Installer make a method 'api' again
    
    https://shibboleth.atlassian.net/browse/JJETTY-26
    
    Move "getBestHostName()" up from impl/InstallerPropertiesImpl
    to InstallerSupport and un-deprecate it (because we will need
    it forever).
---
 .../shibboleth/idp/installer/InstallerSupport.java | 72 +++++++++++++++++++++
 .../installer/impl/InstallerPropertiesImpl.java    | 75 +---------------------
 2 files changed, 73 insertions(+), 74 deletions(-)

diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/InstallerSupport.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/InstallerSupport.java
index 034dc05eb..6cf355507 100644
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/InstallerSupport.java
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/InstallerSupport.java
@@ -18,12 +18,16 @@ import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
+import java.net.InetAddress;
+import java.net.NetworkInterface;
+import java.net.SocketException;
 import java.nio.file.FileVisitResult;
 import java.nio.file.FileVisitor;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.SimpleFileVisitor;
 import java.nio.file.attribute.BasicFileAttributes;
+import java.util.Collections;
 import java.util.List;
 import java.util.function.Predicate;
 
@@ -542,4 +546,72 @@ public final class InstallerSupport {
             return result != null && "y".equalsIgnoreCase(result.substring(0, 1));
         }
     }
+
+    /**
+     * Is this address named?
+     *
+     * <p>Helper method for {@link getBestHostName}.</p>
+     * @param addr what to look at
+     * @return true unless the name is the canonical name
+     */
+    private static boolean hasHostName(final InetAddress addr) {
+        return !addr.getHostAddress().equals(addr.getCanonicalHostName());
+    }
+
+    /**
+     * Find the most apposite network connector, taken from Ant.
+     * @return the best name we can work out
+     */
+    // CheckStyle: CyclomaticComplexity OFF
+    @Nonnull
+    public static String getBestHostName() {
+        InetAddress bestSoFar = null;
+        try {
+            for (final NetworkInterface netInterface : Collections.list(NetworkInterface.getNetworkInterfaces())) {
+                for (final InetAddress address : Collections.list(netInterface.getInetAddresses())) {
+                    if (bestSoFar == null) {
+                        // none selected so far, so this one is better.
+                        bestSoFar = address;
+                    } else if (address == null || address.isLoopbackAddress()) {
+                        // definitely not better than the previously selected address.
+                    } else if (address.isLinkLocalAddress()) {
+                        // link local considered better than loopback
+                        if (bestSoFar.isLoopbackAddress()) {
+                            bestSoFar = address;
+                        }
+                    } else if (address.isSiteLocalAddress()) {
+                        // site local considered better than link local (and loopback)
+                        // address with hostname resolved considered better than
+                        // address without hostname
+                        if (bestSoFar.isLoopbackAddress()
+                                || bestSoFar.isLinkLocalAddress()
+                                || (bestSoFar.isSiteLocalAddress() && !hasHostName(bestSoFar))) {
+                            bestSoFar = address;
+                        }
+                    } else {
+                        // current is a "Global address", considered better than
+                        // site local (and better than link local, loopback)
+                        // address with hostname resolved considered better than
+                        // address without hostname
+                        if (bestSoFar.isLoopbackAddress()
+                                || bestSoFar.isLinkLocalAddress()
+                                || bestSoFar.isSiteLocalAddress()
+                                || !hasHostName(bestSoFar)) {
+                            bestSoFar = address;
+                        }
+                    }
+                }
+            }
+        } catch (final SocketException e) {
+            LoggerFactory.getLogger(InstallerSupport.class).error("Could not get host information", e);
+        }
+        if (bestSoFar == null) {
+            return "localhost.localdomain";
+        }
+        final String result = bestSoFar.getCanonicalHostName();
+        assert result!=null;
+        return result;
+    }
+    // CheckStyle: CyclomaticComplexity ON
+
 }
diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/InstallerPropertiesImpl.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/InstallerPropertiesImpl.java
index 8473dd1d6..a900b5157 100644
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/InstallerPropertiesImpl.java
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/InstallerPropertiesImpl.java
@@ -17,15 +17,11 @@ package net.shibboleth.idp.installer.impl;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
-import java.net.InetAddress;
-import java.net.NetworkInterface;
-import java.net.SocketException;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.security.NoSuchAlgorithmException;
 import java.security.SecureRandom;
 import java.util.Arrays;
-import java.util.Collections;
 import java.util.HashSet;
 import java.util.Properties;
 import java.util.Set;
@@ -202,75 +198,6 @@ public class InstallerPropertiesImpl  {
 // CheckStyle: CyclomaticComplexity ON
 
 
-    /**
-     * Is this address named?
-     *
-     * <p>Helper method for {@link #getBestHostName()}.</p>
-     * @deprecated to be removed in V6
-     * @param addr what to look at
-     * @return true unless the name is the canonical name
-     */
-    private static boolean hasHostName(final InetAddress addr) {
-        return !addr.getHostAddress().equals(addr.getCanonicalHostName());
-    }
-
-
-    /**
-     * Find the most apposite network connector, taken from Ant.
-     * @deprecated To be removed in V6
-     * @return the best name we can work out
-     */
-    // CheckStyle: CyclomaticComplexity OFF
-    @Nonnull private static String getBestHostName() {
-        InetAddress bestSoFar = null;
-        try {
-            for (final NetworkInterface netInterface : Collections.list(NetworkInterface.getNetworkInterfaces())) {
-                for (final InetAddress address : Collections.list(netInterface.getInetAddresses())) {
-                    if (bestSoFar == null) {
-                        // none selected so far, so this one is better.
-                        bestSoFar = address;
-                    } else if (address == null || address.isLoopbackAddress()) {
-                        // definitely not better than the previously selected address.
-                    } else if (address.isLinkLocalAddress()) {
-                        // link local considered better than loopback
-                        if (bestSoFar.isLoopbackAddress()) {
-                            bestSoFar = address;
-                        }
-                    } else if (address.isSiteLocalAddress()) {
-                        // site local considered better than link local (and loopback)
-                        // address with hostname resolved considered better than
-                        // address without hostname
-                        if (bestSoFar.isLoopbackAddress()
-                                || bestSoFar.isLinkLocalAddress()
-                                || (bestSoFar.isSiteLocalAddress() && !hasHostName(bestSoFar))) {
-                            bestSoFar = address;
-                        }
-                    } else {
-                        // current is a "Global address", considered better than
-                        // site local (and better than link local, loopback)
-                        // address with hostname resolved considered better than
-                        // address without hostname
-                        if (bestSoFar.isLoopbackAddress()
-                                || bestSoFar.isLinkLocalAddress()
-                                || bestSoFar.isSiteLocalAddress()
-                                || !hasHostName(bestSoFar)) {
-                            bestSoFar = address;
-                        }
-                    }
-                }
-            }
-        } catch (final SocketException e) {
-            LoggerFactory.getLogger(InstallerSupport.class).error("Could not get host information", e);
-        }
-        if (bestSoFar == null) {
-            return "localhost.localdomain";
-        }
-        final String result = bestSoFar.getCanonicalHostName();
-        assert result!=null;
-        return result;
-    }
-    // CheckStyle: CyclomaticComplexity ON
-
     /**
      * Lookup a property; if it isn't defined then ask the user (if we are allowed).
      * 
@@ -398,7 +325,7 @@ public class InstallerPropertiesImpl  {
     @Nonnull public String getHostName() {
         String result = hostname;
         if (result == null) {
-            result = hostname = getValue(InstallerProperties.HOST_NAME, "Host Name:", () -> getBestHostName());
+            result = hostname = getValue(InstallerProperties.HOST_NAME, "Host Name:", () -> InstallerSupport.getBestHostName());
         }
         return result;
     }

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list