From 401366a254fd1c524a786155c586a631938b2c42 Mon Sep 17 00:00:00 2001 From: Tao Liu Date: Thu, 31 Oct 2024 14:26:59 -0400 Subject: [PATCH] Add the error message when the profile is not exist In Restricted Security Mode, add the error message when the profile name is used without the version part in "-Dsemeru.customprofile=", and the specified profile does not exist in the java.security file. Signed-off-by: Tao Liu --- .../internal/security/RestrictedSecurity.java | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/closed/src/java.base/share/classes/openj9/internal/security/RestrictedSecurity.java b/closed/src/java.base/share/classes/openj9/internal/security/RestrictedSecurity.java index c051e380a07..4c0ce77fcf9 100644 --- a/closed/src/java.base/share/classes/openj9/internal/security/RestrictedSecurity.java +++ b/closed/src/java.base/share/classes/openj9/internal/security/RestrictedSecurity.java @@ -344,23 +344,29 @@ private static void getProfileID(Properties props) { + selectedProfile); } String defaultMatch = null; + Boolean profileExist = false; for (Object keyObject : props.keySet()) { if (keyObject instanceof String key) { - if (key.startsWith(potentialProfileID) && key.endsWith(".desc.default")) { - // Check if property is set to true. - if (Boolean.parseBoolean(props.getProperty(key))) { - // Check if multiple defaults exist and act accordingly. - if (defaultMatch == null) { - defaultMatch = key.split("\\.desc")[0]; - } else { - printStackTraceAndExit("Multiple default RestrictedSecurity" - + " profiles for " + selectedProfile); + if (key.startsWith(potentialProfileID)) { + profileExist = true; + if (key.endsWith(".desc.default")) { + // Check if property is set to true. + if (Boolean.parseBoolean(props.getProperty(key))) { + // Check if multiple defaults exist and act accordingly. + if (defaultMatch == null) { + defaultMatch = key.split("\\.desc")[0]; + } else { + printStackTraceAndExit("Multiple default RestrictedSecurity" + + " profiles for " + selectedProfile); + } } } } } } - if (defaultMatch == null) { + if (!profileExist) { + printStackTraceAndExit(selectedProfile + " is not present in the java.security file."); + } else if (defaultMatch == null) { printStackTraceAndExit("No default RestrictedSecurity profile was found for " + selectedProfile); } else {