/** * Delete a User. * * @param username */ public void deleteUser(String username) { users.remove(username); try { users.save(); } catch (Exception ex) { LOGGER.error("Cannot remove users file,", ex); } }
@Override public void writeSystemProperties(Map<String, String> updatedSystemProperties) { if (updatedSystemProperties == null) { return; } // Get system.properties file // save off the current/old hostname before we make any changes oldHostName = SystemBaseUrl.getHost(); String etcDir = System.getProperty(KARAF_ETC); String systemPropertyFilename = etcDir + File.separator + SYSTEM_PROPERTIES_FILE; String userPropertiesFilename = etcDir + File.separator + USERS_PROPERTIES_FILE; String userAttributesFilename = etcDir + File.separator + USERS_ATTRIBUTES_FILE; File systemPropertiesFile = new File(systemPropertyFilename); File userPropertiesFile = new File(userPropertiesFilename); File userAttributesFile = new File(userAttributesFilename); try { Properties systemDotProperties = new Properties(systemPropertiesFile); updateProperty(SystemBaseUrl.PORT, updatedSystemProperties, systemDotProperties); updateProperty(SystemBaseUrl.HOST, updatedSystemProperties, systemDotProperties); updateProperty(SystemBaseUrl.PROTOCOL, updatedSystemProperties, systemDotProperties); updateProperty(SystemBaseUrl.HTTP_PORT, updatedSystemProperties, systemDotProperties); updateProperty(SystemBaseUrl.HTTPS_PORT, updatedSystemProperties, systemDotProperties); updateProperty(SystemInfo.ORGANIZATION, updatedSystemProperties, systemDotProperties); updateProperty(SystemInfo.SITE_CONTACT, updatedSystemProperties, systemDotProperties); updateProperty(SystemInfo.SITE_NAME, updatedSystemProperties, systemDotProperties); updateProperty(SystemInfo.VERSION, updatedSystemProperties, systemDotProperties); systemDotProperties.save(); } catch (IOException e) { LOGGER.warn("Exception while writing to system.properties file.", e); } try { Properties userDotProperties = new Properties(userPropertiesFile); if (!userDotProperties.isEmpty()) { String oldHostValue = userDotProperties.getProperty(oldHostName); if (oldHostValue != null) { userDotProperties.remove(oldHostName); userDotProperties.setProperty(System.getProperty(SystemBaseUrl.HOST), oldHostValue); userDotProperties.save(); } } } catch (IOException e) { LOGGER.warn("Exception while writing to users.properties file.", e); } Map<String, Object> json = null; try (InputStream stream = Files.newInputStream(Paths.get(userAttributesFile.toURI()))) { json = MAPPER.parser().parseMap(stream); if (json.containsKey(oldHostName)) { json.put(System.getProperty(SystemBaseUrl.HOST), json.remove(oldHostName)); } } catch (IOException e) { LOGGER.error("Unable to read system user attribute file for hostname update.", e); } if (json != null) { try (OutputStream stream = Files.newOutputStream(Paths.get(userAttributesFile.toURI()))) { MAPPER.writeValue(stream, json); } catch (IOException e) { LOGGER.error("Unable to write system user attribute file for hostname update.", e); } } }