@Test public void testEncryption() throws Exception { File tmp = File.createTempFile("passwd", "tmp", new File("target")); tmp = tmp.getCanonicalFile(); URLMasterPasswordProviderConfig config = new URLMasterPasswordProviderConfig(); config.setName("test"); config.setReadOnly(false); config.setLoginEnabled(true); config.setClassName(URLMasterPasswordProvider.class.getCanonicalName()); config.setURL(URLs.fileToUrl(tmp)); config.setEncrypting(true); URLMasterPasswordProvider mpp = new URLMasterPasswordProvider(); mpp.setSecurityManager(getSecurityManager()); mpp.initializeFromConfig(config); mpp.setName(config.getName()); mpp.doSetMasterPassword("geoserver".toCharArray()); String encoded = IOUtils.toString(new FileInputStream(tmp)); assertFalse("geoserver".equals(encoded)); char[] passwd = mpp.doGetMasterPassword(); assertTrue(Arrays.equals("geoserver".toCharArray(), passwd)); } }
@Test public void testUrlConfig() throws Exception { URLMasterPasswordProviderValidator validator = new URLMasterPasswordProviderValidator(getSecurityManager()); URLMasterPasswordProviderConfig config = new URLMasterPasswordProviderConfig(); config.setName("foo"); config.setClassName(URLMasterPasswordProvider.class.getCanonicalName()); try { validator.validateAddMasterPasswordProvider(config); // getSecurityManager().saveMasterPasswordProviderConfig(config); fail(); } catch (URLMasterPasswordProviderException e) { assertSecurityException(e, URLMasterPasswordProviderException.URL_REQUIRED); } config.setURL(new URL("file:ABC")); config.setReadOnly(true); try { validator.validateAddMasterPasswordProvider(config); // getSecurityManager().saveMasterPasswordProviderConfig(config); fail(); } catch (URLMasterPasswordProviderException e) { assertSecurityException( e, URLMasterPasswordProviderException.URL_LOCATION_NOT_READABLE, new URL("file:ABC")); } }