Blame SOURCES/TestSecurityProperties.java

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