8292067: Convert test/sun/management/jmxremote/bootstrap shell tests to java version
Reviewed-by: lmesnik
This commit is contained in:
parent
83a34086bc
commit
3993a1f9ea
@ -1,33 +0,0 @@
|
||||
#
|
||||
# Copyright (c) 2003, 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
|
||||
# under the terms of the GNU General Public License version 2 only, as
|
||||
# published by the Free Software Foundation.
|
||||
#
|
||||
# This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
# version 2 for more details (a copy is included in the LICENSE file that
|
||||
# accompanied this code).
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License version
|
||||
# 2 along with this work; if not, write to the Free Software Foundation,
|
||||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
# or visit www.oracle.com if you need additional information or have any
|
||||
# questions.
|
||||
#
|
||||
|
||||
# Execute the test.
|
||||
# No need to compile (now done by JTReg tags in calling file)
|
||||
#
|
||||
echo ${TESTJAVA}/bin/java ${TESTVMOPTS} -Dtest.src=${TESTCLASSES} \
|
||||
-classpath ${TESTCLASSPATH} $* || exit 20
|
||||
|
||||
${TESTJAVA}/bin/java ${TESTVMOPTS} -Dtest.src=${TESTCLASSES} \
|
||||
-classpath ${TESTCLASSPATH} $* || exit 20
|
||||
|
||||
exit 0
|
@ -1,131 +0,0 @@
|
||||
#
|
||||
# Copyright (c) 2003, 2020, 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
|
||||
# under the terms of the GNU General Public License version 2 only, as
|
||||
# published by the Free Software Foundation.
|
||||
#
|
||||
# This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
# version 2 for more details (a copy is included in the LICENSE file that
|
||||
# accompanied this code).
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License version
|
||||
# 2 along with this work; if not, write to the Free Software Foundation,
|
||||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
# or visit www.oracle.com if you need additional information or have any
|
||||
# questions.
|
||||
#
|
||||
|
||||
#
|
||||
# Utility Shell Script for generating .properties files or .password files
|
||||
# or .access files from a list of input .in files.
|
||||
#
|
||||
# Source in this GeneratePropertyPassword.sh and call the function
|
||||
# generatePropertyPasswordFiles.
|
||||
# Call restoreFilePermissions to restore file permissions after the test completes
|
||||
#
|
||||
|
||||
|
||||
OS=`uname -s`
|
||||
UMASK=`umask`
|
||||
|
||||
case $OS in
|
||||
CYGWIN_NT*)
|
||||
OS="Windows_NT"
|
||||
if [ -z "$SystemRoot" ] ; then
|
||||
SystemRoot=`cygpath $SYSTEMROOT`
|
||||
fi
|
||||
esac
|
||||
|
||||
case $OS in
|
||||
Linux | Darwin | AIX )
|
||||
PATHSEP=":"
|
||||
FILESEP="/"
|
||||
DFILESEP=$FILESEP
|
||||
TMP_FILE=${TESTCLASSES}${FILESEP}${TESTCLASS}.sed.tmpfile
|
||||
|
||||
cat <<EOF > ${TMP_FILE}
|
||||
s^@TEST-SRC@/^${TESTCLASSES}${DFILESEP}^g
|
||||
EOF
|
||||
;;
|
||||
Windows_95 | Windows_98 | Windows_NT | Windows_ME | CYGWIN*)
|
||||
PATHSEP=";"
|
||||
FILESEP="\\"
|
||||
DFILESEP=$FILESEP$FILESEP
|
||||
TMP_FILE=${TESTCLASSES}${FILESEP}${TESTCLASS}.sed.tmpfile
|
||||
|
||||
cat <<EOF > ${TMP_FILE}0
|
||||
s^@TEST-SRC@/^${TESTCLASSES}${DFILESEP}^g
|
||||
EOF
|
||||
# Need to put double backslash in the .properties files
|
||||
cat ${TMP_FILE}0 | sed -e 's^\\\\^ZZZZ^g' | \
|
||||
sed -e 's^\\^ZZZZ^g' | \
|
||||
sed -e 's^ZZZZ^\\\\\\\\^g' > ${TMP_FILE}
|
||||
|
||||
if [ "$OS" = "Windows_NT" ]; then
|
||||
USER=`id -u -n`
|
||||
CACLS="$SystemRoot/system32/cacls.exe"
|
||||
REVOKEALL="$TESTNATIVEPATH/revokeall.exe"
|
||||
if [ ! -x "$REVOKEALL" ] ; then
|
||||
echo "$REVOKEALL doesn't exist or is not executable"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
echo "Unrecognized system! $OS"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
generatePropertyPasswordFiles()
|
||||
{
|
||||
for f in $@
|
||||
do
|
||||
echo processing $f
|
||||
suffix=`basename $f .in`
|
||||
f2="${TESTCLASSES}${FILESEP}${suffix}"
|
||||
|
||||
if [ -f "$f2" ] ; then
|
||||
rm -f $f2 || echo WARNING: $f2 already exits - unable to remove old copy
|
||||
fi
|
||||
|
||||
echo creating $f2
|
||||
sed -f $TMP_FILE $f > $f2
|
||||
|
||||
if [ "$OS" = "Windows_NT" ]; then
|
||||
chown $USER $f2
|
||||
# Grant this user full access
|
||||
echo Y|$CACLS $f2 \/E \/G $USER:F
|
||||
# Revoke everyone else
|
||||
$REVOKEALL $f2
|
||||
# Display ACLs
|
||||
$CACLS $f2
|
||||
else
|
||||
chmod 600 $f2
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
restoreFilePermissions()
|
||||
{
|
||||
for f in $@
|
||||
do
|
||||
suffix=`basename $f .in`
|
||||
f2="${TESTCLASSES}${FILESEP}${suffix}"
|
||||
|
||||
if [ "$OS" = "Windows_NT" ]; then
|
||||
# Grant everyone full control
|
||||
$CACLS $f2 \/E \/G Everyone:F
|
||||
else
|
||||
chmod 777 $f2
|
||||
fi
|
||||
|
||||
done
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,66 +0,0 @@
|
||||
#
|
||||
# Copyright (c) 2003, 2018, 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
|
||||
# under the terms of the GNU General Public License version 2 only, as
|
||||
# published by the Free Software Foundation.
|
||||
#
|
||||
# This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
# version 2 for more details (a copy is included in the LICENSE file that
|
||||
# accompanied this code).
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License version
|
||||
# 2 along with this work; if not, write to the Free Software Foundation,
|
||||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
# or visit www.oracle.com if you need additional information or have any
|
||||
# questions.
|
||||
#
|
||||
|
||||
#
|
||||
# @test
|
||||
# @bug 6528083
|
||||
# @key intermittent
|
||||
# @summary Test RMI Bootstrap
|
||||
#
|
||||
# @library /test/lib
|
||||
#
|
||||
# @build TestLogger Utils RmiBootstrapTest
|
||||
# @run shell/timeout=300 RmiBootstrapTest.sh
|
||||
|
||||
# Define the Java class test name
|
||||
TESTCLASS="RmiBootstrapTest"
|
||||
export TESTCLASS
|
||||
|
||||
# Source in utility shell script to generate and remove .properties and .acl files
|
||||
. ${TESTSRC}/GeneratePropertyPassword.sh
|
||||
|
||||
generatePropertyPasswordFiles `ls ${TESTSRC}/*_test*.in`
|
||||
|
||||
rm -rf ${TESTCLASSES}/ssl
|
||||
mkdir -p ${TESTCLASSES}/ssl
|
||||
cp -rf ${TESTSRC}/ssl/*store ${TESTCLASSES}/ssl
|
||||
chmod -R 777 ${TESTCLASSES}/ssl
|
||||
|
||||
DEBUGOPTIONS=""
|
||||
export DEBUGOPTIONS
|
||||
|
||||
EXTRAOPTIONS="--add-exports jdk.management.agent/jdk.internal.agent=ALL-UNNAMED \
|
||||
--add-exports jdk.management.agent/sun.management.jmxremote=ALL-UNNAMED"
|
||||
export EXTRAOPTIONS
|
||||
|
||||
# Call the common generic test
|
||||
#
|
||||
# No need to since bug 4267864 is now fixed.
|
||||
#
|
||||
echo -------------------------------------------------------------
|
||||
echo Launching test for `basename $0 .sh`
|
||||
echo -------------------------------------------------------------
|
||||
sh ${TESTSRC}/../RunTest.sh ${DEBUGOPTIONS} ${EXTRAOPTIONS} ${TESTCLASS}
|
||||
result=$?
|
||||
restoreFilePermissions `ls ${TESTSRC}/*_test*.in`
|
||||
exit $result
|
@ -1,64 +0,0 @@
|
||||
#
|
||||
# Copyright (c) 2003, 2018, 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
|
||||
# under the terms of the GNU General Public License version 2 only, as
|
||||
# published by the Free Software Foundation.
|
||||
#
|
||||
# This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
# version 2 for more details (a copy is included in the LICENSE file that
|
||||
# accompanied this code).
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License version
|
||||
# 2 along with this work; if not, write to the Free Software Foundation,
|
||||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
# or visit www.oracle.com if you need additional information or have any
|
||||
# questions.
|
||||
#
|
||||
|
||||
#
|
||||
# @test
|
||||
# @bug 6528083
|
||||
# @summary Test RMI Bootstrap with SSL
|
||||
#
|
||||
# @library /test/lib
|
||||
#
|
||||
# @build TestLogger Utils RmiBootstrapTest
|
||||
# @run shell/timeout=300 RmiSslBootstrapTest.sh
|
||||
|
||||
# Define the Java class test name
|
||||
TESTCLASS="RmiBootstrapTest"
|
||||
export TESTCLASS
|
||||
|
||||
# Source in utility shell script to generate and remove .properties and .acl files
|
||||
. ${TESTSRC}/GeneratePropertyPassword.sh
|
||||
|
||||
generatePropertyPasswordFiles `ls ${TESTSRC}/*_ssltest*.in`
|
||||
|
||||
rm -rf ${TESTCLASSES}/ssl
|
||||
mkdir -p ${TESTCLASSES}/ssl
|
||||
cp -rf ${TESTSRC}/ssl/*store ${TESTCLASSES}/ssl
|
||||
chmod -R 777 ${TESTCLASSES}/ssl
|
||||
|
||||
DEBUGOPTIONS=""
|
||||
export DEBUGOPTIONS
|
||||
|
||||
EXTRAOPTIONS="--add-exports jdk.management.agent/jdk.internal.agent=ALL-UNNAMED \
|
||||
--add-exports jdk.management.agent/sun.management.jmxremote=ALL-UNNAMED"
|
||||
export EXTRAOPTIONS
|
||||
|
||||
# Call the common generic test
|
||||
#
|
||||
echo -------------------------------------------------------------
|
||||
echo Launching test for `basename $0 .sh`
|
||||
echo -------------------------------------------------------------
|
||||
sh ${TESTSRC}/../RunTest.sh ${DEBUGOPTIONS} ${EXTRAOPTIONS} ${TESTCLASS} \
|
||||
${TESTCLASSES}/management_ssltest*.properties
|
||||
result=$?
|
||||
restoreFilePermissions `ls ${TESTSRC}/*_ssltest*.in`
|
||||
exit $result
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2003, 2022, 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
|
||||
@ -20,31 +20,37 @@
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import sun.management.jmxremote.ConnectorBootstrap;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.FilenameFilter;
|
||||
import java.io.IOException;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.security.GeneralSecurityException;
|
||||
import java.security.KeyStore;
|
||||
|
||||
import java.util.Properties;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
import java.util.Arrays;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Enumeration;
|
||||
|
||||
import javax.management.remote.*;
|
||||
import javax.management.*;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import jdk.internal.agent.AgentConfigurationError;
|
||||
|
||||
import javax.management.remote.JMXConnector;
|
||||
import javax.management.remote.JMXConnectorFactory;
|
||||
import javax.management.remote.JMXConnectorServer;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 4932854
|
||||
* @key intermittent
|
||||
* @summary Test RMI Bootstrap with SSL and no keystore.
|
||||
*
|
||||
* @library /test/lib
|
||||
*
|
||||
* @run main/timeout=300 RmiSslNoKeyStoreTest .*_ssltest.*.in
|
||||
* */
|
||||
|
||||
/**
|
||||
* <p>This class implements unit test for RMI Bootstrap.
|
||||
* When called with no arguments main() looks in the directory indicated
|
||||
@ -69,163 +75,113 @@ import jdk.internal.agent.AgentConfigurationError;
|
||||
*
|
||||
* <p>Debug traces are logged in "sun.management.test"</p>
|
||||
**/
|
||||
public class RmiSslNoKeyStoreTest {
|
||||
|
||||
static TestLogger log =
|
||||
new TestLogger("RmiSslNoKeyStoreTest");
|
||||
public class RmiSslNoKeyStoreTest extends RmiTestBase {
|
||||
|
||||
static TestLogger log = new TestLogger("RmiSslNoKeyStoreTest");
|
||||
/**
|
||||
* When launching several registries, we increment the port number
|
||||
* to avoid falling into "port number already in use" problems.
|
||||
**/
|
||||
static int testPort = 0;
|
||||
|
||||
/**
|
||||
* Default values for RMI configuration properties.
|
||||
**/
|
||||
public static interface DefaultValues {
|
||||
public static final String PORT="0";
|
||||
public static final String CONFIG_FILE_NAME="management.properties";
|
||||
public static final String USE_SSL="true";
|
||||
public static final String USE_AUTHENTICATION="true";
|
||||
public static final String PASSWORD_FILE_NAME="jmxremote.password";
|
||||
public static final String ACCESS_FILE_NAME="jmxremote.access";
|
||||
public static final String KEYSTORE="keystore";
|
||||
public static final String KEYSTORE_PASSWD="password";
|
||||
public static final String TRUSTSTORE="truststore";
|
||||
public static final String TRUSTSTORE_PASSWD="trustword";
|
||||
}
|
||||
|
||||
/**
|
||||
* Names of RMI configuration properties.
|
||||
**/
|
||||
public static interface PropertyNames {
|
||||
public static final String PORT="com.sun.management.jmxremote.port";
|
||||
public static final String CONFIG_FILE_NAME=
|
||||
"com.sun.management.config.file";
|
||||
public static final String USE_SSL="com.sun.management.jmxremote.ssl";
|
||||
public static final String USE_AUTHENTICATION=
|
||||
"com.sun.management.jmxremote.authenticate";
|
||||
public static final String PASSWORD_FILE_NAME=
|
||||
"com.sun.management.jmxremote.password.file";
|
||||
public static final String ACCESS_FILE_NAME=
|
||||
"com.sun.management.jmxremote.access.file";
|
||||
public static final String INSTRUMENT_ALL=
|
||||
"com.sun.management.instrumentall";
|
||||
public static final String CREDENTIALS =
|
||||
"jmx.remote.credentials";
|
||||
public static final String KEYSTORE="javax.net.ssl.keyStore";
|
||||
public static final String KEYSTORE_PASSWD=
|
||||
"javax.net.ssl.keyStorePassword";
|
||||
public static final String KEYSTORE_TYPE="javax.net.ssl.keyStoreType";
|
||||
public static final String TRUSTSTORE="javax.net.ssl.trustStore";
|
||||
public static final String TRUSTSTORE_PASSWD=
|
||||
"javax.net.ssl.trustStorePassword";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute the full path name for a default file.
|
||||
* @param basename basename (with extension) of the default file.
|
||||
* @return ${JRE}/conf/management/${basename}
|
||||
**/
|
||||
private static String getDefaultFileName(String basename) {
|
||||
final String fileSeparator = File.separator;
|
||||
final StringBuffer defaultFileName =
|
||||
new StringBuffer(System.getProperty("java.home")).
|
||||
append(fileSeparator).append("conf").append(fileSeparator).
|
||||
append("management").append(fileSeparator).
|
||||
append(basename);
|
||||
return defaultFileName.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute the full path name for a default file.
|
||||
* @param basename basename (with extension) of the default file.
|
||||
* @return ${JRE}/conf/management/${basename}
|
||||
**/
|
||||
private static String getDefaultStoreName(String basename) {
|
||||
final String fileSeparator = File.separator;
|
||||
final StringBuffer defaultFileName =
|
||||
new StringBuffer(System.getProperty("test.src")).
|
||||
append(fileSeparator).append("ssl").append(fileSeparator).
|
||||
append(basename);
|
||||
return defaultFileName.toString();
|
||||
}
|
||||
final String DEFAULT_KEY_STORE = defaultStoreNamePrefix + DefaultValues.KEYSTORE;
|
||||
final String KEY_STORE = System.getProperty(PropertyNames.KEYSTORE, DEFAULT_KEY_STORE);
|
||||
|
||||
private static void checkKeystore(Properties props)
|
||||
throws IOException, GeneralSecurityException {
|
||||
if (log.isDebugOn())
|
||||
log.debug("checkKeystore","Checking Keystore configuration");
|
||||
throws IOException, GeneralSecurityException {
|
||||
if (log.isDebugOn()) {
|
||||
log.debug("checkKeystore", "Checking Keystore configuration");
|
||||
}
|
||||
|
||||
final String keyStore =
|
||||
System.getProperty(PropertyNames.KEYSTORE);
|
||||
if (keyStore == null)
|
||||
throw new IllegalArgumentException("System property " +
|
||||
PropertyNames.KEYSTORE +
|
||||
" not specified");
|
||||
final String keyStore = System.getProperty(PropertyNames.KEYSTORE);
|
||||
if (keyStore == null) {
|
||||
throw new IllegalArgumentException("System property " + PropertyNames.KEYSTORE + " not specified");
|
||||
}
|
||||
|
||||
final String keyStorePass =
|
||||
System.getProperty(PropertyNames.KEYSTORE_PASSWD);
|
||||
final String keyStorePass = System.getProperty(PropertyNames.KEYSTORE_PASSWD);
|
||||
if (keyStorePass == null) {
|
||||
// We don't have the password, we can only check whether the
|
||||
// file exists...
|
||||
//
|
||||
final File ksf = new File(keyStore);
|
||||
if (! ksf.canRead())
|
||||
if (!ksf.canRead()) {
|
||||
throw new IOException(keyStore + ": not readable");
|
||||
}
|
||||
|
||||
if (log.isDebugOn())
|
||||
if (log.isDebugOn()) {
|
||||
log.debug("checkSSL", "No password.");
|
||||
throw new IllegalArgumentException("System property " +
|
||||
PropertyNames.KEYSTORE_PASSWD +
|
||||
" not specified");
|
||||
}
|
||||
throw new IllegalArgumentException("System property " + PropertyNames.KEYSTORE_PASSWD + " not specified");
|
||||
}
|
||||
|
||||
// Now we're going to load the keyStore - just to check it's
|
||||
// correct.
|
||||
//
|
||||
final String keyStoreType =
|
||||
System.getProperty(PropertyNames.KEYSTORE_TYPE,
|
||||
KeyStore.getDefaultType());
|
||||
final KeyStore ks = KeyStore.getInstance(keyStoreType);
|
||||
final String keyStoreType = System.getProperty(PropertyNames.KEYSTORE_TYPE, KeyStore.getDefaultType());
|
||||
final KeyStore ks = KeyStore.getInstance(keyStoreType);
|
||||
final FileInputStream fin = new FileInputStream(keyStore);
|
||||
final char keypassword[] = keyStorePass.toCharArray();
|
||||
final char keypassword[] = keyStorePass.toCharArray();
|
||||
|
||||
try {
|
||||
ks.load(fin,keypassword);
|
||||
ks.load(fin, keypassword);
|
||||
} finally {
|
||||
Arrays.fill(keypassword,' ');
|
||||
Arrays.fill(keypassword, ' ');
|
||||
fin.close();
|
||||
}
|
||||
|
||||
if (log.isDebugOn())
|
||||
log.debug("checkSSL","SSL configuration successfully checked");
|
||||
if (log.isDebugOn()) {
|
||||
log.debug("checkSSL", "SSL configuration successfully checked");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls run(args[]).
|
||||
* exit(1) if the test fails.
|
||||
**/
|
||||
public static void main(String args[]) throws Exception {
|
||||
if (args.length == 0) {
|
||||
throw new IllegalArgumentException("Argument is required for this" + " test");
|
||||
}
|
||||
|
||||
final List<Path> credentialFiles = prepareTestFiles(args[0]);
|
||||
|
||||
RmiSslNoKeyStoreTest manager = new RmiSslNoKeyStoreTest();
|
||||
try {
|
||||
manager.run(args);
|
||||
} catch (RuntimeException r) {
|
||||
System.err.println("Test Failed: " + r.getMessage());
|
||||
System.exit(1);
|
||||
} catch (Throwable t) {
|
||||
System.err.println("Test Failed: " + t);
|
||||
t.printStackTrace();
|
||||
System.exit(2);
|
||||
}
|
||||
System.out.println("**** Test RmiSslNoKeyStoreTest Passed ****");
|
||||
|
||||
grantFilesAccess(credentialFiles, AccessControl.EVERYONE);
|
||||
}
|
||||
|
||||
private void checkSslConfiguration() throws Exception {
|
||||
final String defaultConf =
|
||||
getDefaultFileName(DefaultValues.CONFIG_FILE_NAME);
|
||||
final String confname =
|
||||
System.getProperty(PropertyNames.CONFIG_FILE_NAME,defaultConf);
|
||||
final String defaultConf = defaultFileNamePrefix + DefaultValues.CONFIG_FILE_NAME;
|
||||
final String confname = System.getProperty(PropertyNames.CONFIG_FILE_NAME, defaultConf);
|
||||
|
||||
final Properties props = new Properties();
|
||||
final File conf = new File(confname);
|
||||
if (conf.exists()) {
|
||||
FileInputStream fin = new FileInputStream(conf);
|
||||
try {props.load(fin);} finally {fin.close();}
|
||||
try {
|
||||
props.load(fin);
|
||||
} finally {
|
||||
fin.close();
|
||||
}
|
||||
}
|
||||
|
||||
// Do we use SSL?
|
||||
final String useSslStr =
|
||||
props.getProperty(PropertyNames.USE_SSL,
|
||||
DefaultValues.USE_SSL);
|
||||
final boolean useSsl =
|
||||
Boolean.valueOf(useSslStr).booleanValue();
|
||||
final String useSslStr = props.getProperty(PropertyNames.USE_SSL, DefaultValues.USE_SSL);
|
||||
final boolean useSsl = Boolean.valueOf(useSslStr).booleanValue();
|
||||
|
||||
log.debug("checkSslConfiguration",PropertyNames.USE_SSL+"="+useSsl);
|
||||
log.debug("checkSslConfiguration", PropertyNames.USE_SSL + "=" + useSsl);
|
||||
if (useSsl == false) {
|
||||
final String msg =
|
||||
PropertyNames.USE_SSL+"="+useSsl+", can't run test";
|
||||
final String msg = PropertyNames.USE_SSL + "=" + useSsl + ", can't run test";
|
||||
throw new IllegalArgumentException(msg);
|
||||
}
|
||||
|
||||
@ -233,7 +189,7 @@ public class RmiSslNoKeyStoreTest {
|
||||
checkKeystore(props);
|
||||
} catch (Exception x) {
|
||||
// Ok!
|
||||
log.debug("checkSslConfiguration","Test configuration OK: " + x);
|
||||
log.debug("checkSslConfiguration", "Test configuration OK: " + x);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -246,31 +202,30 @@ public class RmiSslNoKeyStoreTest {
|
||||
* Sets the appropriate System properties for config file and
|
||||
* port and then calls ConnectorBootstrap.initialize().
|
||||
* eventually cleans up by calling ConnectorBootstrap.terminate().
|
||||
*
|
||||
* @return null if the test succeeds, an error message otherwise.
|
||||
**/
|
||||
private String testConfiguration(File file,int port) {
|
||||
private String testConfiguration(File file, int port) {
|
||||
|
||||
final String path = (file==null)?null:file.getAbsolutePath();
|
||||
final String config = (path==null)?"Default config file":path;
|
||||
final String path = (file == null) ? null : file.getAbsolutePath();
|
||||
final String config = (path == null) ? "Default config file" : path;
|
||||
|
||||
try {
|
||||
System.out.println("***");
|
||||
System.out.println("*** Testing configuration (port="+
|
||||
port + "): "+ path);
|
||||
System.out.println("*** Testing configuration (port=" + port + "): " + path);
|
||||
System.out.println("***");
|
||||
|
||||
System.setProperty("com.sun.management.jmxremote.port",
|
||||
Integer.toString(port));
|
||||
if (path != null)
|
||||
System.setProperty("com.sun.management.jmxremote.port", Integer.toString(port));
|
||||
if (path != null) {
|
||||
System.setProperty("com.sun.management.config.file", path);
|
||||
else
|
||||
System.getProperties().
|
||||
remove("com.sun.management.config.file");
|
||||
} else {
|
||||
System.getProperties().remove("com.sun.management.config.file");
|
||||
}
|
||||
|
||||
log.trace("testConfiguration","com.sun.management.jmxremote.port="+port);
|
||||
if (path != null && log.isDebugOn())
|
||||
log.trace("testConfiguration",
|
||||
"com.sun.management.config.file="+path);
|
||||
log.trace("testConfiguration", "com.sun.management.jmxremote.port=" + port);
|
||||
if (path != null && log.isDebugOn()) {
|
||||
log.trace("testConfiguration", "com.sun.management.config.file=" + path);
|
||||
}
|
||||
|
||||
checkSslConfiguration();
|
||||
|
||||
@ -278,61 +233,52 @@ public class RmiSslNoKeyStoreTest {
|
||||
try {
|
||||
cs = ConnectorBootstrap.initialize();
|
||||
} catch (AgentConfigurationError x) {
|
||||
final String err = "Failed to initialize connector:" +
|
||||
"\n\tcom.sun.management.jmxremote.port=" + port +
|
||||
((path!=null)?"\n\tcom.sun.management.config.file="+path:
|
||||
"\n\t"+config) +
|
||||
"\n\tError is: " + x;
|
||||
final String err = "Failed to initialize connector:" + "\n\tcom.sun.management.jmxremote.port=" + port +
|
||||
((path != null) ? "\n\tcom.sun.management.config.file=" + path : "\n\t" + config) +
|
||||
"\n\tError is: " + x;
|
||||
|
||||
log.trace("testConfiguration","Expected failure: " + err);
|
||||
log.debug("testConfiguration",x);
|
||||
log.trace("testConfiguration", "Expected failure: " + err);
|
||||
log.debug("testConfiguration", x);
|
||||
System.out.println("Got expected failure: " + x);
|
||||
return null;
|
||||
} catch (Exception x) {
|
||||
log.debug("testConfiguration",x);
|
||||
log.debug("testConfiguration", x);
|
||||
return x.toString();
|
||||
}
|
||||
try {
|
||||
JMXConnector cc =
|
||||
JMXConnectorFactory.connect(cs.getAddress(), null);
|
||||
JMXConnector cc = JMXConnectorFactory.connect(cs.getAddress(), null);
|
||||
cc.close();
|
||||
} catch (IOException x) {
|
||||
final String err = "Failed to initialize connector:" +
|
||||
"\n\tcom.sun.management.jmxremote.port=" + port +
|
||||
((path!=null)?"\n\tcom.sun.management.config.file="+path:
|
||||
"\n\t"+config) +
|
||||
"\n\tError is: " + x;
|
||||
final String err = "Failed to initialize connector:" + "\n\tcom.sun.management.jmxremote.port=" + port +
|
||||
((path != null) ? "\n\tcom.sun.management.config.file=" + path : "\n\t" + config) +
|
||||
"\n\tError is: " + x;
|
||||
|
||||
log.trace("testConfiguration","Expected failure: " + err);
|
||||
log.debug("testConfiguration",x);
|
||||
log.trace("testConfiguration", "Expected failure: " + err);
|
||||
log.debug("testConfiguration", x);
|
||||
System.out.println("Got expected failure: " + x);
|
||||
return null;
|
||||
} catch (Exception x) {
|
||||
log.debug("testConfiguration",x);
|
||||
log.debug("testConfiguration", x);
|
||||
return x.toString();
|
||||
}
|
||||
try {
|
||||
cs.stop();
|
||||
} catch (Exception x) {
|
||||
final String err = "Failed to terminate: "+x;
|
||||
log.trace("testConfiguration",err);
|
||||
log.debug("testConfiguration",x);
|
||||
final String err = "Failed to terminate: " + x;
|
||||
log.trace("testConfiguration", err);
|
||||
log.debug("testConfiguration", x);
|
||||
}
|
||||
final String err = "Bootstrap should have failed:" +
|
||||
"\n\tcom.sun.management.jmxremote.port=" + port +
|
||||
((path!=null)?"\n\tcom.sun.management.config.file="+path:
|
||||
"\n\t"+config);
|
||||
log.trace("testConfiguration",err);
|
||||
final String err = "Bootstrap should have failed:" + "\n\tcom.sun.management.jmxremote.port=" + port +
|
||||
((path != null) ? "\n\tcom.sun.management.config.file=" + path : "\n\t" + config);
|
||||
log.trace("testConfiguration", err);
|
||||
return err;
|
||||
} catch (Exception x) {
|
||||
final String err = "Failed to test bootstrap for:" +
|
||||
"\n\tcom.sun.management.jmxremote.port=" + port +
|
||||
((path!=null)?"\n\tcom.sun.management.config.file="+path:
|
||||
"\n\t"+config)+
|
||||
"\n\tError is: " + x;
|
||||
final String err = "Failed to test bootstrap for:" + "\n\tcom.sun.management.jmxremote.port=" + port +
|
||||
((path != null) ? "\n\tcom.sun.management.config.file=" + path : "\n\t" + config) +
|
||||
"\n\tError is: " + x;
|
||||
|
||||
log.trace("testConfiguration",err);
|
||||
log.debug("testConfiguration",x);
|
||||
log.trace("testConfiguration", err);
|
||||
log.debug("testConfiguration", x);
|
||||
return err;
|
||||
}
|
||||
}
|
||||
@ -340,18 +286,64 @@ public class RmiSslNoKeyStoreTest {
|
||||
/**
|
||||
* Test a configuration file. Determines whether the bootstrap
|
||||
* should succeed or fail depending on the file name:
|
||||
* *ok.properties: bootstrap should succeed.
|
||||
* *ko.properties: bootstrap or connection should fail.
|
||||
* *ok.properties: bootstrap should succeed.
|
||||
* *ko.properties: bootstrap or connection should fail.
|
||||
*
|
||||
* @return null if the test succeeds, an error message otherwise.
|
||||
**/
|
||||
private String testConfigurationFile(String fileName) {
|
||||
File file = new File(fileName);
|
||||
final String portStr = System.getProperty("rmi.port","12424");
|
||||
final int port = Integer.parseInt(portStr);
|
||||
final String portStr = System.getProperty("rmi.port", "12424");
|
||||
final int port = Integer.parseInt(portStr);
|
||||
|
||||
return testConfiguration(file,port+testPort++);
|
||||
return testConfiguration(file, port + testPort++);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test a configuration file.
|
||||
**/
|
||||
private void runConfigurationFile(String fileName) {
|
||||
String errStr = testConfigurationFile(fileName);
|
||||
if (errStr != null) {
|
||||
throw new RuntimeException(errStr);
|
||||
}
|
||||
|
||||
if ((System.getProperty(PropertyNames.KEYSTORE) == null) &&
|
||||
(System.getProperty(PropertyNames.KEYSTORE_PASSWD) == null)) {
|
||||
try {
|
||||
|
||||
// Specify the keystore, but don't specify the
|
||||
// password.
|
||||
//
|
||||
System.setProperty(PropertyNames.KEYSTORE, KEY_STORE);
|
||||
log.trace("run", PropertyNames.KEYSTORE + "=" + KEY_STORE);
|
||||
|
||||
errStr = testConfigurationFile(fileName);
|
||||
if (errStr != null) {
|
||||
throw new RuntimeException(errStr);
|
||||
}
|
||||
} finally {
|
||||
System.getProperties().remove(PropertyNames.KEYSTORE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds all configuration files (*ok.properties and *ko.properties)
|
||||
* and tests them.
|
||||
*
|
||||
* @throws RuntimeException if the test fails.
|
||||
**/
|
||||
public void run(boolean useSsl) throws IOException {
|
||||
final File[] conf = findAllConfigurationFiles(useSsl);
|
||||
if ((conf == null) || (conf.length == 0)) {
|
||||
throw new RuntimeException("No configuration found");
|
||||
}
|
||||
|
||||
for (int i = 0; i < conf.length; i++) {
|
||||
runConfigurationFile(conf[i].toPath().toString());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the specified configuration files.
|
||||
@ -360,59 +352,16 @@ public class RmiSslNoKeyStoreTest {
|
||||
* Otherwise, the configuration files will be automatically determined
|
||||
* by looking at all *.properties files located in the directory
|
||||
* indicated by the System property "test.src".
|
||||
*
|
||||
* @throws RuntimeException if the test fails.
|
||||
**/
|
||||
public void run(String args[]) {
|
||||
final String defaultKeyStore =
|
||||
getDefaultStoreName(DefaultValues.KEYSTORE);
|
||||
final String keyStore =
|
||||
System.getProperty(PropertyNames.KEYSTORE, defaultKeyStore);
|
||||
|
||||
for (int i=0; i<args.length; i++) {
|
||||
|
||||
String errStr =testConfigurationFile(args[i]);
|
||||
if (errStr != null) {
|
||||
throw new RuntimeException(errStr);
|
||||
}
|
||||
|
||||
if ((System.getProperty(PropertyNames.KEYSTORE) == null) &&
|
||||
(System.getProperty(PropertyNames.KEYSTORE_PASSWD) == null)) {
|
||||
try {
|
||||
|
||||
// Specify the keystore, but don't specify the
|
||||
// password.
|
||||
//
|
||||
System.setProperty(PropertyNames.KEYSTORE,keyStore);
|
||||
log.trace("run",PropertyNames.KEYSTORE+"="+keyStore);
|
||||
|
||||
errStr =testConfigurationFile(args[i]);
|
||||
if (errStr != null) {
|
||||
throw new RuntimeException(errStr);
|
||||
}
|
||||
} finally {
|
||||
System.getProperties().remove(PropertyNames.KEYSTORE);
|
||||
}
|
||||
public void run(String args[]) throws IOException {
|
||||
if (args.length == 1) {
|
||||
run(args[0].contains("ssl"));
|
||||
} else {
|
||||
for (int i = 1; i < args.length; i++) {
|
||||
runConfigurationFile(args[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls run(args[]).
|
||||
* exit(1) if the test fails.
|
||||
**/
|
||||
public static void main(String args[]) {
|
||||
RmiSslNoKeyStoreTest manager = new RmiSslNoKeyStoreTest();
|
||||
try {
|
||||
manager.run(args);
|
||||
} catch (RuntimeException r) {
|
||||
System.err.println("Test Failed: "+ r.getMessage());
|
||||
System.exit(1);
|
||||
} catch (Throwable t) {
|
||||
System.err.println("Test Failed: "+ t);
|
||||
t.printStackTrace();
|
||||
System.exit(2);
|
||||
}
|
||||
System.out.println("**** Test RmiSslNoKeyStoreTest Passed ****");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,62 +0,0 @@
|
||||
#
|
||||
# Copyright (c) 2003, 2015, 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
|
||||
# under the terms of the GNU General Public License version 2 only, as
|
||||
# published by the Free Software Foundation.
|
||||
#
|
||||
# This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
# version 2 for more details (a copy is included in the LICENSE file that
|
||||
# accompanied this code).
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License version
|
||||
# 2 along with this work; if not, write to the Free Software Foundation,
|
||||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
# or visit www.oracle.com if you need additional information or have any
|
||||
# questions.
|
||||
#
|
||||
|
||||
#
|
||||
# @test
|
||||
# @summary Test RMI Bootstrap with SSL and no keystore.
|
||||
# @bug 4932854
|
||||
#
|
||||
# @build TestLogger RmiSslNoKeyStoreTest
|
||||
# @run shell/timeout=300 RmiSslNoKeyStoreTest.sh
|
||||
|
||||
# Define the Java class test name
|
||||
TESTCLASS="RmiSslNoKeyStoreTest"
|
||||
export TESTCLASS
|
||||
|
||||
# Source in utility shell script to generate and remove .properties and .acl files
|
||||
. ${TESTSRC}/GeneratePropertyPassword.sh
|
||||
|
||||
generatePropertyPasswordFiles `ls ${TESTSRC}/*_ssltest*.in`
|
||||
|
||||
rm -rf ${TESTCLASSES}/ssl
|
||||
mkdir -p ${TESTCLASSES}/ssl
|
||||
cp -rf ${TESTSRC}/ssl/*store ${TESTCLASSES}/ssl
|
||||
chmod -R 777 ${TESTCLASSES}/ssl
|
||||
|
||||
DEBUGOPTIONS=""
|
||||
export DEBUGOPTIONS
|
||||
|
||||
EXTRAOPTIONS="--add-exports jdk.management.agent/jdk.internal.agent=ALL-UNNAMED \
|
||||
--add-exports jdk.management.agent/sun.management.jmxremote=ALL-UNNAMED"
|
||||
export EXTRAOPTIONS
|
||||
|
||||
# Call the common generic test
|
||||
#
|
||||
echo -------------------------------------------------------------
|
||||
echo Launching test for `basename $0 .sh`
|
||||
echo -------------------------------------------------------------
|
||||
sh ${TESTSRC}/../RunTest.sh ${DEBUGOPTIONS} ${EXTRAOPTIONS} ${TESTCLASS} \
|
||||
${TESTCLASSES}/management_ssltest*.properties
|
||||
result=$?
|
||||
restoreFilePermissions `ls ${TESTSRC}/*_ssltest*.in`
|
||||
exit $result
|
265
test/jdk/sun/management/jmxremote/bootstrap/RmiTestBase.java
Normal file
265
test/jdk/sun/management/jmxremote/bootstrap/RmiTestBase.java
Normal file
@ -0,0 +1,265 @@
|
||||
/*
|
||||
* Copyright (c) 2022, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @library /test/lib
|
||||
* */
|
||||
|
||||
import jdk.test.lib.Platform;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.nio.file.attribute.AclEntry;
|
||||
import java.nio.file.attribute.AclEntryType;
|
||||
import java.nio.file.attribute.AclFileAttributeView;
|
||||
import java.nio.file.attribute.PosixFilePermissions;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class RmiTestBase {
|
||||
static final String SEP = System.getProperty("file.separator");
|
||||
static final String SRC = System.getProperty("test.src");
|
||||
static final String DEST = System.getProperty("test.classes");
|
||||
static final String SRC_SSL = SRC + SEP + "ssl";
|
||||
static final String DEST_SSL = DEST + SEP + "ssl";
|
||||
static final String TEST_SRC = "@TEST-SRC@";
|
||||
|
||||
static final String defaultFileNamePrefix =
|
||||
System.getProperty("java" + ".home") + SEP + "conf" + SEP + "management" + SEP;
|
||||
|
||||
static final String defaultStoreNamePrefix = SRC + SEP + "ssl" + SEP;
|
||||
|
||||
/**
|
||||
* A filter to find all filenames who match <prefix>*<suffix>.
|
||||
* Note that <prefix> and <suffix> can overlap.
|
||||
**/
|
||||
static class FilenameFilterFactory {
|
||||
static FilenameFilter prefixSuffix(final String p, final String s) {
|
||||
return (dir, name) -> name.startsWith(p) && name.endsWith(s);
|
||||
}
|
||||
}
|
||||
|
||||
enum AccessControl {
|
||||
OWNER,
|
||||
EVERYONE,
|
||||
}
|
||||
|
||||
/**
|
||||
* Default values for RMI configuration properties.
|
||||
**/
|
||||
public interface DefaultValues {
|
||||
String PORT = "0";
|
||||
String CONFIG_FILE_NAME = "management.properties";
|
||||
String USE_SSL = "true";
|
||||
String USE_AUTHENTICATION = "true";
|
||||
String PASSWORD_FILE_NAME = "jmxremote.password";
|
||||
String ACCESS_FILE_NAME = "jmxremote.access";
|
||||
String KEYSTORE = "keystore";
|
||||
String KEYSTORE_PASSWD = "password";
|
||||
String TRUSTSTORE = "truststore";
|
||||
String TRUSTSTORE_PASSWD = "trustword";
|
||||
String SSL_NEED_CLIENT_AUTH = "false";
|
||||
}
|
||||
|
||||
/**
|
||||
* Names of RMI configuration properties.
|
||||
**/
|
||||
public interface PropertyNames {
|
||||
String PORT = "com.sun.management.jmxremote.port";
|
||||
String CONFIG_FILE_NAME = "com.sun.management.config.file";
|
||||
String USE_SSL = "com.sun.management.jmxremote.ssl";
|
||||
String USE_AUTHENTICATION = "com.sun.management.jmxremote.authenticate";
|
||||
String PASSWORD_FILE_NAME = "com.sun.management.jmxremote.password.file";
|
||||
String ACCESS_FILE_NAME = "com.sun.management.jmxremote.access.file";
|
||||
String INSTRUMENT_ALL = "com.sun.management.instrumentall";
|
||||
String CREDENTIALS = "jmx.remote.credentials";
|
||||
String KEYSTORE = "javax.net.ssl.keyStore";
|
||||
String KEYSTORE_PASSWD = "javax.net.ssl.keyStorePassword";
|
||||
String KEYSTORE_TYPE = "javax.net.ssl.keyStoreType";
|
||||
String TRUSTSTORE = "javax.net.ssl.trustStore";
|
||||
String TRUSTSTORE_PASSWD = "javax.net.ssl.trustStorePassword";
|
||||
String SSL_ENABLED_CIPHER_SUITES = "com.sun.management.jmxremote.ssl.enabled.cipher.suites";
|
||||
String SSL_ENABLED_PROTOCOLS = "com.sun.management.jmxremote.ssl.enabled.protocols";
|
||||
String SSL_NEED_CLIENT_AUTH = "com.sun.management.jmxremote.ssl.need.client.auth";
|
||||
String SSL_CLIENT_ENABLED_CIPHER_SUITES = "javax.rmi.ssl.client.enabledCipherSuites";
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy test artifacts to test folder.
|
||||
*
|
||||
* @param filenamePattern the filename pattern to look for
|
||||
* @return files who match the filename pattern
|
||||
* @throws IOException if error occurs
|
||||
*/
|
||||
static List<Path> prepareTestFiles(String filenamePattern) throws IOException {
|
||||
copySsl();
|
||||
List<Path> files = Utils.findFiles(Paths.get(SRC), (dir, name) -> name.matches(filenamePattern));
|
||||
|
||||
final Function<String, String> removeSuffix = (s) -> s.substring(0, s.lastIndexOf("."));
|
||||
|
||||
List<Path> propertyFiles =
|
||||
Utils.copyFiles(files, Paths.get(DEST), removeSuffix, StandardCopyOption.REPLACE_EXISTING);
|
||||
|
||||
// replace @TEST-SRC@ with the path of the current test folder
|
||||
if (Platform.isWindows()) {
|
||||
// On Windows, also replace forward slash or single backslash to double backslashes
|
||||
Utils.replaceFilesString(propertyFiles,
|
||||
(s) -> s.replace(TEST_SRC, DEST).replaceAll("[/\\\\]", "\\\\\\\\"));
|
||||
} else {
|
||||
Utils.replaceFilesString(propertyFiles, (s) -> s.replace(TEST_SRC, DEST));
|
||||
}
|
||||
|
||||
grantFilesAccess(propertyFiles, AccessControl.OWNER);
|
||||
|
||||
return Collections.unmodifiableList(files);
|
||||
}
|
||||
|
||||
/**
|
||||
* Grant file access.
|
||||
*
|
||||
* @param file file to grant access
|
||||
* @param access user access or full access
|
||||
* @throws IOException if error occurs
|
||||
*/
|
||||
static void grantAccess(Path file, AccessControl access) throws IOException {
|
||||
Set<String> attr = file.getFileSystem().supportedFileAttributeViews();
|
||||
if (attr.contains("posix")) {
|
||||
String perms = access == AccessControl.OWNER ? "rw-------" : "rwxrwxrwx";
|
||||
Files.setPosixFilePermissions(file, PosixFilePermissions.fromString(perms));
|
||||
} else if (attr.contains("acl")) {
|
||||
AclFileAttributeView view = Files.getFileAttributeView(file, AclFileAttributeView.class);
|
||||
List<AclEntry> acl = new ArrayList<>();
|
||||
for (AclEntry thisEntry : view.getAcl()) {
|
||||
if (access == AccessControl.OWNER) {
|
||||
if (thisEntry.principal().getName().equals(view.getOwner().getName())) {
|
||||
acl.add(Utils.allowAccess(thisEntry));
|
||||
} else if (thisEntry.type() == AclEntryType.ALLOW) {
|
||||
acl.add(Utils.revokeAccess(thisEntry));
|
||||
} else {
|
||||
acl.add(thisEntry);
|
||||
}
|
||||
} else {
|
||||
if (!thisEntry.principal().getName().contains("NULL SID")
|
||||
&& thisEntry.type() != AclEntryType.ALLOW) {
|
||||
acl.add(Utils.allowAccess(thisEntry));
|
||||
} else {
|
||||
acl.add(thisEntry);
|
||||
}
|
||||
}
|
||||
}
|
||||
view.setAcl(acl);
|
||||
} else {
|
||||
throw new RuntimeException("Unsupported file attributes: " + attr);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Grant files' access.
|
||||
*
|
||||
* @param files files to grant access
|
||||
* @param access user access or full access
|
||||
* @throws IOException if error occurs
|
||||
*/
|
||||
static void grantFilesAccess(List<Path> files, AccessControl access) throws IOException {
|
||||
for (Path thisFile : files) {
|
||||
grantAccess(thisFile, access);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy SSL files to test folder.
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
static void copySsl() throws IOException {
|
||||
Path sslSource = Paths.get(SRC_SSL);
|
||||
Path sslTarget = Paths.get(DEST_SSL);
|
||||
|
||||
List<Path> files = Arrays.stream(sslSource.toFile().listFiles()).map(File::toPath).collect(Collectors.toList());
|
||||
Utils.copyFiles(files, sslTarget, StandardCopyOption.REPLACE_EXISTING);
|
||||
|
||||
for (Path file : files) {
|
||||
grantAccess(sslTarget.resolve(file.getFileName()), AccessControl.EVERYONE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all "management*ok.properties" files in the directory
|
||||
* indicated by the "test.src" management property.
|
||||
*
|
||||
* @param useSsl boolean that indicates if test uses SSL
|
||||
* @return configuration files
|
||||
**/
|
||||
static File[] findConfigurationFilesOk(boolean useSsl) {
|
||||
String prefix = useSsl ? "management_ssltest" : "management_test";
|
||||
return findAllConfigurationFiles(prefix, "ok.properties");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all "management*ko.properties" files in the directory
|
||||
* indicated by the "test.src" management property.
|
||||
*
|
||||
* @param useSsl boolean that indicates if test uses SSL
|
||||
* @return configuration files
|
||||
**/
|
||||
static File[] findConfigurationFilesKo(boolean useSsl) {
|
||||
String prefix = useSsl ? "management_ssltest" : "management_test";
|
||||
return findAllConfigurationFiles(prefix, "ko.properties");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all "management*.properties" files in the directory
|
||||
* indicated by the "test.src" management property.
|
||||
*
|
||||
* @param useSsl boolean that indicates if test uses SSL
|
||||
* @return configuration files
|
||||
**/
|
||||
static File[] findAllConfigurationFiles(boolean useSsl) {
|
||||
String prefix = useSsl ? "management_ssltest" : "management_test";
|
||||
return findAllConfigurationFiles(prefix, "properties");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all "management*.properties" files in the directory
|
||||
* indicated by the "test.src" management property.
|
||||
*
|
||||
* @param prefix filename prefix
|
||||
* @param suffix filename suffix
|
||||
* @return configuration files
|
||||
**/
|
||||
static File[] findAllConfigurationFiles(String prefix, String suffix) {
|
||||
final File dir = new File(DEST);
|
||||
final FilenameFilter filter = FilenameFilterFactory.prefixSuffix(prefix, suffix);
|
||||
return dir.listFiles(filter);
|
||||
}
|
||||
}
|
@ -21,6 +21,15 @@
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.file.CopyOption;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.attribute.*;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Utility class.
|
||||
*/
|
||||
@ -46,4 +55,141 @@ public class Utils {
|
||||
String newPath = new String(cs);
|
||||
return newPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return file directories that satisfy the specified filter.
|
||||
*
|
||||
* @param searchDirectory the base directory to search
|
||||
* @param filter a filename filter
|
||||
* @return file directories
|
||||
*/
|
||||
public static List<Path> findFiles(Path searchDirectory,
|
||||
FilenameFilter filter) {
|
||||
return Arrays.stream(searchDirectory.toFile().listFiles(filter))
|
||||
.map(f -> f.toPath())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy files to the target path.
|
||||
*
|
||||
* @param source the paths to the files to copy
|
||||
* @param target the path to the target files
|
||||
* @param filenameMapper mapper function applied to filenames
|
||||
* @param options options specifying how the copy should be done
|
||||
* @return the paths to the target files
|
||||
* @throws IOException if error occurs
|
||||
*/
|
||||
public static List<Path> copyFiles(List<Path> source, Path target,
|
||||
Function<String, String> filenameMapper,
|
||||
CopyOption... options) throws IOException {
|
||||
List<Path> result = new ArrayList<>();
|
||||
|
||||
if (!target.toFile().exists()) {
|
||||
Files.createDirectory(target);
|
||||
}
|
||||
|
||||
for (Path file : source) {
|
||||
if (!file.toFile().exists()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String baseName = file.getFileName().toString();
|
||||
|
||||
Path targetFile = target.resolve(filenameMapper.apply(baseName));
|
||||
Files.copy(file, targetFile, options);
|
||||
result.add(targetFile);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy files to the target path.
|
||||
*
|
||||
* @param source the paths to the files to copy
|
||||
* @param target the path to the target files
|
||||
* @param options options specifying how the copy should be done
|
||||
* @return the paths to the target files
|
||||
* @throws IOException if error occurs
|
||||
*/
|
||||
public static List<Path> copyFiles(List<Path> source, Path target,
|
||||
CopyOption... options) throws IOException {
|
||||
return copyFiles(source, target, (s) -> s, options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an ACL entry that revokes owner access.
|
||||
*
|
||||
* @param acl original ACL entry to build from
|
||||
* @return an ACL entry that revokes all access
|
||||
*/
|
||||
public static AclEntry revokeAccess(AclEntry acl) {
|
||||
return buildAclEntry(acl, AclEntryType.DENY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an ACL entry that allow owner access.
|
||||
* @param acl original ACL entry to build from
|
||||
* @return an ACL entry that allows all access
|
||||
*/
|
||||
public static AclEntry allowAccess(AclEntry acl) {
|
||||
return buildAclEntry(acl, AclEntryType.ALLOW);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build an ACL entry with a given ACL entry type.
|
||||
*
|
||||
* @param acl original ACL entry to build from
|
||||
* @return an ACL entry with a given ACL entry type
|
||||
*/
|
||||
public static AclEntry buildAclEntry(AclEntry acl, AclEntryType type) {
|
||||
return AclEntry.newBuilder()
|
||||
.setType(type)
|
||||
.setPrincipal(acl.principal())
|
||||
.setPermissions(acl.permissions())
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace file string by applying the given mapper function.
|
||||
*
|
||||
* @param source the file to read
|
||||
* @param contentMapper the mapper function applied to file's content
|
||||
* @throws IOException if an I/O error occurs
|
||||
*/
|
||||
public static void replaceFileString(Path source,
|
||||
Function<String, String> contentMapper) throws IOException {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String lineSep = System.getProperty("line.separator");
|
||||
|
||||
try (BufferedReader reader =
|
||||
new BufferedReader(new FileReader(source.toFile()))) {
|
||||
|
||||
String line;
|
||||
|
||||
// read all and replace all at once??
|
||||
while ((line = reader.readLine()) != null) {
|
||||
sb.append(contentMapper.apply(line))
|
||||
.append(lineSep);
|
||||
}
|
||||
}
|
||||
|
||||
try (FileWriter writer = new FileWriter(source.toFile())) {
|
||||
writer.write(sb.toString());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace files' string by applying the given mapper function.
|
||||
*
|
||||
* @param source the file to read
|
||||
* @param contentMapper the mapper function applied to files' content
|
||||
* @throws IOException if an I/O error occurs
|
||||
*/
|
||||
public static void replaceFilesString(List<Path> source,
|
||||
Function<String, String> contentMapper) throws IOException {
|
||||
for (Path file : source) {
|
||||
replaceFileString(file, contentMapper);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user