Class SystemProperties


  • @SupportedAll
    public class SystemProperties
    extends Object
    This class provides functionality that allows single-point-of-access to all related system properties.

    The system properties can be set in couple of ways: programmatically by calling the initializeProperties method, or can be statically loaded at startup from a file named: AMConfig.[class,properties]. Setting the properties through the API takes precedence and will replace the properties loaded via file. For statically loading the properties via a file, this class tries to first find a class, AMConfig.class, and then a file, AMConfig.properties in the CLASSPATH accessible to this code. The AMConfig.class takes precedence over the flat file AMConfig.properties.

    If multiple servers are running, each may have their own configuration file. The naming convention for such scenarios is AMConfig-<serverName>.

    • Field Detail

      • CONFIG_PATH

        public static final String CONFIG_PATH
        Runtime flag to be set, in order to override the path of the configuration file.
        See Also:
        Constant Field Values
      • CONFIG_FILE_NAME

        public static final String CONFIG_FILE_NAME
        Default name of the configuration file.
        See Also:
        Constant Field Values
    • Constructor Detail

      • SystemProperties

        public SystemProperties()
    • Method Detail

      • get

        public static String get​(String key)
        This method lets you query for a system property whose value is same as String key. The method first tries to read the property from java.lang.System followed by a lookup in the config file.
        Parameters:
        key - type String, the key whose value one is looking for.
        Returns:
        the value if the key exists; otherwise returns null
      • replaceServerUriPlaceholder

        public static String replaceServerUriPlaceholder​(String line,
                                                         String value)
        Deal with the special case where OpenAM is deployed at the ROOT context so that lines containing the %SERVER_URI% placeholder are properly handled.
        Parameters:
        line - String the line to replace occurrences of the %SERVER_URI% placeholder.
        value - String the value to use in place of the %SERVER_URI% placeholder.
        Returns:
        A string based on line with any %SERVER_URI% placeholders replaced with value.
      • get

        public static String get​(String key,
                                 String def)
        This method lets you query for a system property whose value is same as String key.
        Parameters:
        key - the key whose value one is looking for.
        def - the default value if the key does not exist.
        Returns:
        the value if the key exists; otherwise returns default value.
      • getAsBoolean

        public static boolean getAsBoolean​(String key)
        Returns the property value as a boolean
        Parameters:
        key - the key whose value one is looking for.
        Returns:
        the boolean value if the key exists; otherwise returns false
      • getAsBoolean

        public static boolean getAsBoolean​(String key,
                                           boolean defaultValue)
        Returns the property value as a boolean
        Parameters:
        key - the property name.
        defaultValue - value if key is not found.
        Returns:
        the boolean value if the key exists; otherwise the default value
      • getAsInt

        public static int getAsInt​(String key,
                                   int defaultValue)
        Parameters:
        key - The System Property key to lookup.
        defaultValue - If the property was not set, or could not be parsed to an int.
        Returns:
        Either the defaultValue, or the numeric value assigned to the System Property.
      • getAsLong

        public static long getAsLong​(String key,
                                     long defaultValue)
        Parameters:
        key - The System Property key to lookup.
        defaultValue - If the property was not set, or could not be parsed to a long.
        Returns:
        Either the defaultValue, or the numeric value assigned to the System Property.
      • getAsSet

        public static Set<String> getAsSet​(String key,
                                           String delimiterRegex,
                                           Set<String> defaultValue)
        Parses a system property as a set of strings by splitting the value on the given delimiter expression.
        Parameters:
        key - The System Property key to lookup.
        delimiterRegex - The regular expression to use to split the value into elements in the set.
        defaultValue - The default set to return if the property does not exist.
        Returns:
        the value of the property parsed as a set of strings.
      • getAsSet

        public static Set<String> getAsSet​(String key,
                                           String delimiterRegex)
        Parses a system property as a set of strings by splitting the value on the given delimiter expression.
        Parameters:
        key - The System Property key to lookup.
        delimiterRegex - The regular expression to use to split the value into elements in the set.
        Returns:
        the value of the property parsed as a set of strings or an empty set if no match is found.
      • getAsSet

        public static Set<String> getAsSet​(String key)
        Parses a system property as a set of strings by splitting the value on white space characters.
        Parameters:
        key - The System Property key to lookup.
        Returns:
        the value of the property parsed as a set of strings or an empty set if no match is found.
      • getProperties

        public static Properties getProperties()
        Returns all the properties defined and their values. This is a defensive copy of the properties and so updates to the returned object will not be reflected in the actual properties used by OpenAM.
        Returns:
        Properties object with a copy of all the key value pairs.
      • getAll

        public static Properties getAll()
        This method lets you get all the properties defined and their values. The method first tries to load the properties from java.lang.System followed by a lookup in the config file.
        Returns:
        Properties object with all the key value pairs.
      • getPlatform

        @Deprecated
        public static Properties getPlatform()
        Deprecated.
        use getAll()
        This method lets you query for all the platform properties defined and their values. Returns a Properties object with all the key value pairs.
        Returns:
        the platform properties
      • initializeProperties

        public static void initializeProperties​(String file)
                                         throws MissingResourceException
        Initializes properties bundle from the file passed.
        Parameters:
        file - type String, file name for the resource bundle
        Throws:
        MissingResourceException - If the resource bundle cannot be found.
      • initializeProperties

        public static void initializeProperties​(Properties properties)
      • initializeProperties

        public static void initializeProperties​(Properties properties,
                                                boolean reset)
        Initializes the properties to be used by OpenAM. Ideally this must be called first before any other method is called within OpenAM. This method provides a programmatic way to set the properties, and will override similar properties if loaded for a properties file.
        Parameters:
        properties - properties for OpenAM
        reset - true to reset existing properties.
      • initializeProperties

        public static void initializeProperties​(Properties properties,
                                                boolean reset,
                                                boolean withDefaults)
        Initializes the properties to be used by OpenAM. Ideally this must be called first before any other method is called within OpenAM. This method provides a programmatic way to set the properties, and will override similar properties if loaded for a properties file.
        Parameters:
        properties - properties for OpenAM.
        reset - true to reset existing properties.
        withDefaults - true to include default properties.
      • initializeProperties

        public static void initializeProperties​(String propertyName,
                                                String propertyValue)
        Initializes a property to be used by OpenAM. Ideally this must be called first before any other method is called within OpenAM. This method provides a programmatic way to set a specific property, and will override similar property if loaded for a properties file.
        Parameters:
        propertyName - property name.
        propertyValue - property value.
      • lastModified

        public static long lastModified()
        Returns a counter for last modification. The counter is incremented if the properties are changed by calling the following method initializeProperties. This is a convenience method for applications to track changes to OpenAM properties.
        Returns:
        counter of the last modification
      • setServerInstanceName

        public static void setServerInstanceName​(String name)
        Sets the server instance name of which properties are retrieved to initialized this object.
        Parameters:
        name - Server instance name.
      • getServerInstanceName

        public static String getServerInstanceName()
        Returns the server instance name of which properties are retrieved to initialized this object.
        Returns:
        Server instance name.
      • isServerMode

        public static boolean isServerMode()
        Returns true if instance is running in server mode.
        Returns:
        true if instance is running in server mode.
      • getConfigPath

        public static String getConfigPath()
      • getAttributeMap

        public static Map<String,​com.sun.identity.common.AttributeStruct> getAttributeMap()
        Returns the property name to service attribute schema name mapping.
        Returns:
        Property name to service attribute schema name mapping.
      • observe

        public static void observe​(com.sun.identity.common.configuration.ConfigurationListener listener,
                                   String... properties)
        Listen for runtime changes to a system property value. Only values that are stored in the SMS will be changed at runtime. See serverdefaults.properties, amPlatform.xml and serverAttributeMap.properties.
        Parameters:
        listener - The listener to call when one of the provided properties has changed.
        properties - The list of properties that should be observed. A change in any one of these properties will cause the listener to be notified.