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