Blame SOURCES/TestSecurityProperties.java

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