Blame SOURCES/TestSecurityProperties.java

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