Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TKSS-883: Backport JDK-8319332: Security properties files inclusion #886

Merged
merged 1 commit into from
Oct 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -30,6 +30,7 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.security.GeneralSecurityException;
import java.util.function.UnaryOperator;

/**
* A utility class to expand properties embedded in a string.
Expand All @@ -52,15 +53,31 @@ public ExpandException(String msg) {
}
}

public static String expand(String value)
throws ExpandException
{
public static String expand(String value) throws ExpandException {
return expand(value, false);
}

public static String expand(String value, boolean encodeURL)
throws ExpandException
{
public static String expand(String value, boolean encodeURL)
throws ExpandException {
return expand(value, encodeURL, System::getProperty);
}

/*
* In non-strict mode an undefined property is replaced by an empty string.
*/
public static String expandNonStrict(String value) {
try {
return expand(value, false, key -> System.getProperty(key, ""));
} catch (ExpandException e) {
// should not happen
throw new AssertionError("unexpected expansion error: when " +
"expansion is non-strict, undefined properties should " +
"be replaced by an empty string", e);
}
}

private static String expand(String value, boolean encodeURL,
UnaryOperator<String> propertiesGetter) throws ExpandException {
if (value == null)
return null;

Expand Down Expand Up @@ -106,7 +123,7 @@ public static String expand(String value, boolean encodeURL)
if (prop.equals("/")) {
sb.append(java.io.File.separatorChar);
} else {
String val = System.getProperty(prop);
String val = propertiesGetter.apply(prop);
if (val != null) {
if (encodeURL) {
// encode 'val' unless it's an absolute URI
Expand Down