[java-idp-plugin-jetty] branch main updated: JJETTY-16 Make logging work OOB
Rod Widdowson
rdw at steadingsoftware.com
Sat Sep 13 15:02:09 UTC 2025
This is an automated email from the git hooks/post-receive script.
rdw pushed a commit to branch main
in repository java-idp-plugin-jetty.
View the commit online:
http://git.shibboleth.net/view/?p=java-idp-plugin-jetty.git;a=commit;h=44686861482aedb6acf40a162fbcf01d68054fc3
The following commit(s) were added to refs/heads/main by this push:
new 4468686 JJETTY-16 Make logging work OOB
4468686 is described below
commit 44686861482aedb6acf40a162fbcf01d68054fc3
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Sat Sep 13 16:00:39 2025 +0100
JJETTY-16 Make logging work OOB
https://shibboleth.atlassian.net/browse/JJETTY-16
Find the correct logback version and write an ini file with that info
Copy the logback jars from the IdP to jetty-base
---
.../shibboleth/idp/module/jetty/JettyModule.java | 95 +++++++++++++++++++++-
1 file changed, 94 insertions(+), 1 deletion(-)
diff --git a/jetty-impl/src/main/java/net/shibboleth/idp/module/jetty/JettyModule.java b/jetty-impl/src/main/java/net/shibboleth/idp/module/jetty/JettyModule.java
index d4255a6..e5f4906 100644
--- a/jetty-impl/src/main/java/net/shibboleth/idp/module/jetty/JettyModule.java
+++ b/jetty-impl/src/main/java/net/shibboleth/idp/module/jetty/JettyModule.java
@@ -13,9 +13,19 @@
*/
package net.shibboleth.idp.module.jetty;
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PrintStream;
+import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
+import java.util.Iterator;
import java.util.Map;
import javax.annotation.Nonnull;
@@ -27,6 +37,7 @@ import net.shibboleth.idp.installer.impl.InstallerProperties;
import net.shibboleth.idp.module.impl.PluginIdPModule;
import net.shibboleth.profile.module.ModuleContext;
import net.shibboleth.profile.module.ModuleException;
+import net.shibboleth.shared.annotation.constraint.NotEmpty;
import net.shibboleth.shared.collection.CollectionSupport;
import net.shibboleth.shared.primitive.LoggerFactory;
import net.shibboleth.shared.security.impl.SelfSignedCertificateGenerator;
@@ -53,10 +64,92 @@ public class JettyModule extends PluginIdPModule {
if (!Files.exists(keystore)) {
generateKeystore(keystore);
}
+ handleLogbackJars(idpHome, "jetty-base-12");
return result;
}
- /** Generate an mock idp-userfacing.p12 keystore.
+ /** Copy the logback jars into jetty-base\lib\logging and set up an appropriate ini file.
+ * @param idpHome idpHome
+ * @param jettyBaseName the jetty base to populate (parameterized to allow multiple jett-bases per plugin)
+ * @throws ModuleException if we cannot find the logback version or get an IO issue.
+ */
+ private void handleLogbackJars(final @Nonnull Path idpHome, final @Nonnull @NotEmpty String jettyBaseName) throws ModuleException {
+
+ final Path jettyBaseDir = idpHome.resolve(jettyBaseName);
+ final Path jarTargetDir = jettyBaseDir.resolve("lib").resolve("logging");
+ try {
+ log.debug("Creating {}", jarTargetDir);
+ Files.createDirectories(jarTargetDir);
+
+ final Path distLibDir = idpHome.resolve("dist").resolve("webapp").resolve("WEB-INF").resolve("lib");
+ final String version = inferLogbackVersion(distLibDir);
+
+ copyLogbackJar(distLibDir, jarTargetDir, "logback-classic-" + version + ".jar");
+ copyLogbackJar(distLibDir, jarTargetDir, "logback-core-" + version + ".jar");
+
+ log.error("Writing logback ini");
+ try(final PrintStream out = new PrintStream(jettyBaseDir.resolve("start.d").resolve("logback.ini").toFile())) {
+ out.format("logback.version=%s\n", version);
+ }
+ }
+ catch (final IOException ex) {
+ log.error("Could not set up logback environment {}", ex);
+ throw new ModuleException(ex);
+ }
+ }
+
+ /** Copy a names logback jar from the IdP distribution to jetty-base
+ * @param sourceDir where to copy from (idp.home/dist/webapp/WEB-INF/lib
+ * @param targetDir
+ * @param jarName
+ * @throws IOException if the copy fails
+ */
+ private void copyLogbackJar(Path sourceDir, Path targetDir, String jarName) throws IOException {
+
+ final File targetFile = targetDir.resolve(jarName).toFile();
+
+ if (targetFile.exists()) {
+ log.debug("Logback jar {} already exists.", targetFile);
+ return;
+ }
+
+ final File sourceFile = sourceDir.resolve(jarName).toFile();
+ if (!sourceFile.exists()) {
+ log.error("Logback jar {} does not exist.", sourceFile);
+ throw new IOException("Logback jar not found");
+ }
+
+ log.debug("Copying {} to {}", sourceFile, targetFile);
+ try(final InputStream in = new BufferedInputStream(new FileInputStream(sourceFile));
+ final OutputStream out = new BufferedOutputStream(new FileOutputStream(targetFile))) {
+ in.transferTo(out);
+ }
+ }
+
+ /** Find out what version of logback this IdP install uses.
+ * Look for logback-classic-version.jar and pluck out the version.
+ * @param distLibDir {@link Path}for idp.home/dist/webapp/WEB-INF/lib
+ * @return the version.
+ * @throws ModuleException if the lookup failed.
+ */
+ private String inferLogbackVersion(Path distLibDir) throws ModuleException {
+
+ try (DirectoryStream<Path> stream = Files.newDirectoryStream(distLibDir, "logback-classic-*.jar")) {
+ Iterator<Path> i = stream.iterator();
+ if (!i.hasNext()) {
+ log.error("Could not locate logback-classic-*.jar in {}", distLibDir);
+ throw new ModuleException("Could not locate logback jars ");
+ }
+ final String fileName = i.next().getFileName().toString();
+ final int len = fileName.length();
+ return fileName.substring(16, len-4);
+ } catch (final IOException ex) {
+ log.error("Error looking for logback-classic-*.jar in {}", distLibDir, ex);
+ throw new ModuleException(ex);
+ }
+ }
+
+ /** Generate an mock idp-userfacing.p12 keystore.
* @param keystore where to put it
* @throws ModuleException if the generator fails
*/
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list