Class JiveGlobals
When starting up the application this class needs to be configured so that the initial
configuration of the application may be loaded from the configuration file. The configuration
file holds properties stored in XML format, database configuration and user authentication
configuration. Use setHomePath(Path) and setConfigName(String) for
setting the home directory and path to the configuration file.
XML property names must be in the form prop.name - parts of the name must
be separated by ".". The value can be any valid String, including strings with line breaks.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voiddeleteProperty(String name) Deletes a Jive property.static voiddeleteXMLProperty(String name) Deletes a locale property.static StringformatDate(Date date) Formats a Date object to return a date using the global locale.static StringformatDateTime(Date date) Formats a Date object to return a date and time using the global locale.static StringformatTime(Date date) Formats a Date object to return a time using the global locale.static StringGets the Blowfish key derivation function (KDF) type.static StringGets the Blowfish encryption salt.static booleangetBooleanProperty(String name) Returns a boolean value Jive property.static booleangetBooleanProperty(String name, boolean defaultValue) Returns a boolean value Jive property.static Pathstatic StringReturns the name of the local config file.static doublegetDoubleProperty(String name, double defaultValue) Returns a double value Jive property.static intReturns the count of encrypted properties in openfire.xml that have values.static StringReturns the encryption algorithm configured in security.xml.static <E extends Enum<E>>
EgetEnumProperty(String name, Class<E> enumType, E defaultValue) Returns an enum constant Jive property.static PathReturns the location of thehomedirectory.static intgetIntProperty(String name, int defaultValue) Returns an integer value Jive property.getListProperty(String parent, List<String> defaultValues) Return all immediate children property values of a parent Jive property as a list of strings, or an default list if the property does not exist.static LocaleReturns the global Locale used by Jive.static longgetLongProperty(String name, long defaultValue) Returns a long value Jive property.static StringGets the current master encryption key used for property encryption.getProperties(String parent) Return all immediate children property values of a parent Jive property as a list of strings, or an empty list if there are no children.static StringgetProperty(String name) Returns a Jive property.static StringgetProperty(String name, String defaultValue) Returns a Jive property.static EncryptorFetches the current property encryptor.static EncryptorgetPropertyEncryptor(boolean useNewEncryptor) Fetches the property encryptor.Returns all Jive property names.getPropertyNames(String parent) Return all immediate children property names of a parent Jive property as a list of strings, or an empty list if there are no children.static Pathstatic StringReturns the name of the local security config file.static TimeZoneReturns the global TimeZone used by Jive.getXMLProperties(String parent) Return all immediate children property values of a parent local property as a list of strings, or an empty list if there are no children.static StringgetXMLProperty(String name) Returns a local property.static booleangetXMLProperty(String name, boolean defaultValue) Returns a boolean value local property.static intgetXMLProperty(String name, int defaultValue) Returns an integer value local property.static StringgetXMLProperty(String name, String defaultValue) Returns a local property.Return all property names as a list of strings, or an empty list if jiveHome has not been loaded.static booleanChecks whether Blowfish encryption migration from SHA1 to PBKDF2 is needed.static booleanisPropertyEncrypted(String name) Determines whether a property is configured for encryption.static booleanisPropertySensitive(String name) Flags certain properties as being sensitive, based on property naming conventions.static booleanisXMLPropertyEncrypted(String name) Determines whether an XML property is configured for encryption.static voidmigrateProperty(String name) Convenience routine to migrate an XML property into the database storage method.static voidmigratePropertyTree(String name) Convenience routine to migrate a tree of XML propertis into the database storage method.static intMigrates encrypted XML properties (in openfire.xml) from SHA1 to PBKDF2 key derivation.static voidRe-initialises the property encryptor with the current encryption settings.static voidsetBlowfishKdf(String kdf) Sets the Blowfish key derivation function (KDF) type and re-initialises the property encryptor cache to use the new KDF immediately.static voidsetConfigName(String configName) Allows the name of the local config file name to be changed.static voidsetHomePath(Path homeDir) Sets the location of thehomedirectory.static voidSets the global locale used by Jive.static voidsetProperties(Map<String, String> propertyMap) Sets multiple Jive properties at once.static voidsetProperty(String name, String value) Sets a Jive property.static voidsetProperty(String name, String value, boolean encrypt) Sets a Jive property.static voidsetProperty(String name, List<String> values) Sets a Jive property with a list of values.static booleansetPropertyEncrypted(String name, boolean encrypt) Set the encryption status for the given property.static voidsetTimeZone(TimeZone newTimeZone) Sets the global time zone used by Jive.static voidThis method is called early during the setup process to set the algorithm for encrypting property valuesstatic voidThis method is called early during the setup process to set a custom key for encrypting property valuesstatic voidsetXMLProperties(Map<String, String> propertyMap) Sets multiple local properties at once.static booleansetXMLProperty(String name, String value) Sets a local property.
-
Field Details
-
BLOWFISH_KDF_PBKDF2
Blowfish key derivation function using PBKDF2-HMAC-SHA512- See Also:
-
BLOWFISH_KDF_SHA1
Blowfish key derivation function using legacy SHA1 (for backward compatibility)- See Also:
-
setupExcludePaths
-
-
Constructor Details
-
JiveGlobals
public JiveGlobals()
-
-
Method Details
-
getLocale
Returns the global Locale used by Jive. A locale specifies language and country codes, and is used for internationalization. The default locale is system dependent - Locale.getDefault().- Returns:
- the global locale used by Jive.
-
setLocale
Sets the global locale used by Jive. A locale specifies language and country codes, and is used for formatting dates and numbers. The default locale is Locale.US.- Parameters:
newLocale- the global Locale for Jive.
-
getTimeZone
Returns the global TimeZone used by Jive. The default is the VM's default time zone.- Returns:
- the global time zone used by Jive.
-
setTimeZone
Sets the global time zone used by Jive. The default time zone is the VM's time zone.- Parameters:
newTimeZone- Time zone to set.
-
formatTime
Formats a Date object to return a time using the global locale.- Parameters:
date- the Date to format.- Returns:
- a String representing the time.
-
formatDate
Formats a Date object to return a date using the global locale.- Parameters:
date- the Date to format.- Returns:
- a String representing the date.
-
formatDateTime
Formats a Date object to return a date and time using the global locale.- Parameters:
date- the Date to format.- Returns:
- a String representing the date and time.
-
getHomePath
Returns the location of thehomedirectory.- Returns:
- the location of the home dir.
-
setHomePath
Sets the location of thehomedirectory. The directory must exist and the user running the application must have read and write permissions over the specified directory.- Parameters:
homeDir- the location of the home dir.
-
getXMLProperty
Returns a local property. Local properties are stored in the file defined inJIVE_CONFIG_FILENAMEthat exists in thehomedirectory. Properties are always specified as "foo.bar.prop", which would map to the following entry in the XML file:<foo> <bar> <prop>some value</prop> </bar> </foo>- Parameters:
name- the name of the property to return.- Returns:
- the property value specified by name.
-
getXMLProperty
Returns a local property. Local properties are stored in the file defined inJIVE_CONFIG_FILENAMEthat exists in thehomedirectory. Properties are always specified as "foo.bar.prop", which would map to the following entry in the XML file:<foo> <bar> <prop>some value</prop> </bar> </foo>If the specified property can't be found, thedefaultValuewill be returned.- Parameters:
name- the name of the property to return.defaultValue- the default value for the property.- Returns:
- the property value specified by name.
-
getXMLProperty
Returns an integer value local property. Local properties are stored in the file defined inJIVE_CONFIG_FILENAMEthat exists in thehomedirectory. Properties are always specified as "foo.bar.prop", which would map to the following entry in the XML file:<foo> <bar> <prop>some value</prop> </bar> </foo>If the specified property can't be found, or if the value is not a number, thedefaultValuewill be returned.- Parameters:
name- the name of the property to return.defaultValue- value returned if the property could not be loaded or was not a number.- Returns:
- the property value specified by name or
defaultValue.
-
getXMLProperty
Returns a boolean value local property. Local properties are stored in the file defined inJIVE_CONFIG_FILENAMEthat exists in thehomedirectory. Properties are always specified as "foo.bar.prop", which would map to the following entry in the XML file:<foo> <bar> <prop>some value</prop> </bar> </foo>If the specified property can't be found, thedefaultValuewill be returned. If the property is found, it will be parsed usingBoolean.valueOf(String).- Parameters:
name- the name of the property to return.defaultValue- value returned if the property could not be loaded or was not a number.- Returns:
- the property value specified by name or
defaultValue.
-
setXMLProperty
Sets a local property. If the property doesn't already exists, a new one will be created. Local properties are stored in the file defined inJIVE_CONFIG_FILENAMEthat exists in thehomedirectory. Properties are always specified as "foo.bar.prop", which would map to the following entry in the XML file:<foo> <bar> <prop>some value</prop> </bar> </foo>- Parameters:
name- the name of the property being set.value- the value of the property being set.- Returns:
trueif the property was correctly saved to file, otherwisefalse
-
setXMLProperties
Sets multiple local properties at once. If a property doesn't already exists, a new one will be created. Local properties are stored in the file defined inJIVE_CONFIG_FILENAMEthat exists in thehomedirectory. Properties are always specified as "foo.bar.prop", which would map to the following entry in the XML file:<foo> <bar> <prop>some value</prop> </bar> </foo>- Parameters:
propertyMap- a map of properties, keyed on property name.
-
getXMLProperties
Return all immediate children property values of a parent local property as a list of strings, or an empty list if there are no children. For example, given the propertiesX.Y.A,X.Y.B,X.Y.CandX.Y.C.D, then the immediate child properties ofX.YareA,B, andC(the value ofC.Dwould not be returned using this method).Local properties are stored in the file defined in
JIVE_CONFIG_FILENAMEthat exists in thehomedirectory. Properties are always specified as "foo.bar.prop", which would map to the following entry in the XML file:<foo> <bar> <prop>some value</prop> </bar> </foo>- Parameters:
parent- the name of the parent property to return the children for.- Returns:
- all child property values for the given parent.
-
getXMLPropertyNames
Return all property names as a list of strings, or an empty list if jiveHome has not been loaded.- Returns:
- all child property for the given parent.
-
deleteXMLProperty
Deletes a locale property. If the property doesn't exist, the method does nothing.- Parameters:
name- the name of the property to delete.
-
getProperty
Returns a Jive property.- Parameters:
name- the name of the property to return.- Returns:
- the property value specified by name.
-
getProperty
Returns a Jive property. If the specified property doesn't exist, thedefaultValuewill be returned.- Parameters:
name- the name of the property to return.defaultValue- value returned if the property doesn't exist.- Returns:
- the property value specified by name.
-
getEnumProperty
Returns an enum constant Jive property. If the specified property doesn't exist, or if it's value cannot be parsed as an enum constant, thedefaultValuewill be returned.- Type Parameters:
E- The enum type whose constant is to be returned.- Parameters:
name- the name of the property to return.enumType- theClassobject of the enum type from which to return a constant.defaultValue- value returned if the property doesn't exist or it's value could not be parsed.- Returns:
- the property value (as an enum constant) or
defaultValue.
-
getIntProperty
Returns an integer value Jive property. If the specified property doesn't exist, thedefaultValuewill be returned.- Parameters:
name- the name of the property to return.defaultValue- value returned if the property doesn't exist or was not a number.- Returns:
- the property value specified by name or
defaultValue.
-
getLongProperty
Returns a long value Jive property. If the specified property doesn't exist, thedefaultValuewill be returned.- Parameters:
name- the name of the property to return.defaultValue- value returned if the property doesn't exist or was not a number.- Returns:
- the property value specified by name or
defaultValue.
-
getDoubleProperty
Returns a double value Jive property. If the specified property doesn't exist, thedefaultValuewill be returned.- Parameters:
name- the name of the property to return.defaultValue- value returned if the property doesn't exist or was not a number.- Returns:
- the property value specified by name or
defaultValue.
-
getBooleanProperty
Returns a boolean value Jive property.- Parameters:
name- the name of the property to return.- Returns:
- true if the property value exists and is set to
"true"(ignoring case). Otherwisefalseis returned.
-
getBooleanProperty
Returns a boolean value Jive property. If the property doesn't exist, thedefaultValuewill be returned. If the specified property can't be found, or if the value is not a number, thedefaultValuewill be returned.- Parameters:
name- the name of the property to return.defaultValue- value returned if the property doesn't exist.- Returns:
- true if the property value exists and is set to
"true"(ignoring case). Otherwisefalseis returned.
-
getPropertyNames
Return all immediate children property names of a parent Jive property as a list of strings, or an empty list if there are no children. For example, given the propertiesX.Y.A,X.Y.B,X.Y.CandX.Y.C.D, then the immediate child properties ofX.YareA,B, andC(C.Dwould not be returned using this method).- Parameters:
parent- Parent "node" to find the children of.- Returns:
- a List of all immediate children property names (Strings).
-
getProperties
Return all immediate children property values of a parent Jive property as a list of strings, or an empty list if there are no children. For example, given the propertiesX.Y.A,X.Y.B,X.Y.CandX.Y.C.D, then the immediate child properties ofX.YareX.Y.A,X.Y.B, andX.Y.C(the value ofX.Y.C.Dwould not be returned using this method).- Parameters:
parent- the name of the parent property to return the children for.- Returns:
- all child property values for the given parent.
-
getListProperty
Return all immediate children property values of a parent Jive property as a list of strings, or an default list if the property does not exist. This implementation ignores child property values that are empty (these are excluded from the result). When all child properties are empty, an empty collection (and explicitly not the default values) is returned. This allows a property to override a default non-empty collection with an empty one. The child properties that are evaluated in this method are the same child properties as those used bygetProperties(String).- Parameters:
parent- the name of the parent property to return the children for.defaultValues- values returned if the property doesn't exist.- Returns:
- all child property values for the given parent.
-
getPropertyNames
Returns all Jive property names.- Returns:
- a List of all property names (Strings).
-
setProperty
Sets a Jive property. If the property doesn't already exists, a new one will be created.- Parameters:
name- the name of the property being set.value- the value of the property being set.
-
setProperty
Sets a Jive property. If the property doesn't already exists, a new one will be created.- Parameters:
name- the name of the property being set.value- the value of the property being set.encrypt-trueto encrypt the property in the database, otherfalse
-
setProperty
Sets a Jive property with a list of values. If the property doesn't already exists, a new one will be created. Empty or null values in the collection are ignored. Each value is stored as a direct child property of the property name provided as an argument to this method. When this method is used, all previous children of the property will be deleted. When the provided value is null, any previously stored collection will be removed. If it is an empty collection (or a collection that consists of null and empty values onlu), it is stored as an empty collection (represented by a child property that has an empty value). The naming convention used by this method to define child properties is subject to change, and should not be depended on. This method differs fromsetProperties(Map), which is used to set multiple properties. This method sets one property with multiple values.- Parameters:
name- the name of the property being set.values- the values of the property.
-
setProperties
Sets multiple Jive properties at once. If a property doesn't already exists, a new one will be created. This method differs fromsetProperty(String, List), which is used to one property with multiple values. This method sets multiple properties, each with one value.- Parameters:
propertyMap- a map of properties, keyed on property name.
-
deleteProperty
Deletes a Jive property. If the property doesn't exist, the method does nothing. All children of the property will be deleted as well.- Parameters:
name- the name of the property to delete.
-
migrateProperty
Convenience routine to migrate an XML property into the database storage method. Will check for the XML property being null before migrating.- Parameters:
name- the name of the property to migrate.
-
migratePropertyTree
Convenience routine to migrate a tree of XML propertis into the database storage method.- Parameters:
name- the name of the base property to migrate.
-
isPropertySensitive
Flags certain properties as being sensitive, based on property naming conventions. Values for matching property names are hidden from the Openfire console.- Parameters:
name- The name of the property- Returns:
- True if the property is considered sensitive, otherwise false
-
isXMLPropertyEncrypted
Determines whether an XML property is configured for encryption.- Parameters:
name- The name of the property- Returns:
trueif the property is stored using encryption, otherwisefalse
-
isPropertyEncrypted
Determines whether a property is configured for encryption.- Parameters:
name- The name of the property- Returns:
trueif the property is stored using encryption, otherwisefalse
-
setPropertyEncrypted
Set the encryption status for the given property.- Parameters:
name- The name of the propertyencrypt- True to encrypt the property, false to decrypt- Returns:
- True if the property's encryption status changed, otherwise false
-
getPropertyEncryptor
Fetches the property encryptor.- Parameters:
useNewEncryptor- Should use the new encryptor- Returns:
- The property encryptor
-
getPropertyEncryptor
Fetches the current property encryptor.- Returns:
- The current property encryptor
-
setupPropertyEncryptionAlgorithm
This method is called early during the setup process to set the algorithm for encrypting property values- Parameters:
alg- the algorithm used to encrypt properties
-
setupPropertyEncryptionKey
This method is called early during the setup process to set a custom key for encrypting property values- Parameters:
key- the key used to encrypt properties
-
getMasterEncryptionKey
Gets the current master encryption key used for property encryption. The key is deobfuscated from security.xml. This method is primarily used by migration tools and encryption utilities that need direct access to the master key.- Returns:
- The current master encryption key, or null if no key is configured
-
getBlowfishSalt
Gets the Blowfish encryption salt. If no salt exists, generates a new cryptographically random 32-byte salt and stores it in security.xml.- Returns:
- Base64-encoded salt (32 bytes)
-
getBlowfishKdf
Gets the Blowfish key derivation function (KDF) type. Returns "sha1" for legacy single-round SHA1 hashing, or "pbkdf2" for PBKDF2-HMAC-SHA512 key derivation.- Returns:
- The KDF type ("sha1" or "pbkdf2"), defaults to "sha1" for backward compatibility
-
setBlowfishKdf
Sets the Blowfish key derivation function (KDF) type and re-initialises the property encryptor cache to use the new KDF immediately.- Parameters:
kdf- The KDF type ("sha1" or "pbkdf2")
-
migrateXMLPropertiesFromSHA1ToPBKDF2
public static int migrateXMLPropertiesFromSHA1ToPBKDF2()Migrates encrypted XML properties (in openfire.xml) from SHA1 to PBKDF2 key derivation. This method uses the encryptor swap pattern to re-encrypt properties: 1. Sets up SHA1 encryptor for decryption and PBKDF2 encryptor for encryption 2. Reads property names listed as encrypted in security.xml 3. For each property: reads value from openfire.xml (decrypts with SHA1), writes back (encrypts with PBKDF2) 4. Restores original encryptor state CRITICAL: This operation cannot be reversed without a backup. Call this BEFORE updating the KDF setting and BEFORE database migration.- Returns:
- Number of XML properties successfully migrated
- Throws:
IllegalStateException- if not using Blowfish encryption or already using PBKDF2RuntimeException- if migration fails for any property- Since:
- 5.1.0
-
getEncryptedXMLPropertyValueCount
public static int getEncryptedXMLPropertyValueCount()Returns the count of encrypted properties in openfire.xml that have values. This counts only properties from security.xml that exist in openfire.xml with non-empty values (i.e., properties that will actually be migrated).- Returns:
- Number of encrypted properties with values in openfire.xml
- Since:
- 5.1.0
-
isBlowfishMigrationNeeded
public static boolean isBlowfishMigrationNeeded()Checks whether Blowfish encryption migration from SHA1 to PBKDF2 is needed. Returns true if the server is currently using Blowfish encryption with the legacy SHA1 key derivation function.- Returns:
- true if migration from SHA1 to PBKDF2 is needed, false otherwise
- Since:
- 5.1.0
-
getEncryptionAlgorithm
Returns the encryption algorithm configured in security.xml.- Returns:
- The encryption algorithm ("AES" or "Blowfish"), defaults to "Blowfish" if not configured
- Since:
- 5.1.0
-
reinitialisePropertyEncryptor
public static void reinitialisePropertyEncryptor()Re-initialises the property encryptor with the current encryption settings. Call this after changing the encryption algorithm or KDF to ensure new properties are encrypted with the updated settings without requiring a restart.- Since:
- 5.1.0
-
setConfigName
Allows the name of the local config file name to be changed. The default is "openfire.xml".- Parameters:
configName- the name of the config file.
-
getConfigName
Returns the name of the local config file.- Returns:
- the name of the config file.
-
getSecurityConfigName
Returns the name of the local security config file.- Returns:
- the name of the security config file.
-
getConfigLocation
-
getSecurityConfigLocation
-