From ed4695b5815f9c3b6764b99122c892cc6043d2d1 Mon Sep 17 00:00:00 2001 From: lprimak Date: Tue, 11 Jun 2024 14:15:23 -0500 Subject: [PATCH] enh: Build on JDK 22 --- .github/workflows/maven.yml | 5 ++++- tools/hasher/pom.xml | 13 +++++-------- .../org/apache/shiro/tools/hasher/Hasher.java | 16 ++++++++++++++-- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index ffa5d40bfa..8ea56639d9 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -55,7 +55,7 @@ jobs: strategy: matrix: os: [ 'ubuntu-latest', 'windows-latest', 'macOS-latest' ] - jdk: [ 11, 17, 21 ] + jdk: [ 11, 17, 21, 22 ] dist: [ 'temurin', 'adopt-openj9', 'zulu' ] exclude: # was already built @@ -71,6 +71,9 @@ jobs: # no OpenJ9 21 - dist: adopt-openj9 jdk: 21 + # no OpenJ9 22 + - dist: adopt-openj9 + jdk: 22 fail-fast: false runs-on: ${{ matrix.os }} diff --git a/tools/hasher/pom.xml b/tools/hasher/pom.xml index 5d0e3dc631..e88a863524 100644 --- a/tools/hasher/pom.xml +++ b/tools/hasher/pom.xml @@ -38,14 +38,6 @@ org.apache.shiro shiro-core - - - - commons-beanutils - commons-beanutils - - @@ -71,6 +63,11 @@ log4j-slf4j2-impl runtime + + org.slf4j + jcl-over-slf4j + runtime + org.apache.logging.log4j log4j-api diff --git a/tools/hasher/src/main/java/org/apache/shiro/tools/hasher/Hasher.java b/tools/hasher/src/main/java/org/apache/shiro/tools/hasher/Hasher.java index 83ae0926e1..d57d867b14 100644 --- a/tools/hasher/src/main/java/org/apache/shiro/tools/hasher/Hasher.java +++ b/tools/hasher/src/main/java/org/apache/shiro/tools/hasher/Hasher.java @@ -18,6 +18,7 @@ */ package org.apache.shiro.tools.hasher; +import org.apache.commons.beanutils.PropertyUtils; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.CommandLineParser; import org.apache.commons.cli.DefaultParser; @@ -479,9 +480,8 @@ private static void printHelpAndExit(Options options, Exception e, boolean debug private static char[] readPassword(boolean confirm) throws IOException { java.io.Console console = System.console(); char[] first; - if (console != null) { + if (isTerminal(console)) { first = console.readPassword("%s", "Password to hash: "); - //throw new IllegalStateException("java.io.Console is not available on the current JVM. Cannot read passwords."); } else if (System.in != null) { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String readLine = br.readLine(); @@ -495,6 +495,9 @@ private static char[] readPassword(boolean confirm) throws IOException { throw new IllegalArgumentException("No password specified."); } if (confirm) { + if (!isTerminal(console)) { + throw new IllegalStateException("Cannot confirm password when console is not available."); + } char[] second = console.readPassword("%s", "Password to hash (confirm): "); if (!Arrays.equals(first, second)) { String msg = "Password entries do not match."; @@ -504,6 +507,15 @@ private static char[] readPassword(boolean confirm) throws IOException { return first; } + private static boolean isTerminal(java.io.Console console) throws IOException { + try { + // isTerminal is only available in Java 22 or later + return console != null && (Boolean) PropertyUtils.getProperty(console, "terminal"); + } catch (ReflectiveOperationException e) { + return true; + } + } + private static File toFile(String path) { String resolved = path; if (path.startsWith("~/") || path.startsWith(("~\\"))) {