[java-identity-provider] 02/02: IDP-2333 Generate idp-userfacing.p12 on initial module enable

Rod Widdowson rdw at steadingsoftware.com
Fri Oct 11 13:26:38 UTC 2024


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:
http://git.shibboleth.net/view/?p=java-identity-provider.git;a=commit;h=ff5f1a0c164be142ada4ff19cf989e81d38f7786

commit ff5f1a0c164be142ada4ff19cf989e81d38f7786
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Fri Oct 11 11:22:18 2024 +0100

    IDP-2333 Generate idp-userfacing.p12 on initial module enable
    
    https://shibboleth.atlassian.net/browse/IDP-2333
    
    Move helper function from InstallerProperties to InstallerSupport to get a host name
---
 .../shibboleth/idp/installer/InstallerSupport.java | 74 ++++++++++++++++++++
 .../idp/installer/impl/InstallerProperties.java    | 79 ++--------------------
 2 files changed, 78 insertions(+), 75 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 b96189b68..537def056 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;
 
@@ -456,6 +460,76 @@ public final class InstallerSupport {
         pathsCopied.addAll(visitor.getCopiedList());
     }
 
+    /**
+     * 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
+
+
     /**
      * A @{link {@link FileVisitor} which detects (and logs) whether a copy would overwrite.
      */
diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/InstallerProperties.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/InstallerProperties.java
index 6e258b12e..6ba8736fd 100644
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/InstallerProperties.java
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/InstallerProperties.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;
@@ -39,6 +35,7 @@ import org.apache.tools.ant.input.InputHandler;
 import org.apache.tools.ant.input.InputRequest;
 import org.slf4j.Logger;
 
+import net.shibboleth.idp.installer.InstallerSupport;
 import net.shibboleth.shared.annotation.constraint.NonnullAfterInit;
 import net.shibboleth.shared.annotation.constraint.NotEmpty;
 import net.shibboleth.shared.annotation.constraint.NotLive;
@@ -365,85 +362,17 @@ public class InstallerProperties  {
         return !tidy;
     }
 
-    /**
-     * Is this address named?
-     * 
-     * <p>Helper method for {@link #bestHostName()}.</p>
-     * 
-     * @param addr what to look at
-     * @return true unless the name is the canonical name
-     */
-    private 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 private String bestHostName() {
-        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) {
-            log.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
-
     /**
      * Get the host name for this install.
-     * 
+     *
      * <p>Defaults to information pulled from the network.</p>
-     * 
+     *
      * @return the host name.
      */
     @Nonnull public String getHostName() {
         String result = hostname;
         if (result == null) {
-            result = hostname = getValue(HOST_NAME, "Host Name:", () -> bestHostName());
+            result = hostname = getValue(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