@Test public void testWriteFile_failure() throws Exception { File passwordFile = new File(applicationDirectories.getWorkDirectory(), "admin.password"); Files.write(passwordFile.toPath(), "testpass".getBytes("UTF-8")); passwordFile.setWritable(false); assertThat(underTest.writeFile("testpass2"), is(false)); String storedPassword = new String( Files.readAllBytes(new File(applicationDirectories.getWorkDirectory(), "admin.password").toPath())); assertThat(storedPassword, is("testpass")); }
@Override public boolean writeFile(String password) throws IOException { File workdir = applicationDirectories.getWorkDirectory(); if (!workdir.isDirectory() && !workdir.mkdirs()) { log.error("Failed to create work directory {}", workdir); return false; } if (adminPasswordFile.createNewFile()) { adminPasswordFile.setReadable(true, true); } try { log.info("Writing admin user temporary password to {}", adminPasswordFile.toString()); Files.write(adminPasswordFile.toPath(), password.getBytes(StandardCharsets.UTF_8)); } catch (Exception e) { log.error("Failed to write temporary password to disk", e); return false; } return true; }
AdminPasswordFileManagerImpl extends ComponentSupport implements AdminPasswordFileManager { @Override public boolean writeFile(String password) throws IOException { File workdir = applicationDirectories.getWorkDirectory(); if (!workdir.isDirectory() && !workdir.mkdirs()) { log.error("Failed to create work directory {}", workdir); return false; } if (adminPasswordFile.createNewFile()) { adminPasswordFile.setReadable(true, true); } try { log.info("Writing admin user temporary password to {}", adminPasswordFile.toString()); Files.write(adminPasswordFile.toPath(), password.getBytes(StandardCharsets.UTF_8)); } catch (Exception e) { log.error("Failed to write temporary password to disk", e); return false; } return true; } }
AdminPasswordFileManagerImpl extends ComponentSupport implements AdminPasswordFileManager { @Override public boolean writeFile(String password) throws IOException { File workdir = applicationDirectories.getWorkDirectory(); if (!workdir.isDirectory() && !workdir.mkdirs()) { log.error("Failed to create work directory {}", workdir); return false; } if (adminPasswordFile.createNewFile()) { adminPasswordFile.setReadable(true, true); } try { log.info("Writing admin user temporary password to {}", adminPasswordFile.toString()); Files.write(adminPasswordFile.toPath(), password.getBytes(StandardCharsets.UTF_8)); } catch (Exception e) { log.error("Failed to write temporary password to disk", e); return false; } return true; } @Inject  AdminPasswordFileManagerImpl(final ApplicationDirectories applicationDirectories); }
AdminPasswordFileManagerImpl extends ComponentSupport implements AdminPasswordFileManager { @Override public boolean writeFile(String password) throws IOException { File workdir = applicationDirectories.getWorkDirectory(); if (!workdir.isDirectory() && !workdir.mkdirs()) { log.error("Failed to create work directory {}", workdir); return false; } if (adminPasswordFile.createNewFile()) { adminPasswordFile.setReadable(true, true); } try { log.info("Writing admin user temporary password to {}", adminPasswordFile.toString()); Files.write(adminPasswordFile.toPath(), password.getBytes(StandardCharsets.UTF_8)); } catch (Exception e) { log.error("Failed to write temporary password to disk", e); return false; } return true; } @Inject  AdminPasswordFileManagerImpl(final ApplicationDirectories applicationDirectories); @Override boolean writeFile(String password); @Override boolean exists(); @Override String getPath(); @Override String readFile(); @Override void removeFile(); }
AdminPasswordFileManagerImpl extends ComponentSupport implements AdminPasswordFileManager { @Override public boolean writeFile(String password) throws IOException { File workdir = applicationDirectories.getWorkDirectory(); if (!workdir.isDirectory() && !workdir.mkdirs()) { log.error("Failed to create work directory {}", workdir); return false; } if (adminPasswordFile.createNewFile()) { adminPasswordFile.setReadable(true, true); } try { log.info("Writing admin user temporary password to {}", adminPasswordFile.toString()); Files.write(adminPasswordFile.toPath(), password.getBytes(StandardCharsets.UTF_8)); } catch (Exception e) { log.error("Failed to write temporary password to disk", e); return false; } return true; } @Inject  AdminPasswordFileManagerImpl(final ApplicationDirectories applicationDirectories); @Override boolean writeFile(String password); @Override boolean exists(); @Override String getPath(); @Override String readFile(); @Override void removeFile(); final ApplicationDirectories applicationDirectories; }