5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * Copyright (c) 2006 Sun Microsystems Inc. All Rights Reserved
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * The contents of this file are subject to the terms
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * of the Common Development and Distribution License
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * (the License). You may not use this file except in
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * compliance with the License.
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * You can obtain a copy of the License at
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * https://opensso.dev.java.net/public/CDDLv1.0.html or
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * See the License for the specific language governing
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * permission and limitations under the License.
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * When distributing Covered Code, include this CDDL
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * Header Notice in each file and include the License file
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * If applicable, add the following below the CDDL Header,
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * with the fields enclosed by brackets [] replaced by
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * your own identifying information:
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * "Portions Copyrighted [year] [name of copyright owner]"
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * $Id: SystemPropertiesManager.java,v 1.3 2008/06/25 05:53:01 qcheng Exp $
6cf99bcf5206a0fcc9dd9296fc46ac28c3fe8adePeter Major * Portions Copyrighted 2014-2016 ForgeRock AS.
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * This manages the system configuration class. The order for locating
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * the implementation class for ISystemProperties is
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * <li>Instantiate the class that is defined in System parameter,
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * <code>com.sun.identity.systemconfiguration</code> e.g.
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * <code>java -D"com.sun.identity.systemconfiguration=mypkg.myconfig"</code>
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * <li>Instantiate <code>com.sun.identity.common.SystemConfigurationUtil</code>
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * <li>Instantiate <code>com.sun.identity.configuration.SystemProperties</code>
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster private static ISystemProperties systemProperties;
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster private static final String DEBUG_SYSTEM_CONFIG =
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster "systempropertiesmanager";
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster "com.sun.identity.systemconfiguration";
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster // may be that PARAM_SYS_CONFIG is not defined
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster "com.sun.identity.configuration.FedSystemProperties") &&
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster // may be it is not a federation setup.
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster "com.sun.identity.configuration.SystemProperties") &&
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster "com.sun.identity.configuration.FedLibSystemProperties");
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster private static boolean instantiateDefinedProvider() {
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster boolean succeeded = true;
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster String param = System.getProperty(PARAM_SYS_CONFIG);
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster systemProperties = (ISystemProperties)clazz.newInstance();
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster private static boolean instantiateProvider(String providerClassName) {
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster boolean succeeded = false;
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster Class clazz = Class.forName(providerClassName);
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster systemProperties = (ISystemProperties)clazz.newInstance();
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster // ok if it is not found.
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * Returns system properties implementation class.
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * @return system properties implementation class.
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster public static ISystemProperties getSystemProperties() {
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * Returns property string.
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * @param key Key of the property.
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * @return property string.
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster return (systemProperties != null) ? systemProperties.get(key) : null;
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * Returns property string.
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * @param key Key of the property.
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * @param defaultValue Default value if the property is not found.
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * @return property string.
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster public static String get(String key, String defaultValue) {
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster return ((value != null) && (value.trim().length() > 0))
4b8ea03236c81cce9d3d032571eb2172bb446fe8Charles Sparey * Returns the property value as a boolean
4b8ea03236c81cce9d3d032571eb2172bb446fe8Charles Sparey * @since 13.0.0
4b8ea03236c81cce9d3d032571eb2172bb446fe8Charles Sparey * @param key the key whose value one is looking for.
4b8ea03236c81cce9d3d032571eb2172bb446fe8Charles Sparey * @return the boolean value if the key exists; otherwise returns false
4b8ea03236c81cce9d3d032571eb2172bb446fe8Charles Sparey public static boolean getAsBoolean(String key) {
6cf99bcf5206a0fcc9dd9296fc46ac28c3fe8adePeter Major * Returns the property value as a boolean.
6cf99bcf5206a0fcc9dd9296fc46ac28c3fe8adePeter Major * @since 13.0.0
6cf99bcf5206a0fcc9dd9296fc46ac28c3fe8adePeter Major * @param key The key whose value one is looking for.
6cf99bcf5206a0fcc9dd9296fc46ac28c3fe8adePeter Major * @param defaultValue The default value to return when the setting is not defined.
6cf99bcf5206a0fcc9dd9296fc46ac28c3fe8adePeter Major * @return The boolean value if the key exists; otherwise the default value is returned.
6cf99bcf5206a0fcc9dd9296fc46ac28c3fe8adePeter Major public static boolean getAsBoolean(String key, boolean defaultValue) {
9c1ec205dd4a7c6a5a2b06fa7385cf5b33274208Neil Madden * Returns property as an integer, returning the default if the property is not set or cannot be parsed as an
9c1ec205dd4a7c6a5a2b06fa7385cf5b33274208Neil Madden * @since 12.0.0
9c1ec205dd4a7c6a5a2b06fa7385cf5b33274208Neil Madden * @param key the system property name.
9c1ec205dd4a7c6a5a2b06fa7385cf5b33274208Neil Madden * @param defaultValue the default value to use if the property is not present or not an integer.
9c1ec205dd4a7c6a5a2b06fa7385cf5b33274208Neil Madden * @return the property value if present and a valid integer, otherwise the default value.
9c1ec205dd4a7c6a5a2b06fa7385cf5b33274208Neil Madden public static int getAsInt(String key, int defaultValue) {
9c1ec205dd4a7c6a5a2b06fa7385cf5b33274208Neil Madden // Return default value
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * Initializes the properties to be used by Open Federation Library.
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * Ideally this must be called first before any other method is called
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * within Open Federation Library. This method provides a programmatic way
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * to set the properties, and will override similar properties if loaded
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * for a properties file.
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * @param properties properties for Open Federation Library
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster public static void initializeProperties(Properties properties) {
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster systemProperties.initializeProperties(properties);
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * Initializes the properties map.
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * @param propertyName Name of properties.
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * @param propertyValue Value of properties.