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