|
|
c0ba06 |
import java.io.File;
|
|
|
c0ba06 |
import java.io.FileInputStream;
|
|
|
c0ba06 |
import java.security.Security;
|
|
|
c0ba06 |
import java.util.Properties;
|
|
|
c0ba06 |
|
|
|
c0ba06 |
public class TestSecurityProperties {
|
|
|
c0ba06 |
// JDK 11
|
|
|
c0ba06 |
private static final String JDK_PROPS_FILE_JDK_11 = System.getProperty("java.home") + "/conf/security/java.security";
|
|
|
c0ba06 |
// JDK 8
|
|
|
c0ba06 |
private static final String JDK_PROPS_FILE_JDK_8 = System.getProperty("java.home") + "/lib/security/java.security";
|
|
|
c0ba06 |
|
|
|
c0ba06 |
public static void main(String[] args) {
|
|
|
c0ba06 |
Properties jdkProps = new Properties();
|
|
|
c0ba06 |
loadProperties(jdkProps);
|
|
|
c0ba06 |
for (Object key: jdkProps.keySet()) {
|
|
|
c0ba06 |
String sKey = (String)key;
|
|
|
c0ba06 |
String securityVal = Security.getProperty(sKey);
|
|
|
c0ba06 |
String jdkSecVal = jdkProps.getProperty(sKey);
|
|
|
c0ba06 |
if (!securityVal.equals(jdkSecVal)) {
|
|
|
c0ba06 |
String msg = "Expected value '" + jdkSecVal + "' for key '" +
|
|
|
c0ba06 |
sKey + "'" + " but got value '" + securityVal + "'";
|
|
|
c0ba06 |
throw new RuntimeException("Test failed! " + msg);
|
|
|
c0ba06 |
} else {
|
|
|
c0ba06 |
System.out.println("DEBUG: " + sKey + " = " + jdkSecVal + " as expected.");
|
|
|
c0ba06 |
}
|
|
|
c0ba06 |
}
|
|
|
c0ba06 |
System.out.println("TestSecurityProperties PASSED!");
|
|
|
c0ba06 |
}
|
|
|
c0ba06 |
|
|
|
c0ba06 |
private static void loadProperties(Properties props) {
|
|
|
c0ba06 |
String javaVersion = System.getProperty("java.version");
|
|
|
c0ba06 |
System.out.println("Debug: Java version is " + javaVersion);
|
|
|
c0ba06 |
String propsFile = JDK_PROPS_FILE_JDK_11;
|
|
|
c0ba06 |
if (javaVersion.startsWith("1.8.0")) {
|
|
|
c0ba06 |
propsFile = JDK_PROPS_FILE_JDK_8;
|
|
|
c0ba06 |
}
|
|
|
c0ba06 |
try (FileInputStream fin = new FileInputStream(new File(propsFile))) {
|
|
|
c0ba06 |
props.load(fin);
|
|
|
c0ba06 |
} catch (Exception e) {
|
|
|
c0ba06 |
throw new RuntimeException("Test failed!", e);
|
|
|
c0ba06 |
}
|
|
|
c0ba06 |
}
|
|
|
c0ba06 |
}
|