Blame SOURCES/TestSecurityProperties.java

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