openfireProperties = new XMLProperties(home + File.separator + getConfigName()); openfireProperties = new XMLProperties(); } catch (IOException e) { Log.error("Failed to setup default openfire properties", e);
/** * Creates a new empty XMLPropertiesTest object. * * @throws IOException if an error occurs loading the properties. */ public XMLProperties() throws IOException { buildDoc(new StringReader("<root />")); }
String encryptedKey = securityProperties.getProperty(ENCRYPTION_KEY_CURRENT); if (encryptedKey == null || encryptedKey.isEmpty()) { currentKey = null; String newKey = securityProperties.getProperty(ENCRYPTION_KEY_NEW, false); if (newKey != null) { String oldKey = securityProperties.getProperty(ENCRYPTION_KEY_OLD); if (oldKey == null) { if (currentKey != null) { for (String xmlProp : openfireProperties.getAllPropertyNames()) { if (isPropertyEncrypted(xmlProp)) { openfireProps.put(xmlProp, openfireProperties.getProperty(xmlProp)); for (String propertyName : securityProperties.getProperties(ENCRYPTED_PROPERTY_NAMES, true)) { Log.info("Updating encrypted value for " + propertyName); if (openfireProps.containsKey(propertyName)) { openfireProperties.setProperty(propertyName, openfireProps.get(propertyName)); } else if (!resetProperty(propertyName)) { Log.warn("Failed to reset encrypted property value for " + propertyName); securityProperties.deleteProperty(ENCRYPTION_KEY_NEW); securityProperties.deleteProperty(ENCRYPTION_KEY_OLD); securityProperties.setProperty(ENCRYPTION_KEY_CURRENT, keyEncryptor.encrypt(currentKey));
/** * Returns a list of names for all properties found in the XML file. * * @return Names for all properties in the file */ public List<String> getAllPropertyNames() { List<String> result = new ArrayList<>(); for (String propertyName : getChildPropertyNamesFor(document.getRootElement(), "")) { if (getProperty(propertyName) != null) { result.add(propertyName); } } return result; }
@Override public void run() { // Migrate all secure XML properties into the database automatically for (String propertyName : securityProperties.getAllPropertyNames()) { if (!propertyName.startsWith(ENCRYPTED_PROPERTY_NAME_PREFIX)) { setPropertyEncrypted(propertyName, true); securityProperties.migrateProperty(propertyName); } } } }, 1000);
/** * This method is called early during the setup process to * set the algorithm for encrypting property values */ public static void setupPropertyEncryptionAlgorithm(String alg) { // Get the old secret key and encryption type String oldAlg = securityProperties.getProperty(ENCRYPTION_ALGORITHM); String oldKey = securityProperties.getProperty(ENCRYPTION_KEY_CURRENT); if(StringUtils.isNotEmpty(oldAlg) && !oldAlg.equals(alg) && StringUtils.isNotEmpty(oldKey)){ // update encrypted properties updateEncryptionProperties(oldAlg, oldKey, alg, oldAlg); } if (ENCRYPTION_ALGORITHM_AES.equalsIgnoreCase(alg)) { securityProperties.setProperty(ENCRYPTION_ALGORITHM, ENCRYPTION_ALGORITHM_AES); } else { securityProperties.setProperty(ENCRYPTION_ALGORITHM, ENCRYPTION_ALGORITHM_BLOWFISH); } }
/** * Deletes the specified property. * * @param name the property to delete. */ public synchronized void deleteProperty(String name) { // Remove property from cache. propertyCache.remove(name); String[] propName = parsePropertyName(name); // Search for this property by traversing down the XML hierarchy. Element element = document.getRootElement(); for (int i = 0; i < propName.length - 1; i++) { element = element.element(propName[i]); // Can't find the property so return. if (element == null) { return; } } // Found the correct element to remove, so remove it... element.remove(element.element(propName[propName.length - 1])); if (element.elements().size() == 0) { element.getParent().remove(element); } // .. then write to disk. saveProperties(); JiveGlobals.setPropertyEncrypted(name, false); // Generate event. Map<String, Object> params = Collections.emptyMap(); PropertyEventDispatcher.dispatchEvent(name, PropertyEventDispatcher.EventType.xml_property_deleted, params); }
/** * Returns the value of the attribute of the given property name or <tt>null</tt> * if it doesn't exist. * * @param name the property name to lookup - ie, "foo.bar" * @param attribute the name of the attribute, ie "id" * @return the value of the attribute of the given property or <tt>null</tt> if * it doesn't exist. */ public String getAttribute(String name, String attribute) { if (name == null || attribute == null) { return null; } String[] propName = parsePropertyName(name); // Search for this property by traversing down the XML hierarchy. Element element = document.getRootElement(); for (String child : propName) { element = element.element(child); if (element == null) { // This node doesn't match this part of the property name which // indicates this property doesn't exist so return empty array. break; } } if (element != null) { // Get its attribute values return element.attributeValue(attribute); } return null; }
/** * Returns the value of the specified property. * * @param name the name of the property to get. * @return the value of the specified property. */ public synchronized String getProperty(String name) { return getProperty(name, true); }
String[] propName = parsePropertyName(name); setProperty(name, value);
public void setProperties(Map<String, String> propertyMap) { for (String propertyName : propertyMap.keySet()) { String propertyValue = propertyMap.get(propertyName); setProperty(propertyName, propertyValue); } } }
static void clearXMLPropertyEncryptionEntry(String name) { if (isSetupMode()) { return; } if (securityProperties == null) { loadSecurityProperties(); } if (openfireProperties == null) { loadOpenfireProperties(); } // Note; only remove the encryption indicator from XML file if the (encrypted) property is not also defined in the XML file if (JiveGlobals.isXMLPropertyEncrypted(name) && openfireProperties.getProperty(name) == null) { securityProperties.removeFromList(ENCRYPTED_PROPERTY_NAMES, name); } }
/** * Convenience routine to migrate an XML property into the database * storage method. Will check for the XML property being null before * migrating. * * @param name the name of the property to migrate. */ public void migrateProperty(String name) { final String xmlPropertyValue = getProperty(name); if (xmlPropertyValue != null) { final String databasePropertyValue = JiveGlobals.getProperty(name); if (databasePropertyValue == null) { Log.debug("JiveGlobals: Migrating XML property '" + name + "' into database."); JiveGlobals.setProperty(name, xmlPropertyValue); if (JiveGlobals.isXMLPropertyEncrypted(name)) { JiveGlobals.setPropertyEncrypted(name, true); } deleteProperty(name); } else if (databasePropertyValue.equals(xmlPropertyValue)) { Log.debug("JiveGlobals: Deleting duplicate XML property '" + name + "' that is already in database."); if (JiveGlobals.isXMLPropertyEncrypted(name)) { JiveGlobals.setPropertyEncrypted(name, true); } deleteProperty(name); } else if (!databasePropertyValue.equals(xmlPropertyValue)) { Log.warn("XML Property '" + name + "' differs from what is stored in the database. Please make property changes in the database instead of the configuration file."); } } }
/** * Return all property names as a list of strings, or an empty list if jiveHome has not been loaded. * * @return all child property for the given parent. */ public static List<String> getXMLPropertyNames() { if (openfireProperties == null) { loadOpenfireProperties(); } return openfireProperties.getAllPropertyNames(); }
/** * Deletes a locale property. If the property doesn't exist, the method * does nothing. * * @param name the name of the property to delete. */ public static void deleteXMLProperty(String name) { if (openfireProperties == null) { loadOpenfireProperties(); } openfireProperties.deleteProperty(name); }
private List<String> getChildPropertyNamesFor(Element parent, String parentName) { List<String> result = new ArrayList<>(); for (Element child : parent.elements()) { String childName = parentName + (parentName.isEmpty() ? "" : ".") + child.getName(); if (!result.contains(childName)) { result.add(childName); result.addAll(getChildPropertyNamesFor(child, childName)); } } return result; }
/** * Copies the inFile to the outFile. * * @param inFile The file to copy from * @param outFile The file to copy to * @throws IOException If there was a problem making the copy */ private static void copy(File inFile, File outFile) throws IOException { FileInputStream fin = null; FileOutputStream fout = null; try { fin = new FileInputStream(inFile); fout = new FileOutputStream(outFile); copy(fin, fout); } finally { try { if (fin != null) fin.close(); } catch (IOException e) { // do nothing } try { if (fout != null) fout.close(); } catch (IOException e) { // do nothing } } }
String[] propName = parsePropertyName(name); saveProperties();
/** * This method is called early during the setup process to * set a custom key for encrypting property values */ public static void setupPropertyEncryptionKey(String key) { // Get the old secret key and encryption type String oldAlg = securityProperties.getProperty(ENCRYPTION_ALGORITHM); String oldKey = securityProperties.getProperty(ENCRYPTION_KEY_CURRENT); if(StringUtils.isNotEmpty(oldKey) && !oldKey.equals(key) && StringUtils.isNotEmpty(oldAlg)) { // update encrypted properties updateEncryptionProperties(oldAlg, oldKey, oldAlg, key); } securityProperties.setProperty(ENCRYPTION_KEY_CURRENT, new AesEncryptor().encrypt(currentKey)); }
String[] propName = parsePropertyName(parent);