/** * @param file * @throws IOException * @deprecated Use {@link #dumpMasterPassword(Resource)} */ public boolean dumpMasterPassword(File file) throws IOException { return dumpMasterPassword(Files.asResource(file)); }
boolean dumpMasterPassword() throws IOException { return getSecurityManager().dumpMasterPassword(new File(fileName)); } }
boolean dumpMasterPassword() throws IOException { return getSecurityManager().dumpMasterPassword(new File(fileName)); } }
@Test public void testMasterPasswordDumpNotAuthorized() throws Exception { GeoServerSecurityManager secMgr = getSecurityManager(); File f = File.createTempFile("masterpw", "info"); try { assertFalse(secMgr.dumpMasterPassword(Files.asResource(f))); TestingAuthenticationToken auth = new TestingAuthenticationToken( "admin", "geoserver", (List) Arrays.asList(GeoServerRole.ADMIN_ROLE)); auth.setAuthenticated(true); SecurityContextHolder.getContext().setAuthentication(auth); assertFalse(secMgr.dumpMasterPassword(Files.asResource(f))); } finally { f.delete(); } }
@Test public void testMasterPasswordDump() throws Exception { GeoServerSecurityManager secMgr = getSecurityManager(); File f = File.createTempFile("masterpw", "info"); f.delete(); try { assertFalse(secMgr.dumpMasterPassword(Files.asResource(f))); TestingAuthenticationToken auth = new TestingAuthenticationToken( "admin", "geoserver", (List) Arrays.asList(GeoServerRole.ADMIN_ROLE)); auth.setAuthenticated(true); SecurityContextHolder.getContext().setAuthentication(auth); assertTrue(secMgr.dumpMasterPassword(Files.asResource(f))); dumpPWInfoFile(f); assertTrue(masterPWInfoFileContains(f, new String(secMgr.getMasterPassword()))); } finally { f.delete(); } }
@Test public void testMasterPasswordDumpNotOverwrite() throws Exception { GeoServerSecurityManager secMgr = getSecurityManager(); File f = File.createTempFile("masterpw", "info"); try (FileOutputStream os = new FileOutputStream(f)) { os.write("This should not be overwritten!".getBytes(StandardCharsets.UTF_8)); } try { assertFalse(secMgr.dumpMasterPassword(Files.asResource(f))); TestingAuthenticationToken auth = new TestingAuthenticationToken( "admin", "geoserver", (List) Arrays.asList(GeoServerRole.ADMIN_ROLE)); auth.setAuthenticated(true); SecurityContextHolder.getContext().setAuthentication(auth); assertFalse(secMgr.dumpMasterPassword(Files.asResource(f))); dumpPWInfoFile(f); assertTrue(masterPWInfoFileContains(f, "This should not be overwritten!")); assertFalse(masterPWInfoFileContains(f, new String(secMgr.getMasterPassword()))); } finally { f.delete(); } }