BrooklynPropertiesFactoryHelper { public BrooklynProperties.Factory.Builder createPropertiesBuilder() { if (brooklynProperties == null) { BrooklynProperties.Factory.Builder builder = BrooklynProperties.Factory.builderDefault(); if (Strings.isNonEmpty(globalBrooklynPropertiesFile)) { File globalProperties = new File(Os.tidyPath(globalBrooklynPropertiesFile)); if (globalProperties.exists()) { globalProperties = resolveSymbolicLink(globalProperties); checkFileReadable(globalProperties); checkFilePermissionsX00(globalProperties); LOG.debug("Using global properties file " + globalProperties); } else { LOG.debug("Global properties file " + globalProperties + " does not exist, will ignore"); } builder.globalPropertiesFile(globalProperties.getAbsolutePath()); } else { LOG.debug("Global properties file disabled"); builder.globalPropertiesFile(null); } if (Strings.isNonEmpty(localBrooklynPropertiesFile)) { File localProperties = new File(Os.tidyPath(localBrooklynPropertiesFile)); localProperties = resolveSymbolicLink(localProperties); checkFileReadable(localProperties); checkFilePermissionsX00(localProperties); builder.localPropertiesFile(localProperties.getAbsolutePath()); } if (propertiesSupplier != null) { builder.propertiesSupplier(propertiesSupplier); } return builder; } else { if (globalBrooklynPropertiesFile != null) LOG.warn("Ignoring globalBrooklynPropertiesFile "+globalBrooklynPropertiesFile+" because explicit brooklynProperties supplied"); if (localBrooklynPropertiesFile != null) LOG.warn("Ignoring localBrooklynPropertiesFile "+localBrooklynPropertiesFile+" because explicit brooklynProperties supplied"); return Builder.fromProperties(brooklynProperties); } } BrooklynPropertiesFactoryHelper(String globalBrooklynPropertiesFile, String localBrooklynPropertiesFile);  BrooklynPropertiesFactoryHelper(BrooklynProperties brooklynProperties);  BrooklynPropertiesFactoryHelper(String globalBrooklynPropertiesFile,
            String localBrooklynPropertiesFile,
            BrooklynProperties brooklynProperties);  BrooklynPropertiesFactoryHelper(
            String globalBrooklynPropertiesFile,
            String localBrooklynPropertiesFile,
            Supplier<Map<?, ?>> propertiesSupplier);  BrooklynPropertiesFactoryHelper(String globalBrooklynPropertiesFile,
            String localBrooklynPropertiesFile,
            BrooklynProperties brooklynProperties,
            Supplier<Map<?, ?>> propertiesSupplier); BrooklynProperties.Factory.Builder createPropertiesBuilder();  }
@Test(groups="UNIX") public void testChecksGlobalBrooklynPropertiesPermissionsX00() throws Exception { File propsFile = File.createTempFile("testChecksGlobalBrooklynPropertiesPermissionsX00", ".properties"); propsFile.setReadable(true, false); try { new BrooklynPropertiesFactoryHelper(propsFile.getAbsolutePath(), null) .createPropertiesBuilder(); Assert.fail("Should have thrown"); } catch (FatalRuntimeException e) { if (!e.toString().contains("Invalid permissions for file")) throw e; } finally { propsFile.delete(); } }
@Test(groups="UNIX") public void testChecksLocalBrooklynPropertiesPermissionsX00() throws Exception { File propsFile = File.createTempFile("testChecksLocalBrooklynPropertiesPermissionsX00", ".properties"); propsFile.setReadable(true, false); try { new BrooklynPropertiesFactoryHelper(propsFile.getAbsolutePath(), null) .createPropertiesBuilder(); Assert.fail("Should have thrown"); } catch (FatalRuntimeException e) { if (!e.toString().contains("Invalid permissions for file")) throw e; } finally { propsFile.delete(); } }
@Test(groups="UNIX") public void testStartsWithSymlinkedBrooklynPropertiesPermissionsX00() throws Exception { File dir = Files.createTempDir(); Path globalPropsFile = java.nio.file.Files.createFile(Paths.get(dir.toString(), "globalProps.properties")); Path globalSymlink = java.nio.file.Files.createSymbolicLink(Paths.get(dir.toString(), "globalLink"), globalPropsFile); Path localPropsFile = java.nio.file.Files.createFile(Paths.get(dir.toString(), "localPropsFile.properties")); Path localSymlink = java.nio.file.Files.createSymbolicLink(Paths.get(dir.toString(), "localLink"), localPropsFile); Files.write(getMinimalLauncherPropertiesString() + "key_in_global=1", globalPropsFile.toFile(), Charset.defaultCharset()); Files.write("key_in_local=2", localPropsFile.toFile(), Charset.defaultCharset()); FileUtil.setFilePermissionsTo600(globalPropsFile.toFile()); FileUtil.setFilePermissionsTo600(localPropsFile.toFile()); try { BrooklynProperties props = new BrooklynPropertiesFactoryHelper( globalSymlink.toAbsolutePath().toString(), localSymlink.toAbsolutePath().toString()) .createPropertiesBuilder() .build(); assertEquals(props.getFirst("key_in_global"), "1"); assertEquals(props.getFirst("key_in_local"), "2"); } finally { Os.deleteRecursively(dir); } }
@Test public void testStartsWithBrooklynPropertiesPermissionsX00() throws Exception { File globalPropsFile = File.createTempFile("testChecksLocalBrooklynPropertiesPermissionsX00_global", ".properties"); Files.write(getMinimalLauncherPropertiesString()+"key_in_global=1", globalPropsFile, Charset.defaultCharset()); File localPropsFile = File.createTempFile("testChecksLocalBrooklynPropertiesPermissionsX00_local", ".properties"); Files.write("key_in_local=2", localPropsFile, Charset.defaultCharset()); FileUtil.setFilePermissionsTo600(globalPropsFile); FileUtil.setFilePermissionsTo600(localPropsFile); try { BrooklynProperties props = new BrooklynPropertiesFactoryHelper( globalPropsFile.getAbsolutePath(), localPropsFile.getAbsolutePath()) .createPropertiesBuilder() .build(); assertEquals(props.getFirst("key_in_global"), "1"); assertEquals(props.getFirst("key_in_local"), "2"); } finally { globalPropsFile.delete(); localPropsFile.delete(); } }