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