All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.owasp.esapi.configuration.EsapiPropertyManager Maven / Gradle / Ivy

Go to download

The Enterprise Security API (ESAPI) project is an OWASP project to create simple strong security controls for every web platform. Security controls are not simple to build. You can read about the hundreds of pitfalls for unwary developers on the OWASP website. By providing developers with a set of strong controls, we aim to eliminate some of the complexity of creating secure web applications. This can result in significant cost savings across the SDLC.

There is a newer version: 2.5.5.0
Show newest version
package org.owasp.esapi.configuration;

import org.owasp.esapi.configuration.consts.EsapiConfiguration;
import org.owasp.esapi.errors.ConfigurationException;

import java.util.TreeSet;

import static org.owasp.esapi.configuration.EsapiPropertyLoaderFactory.createPropertyLoader;

/**
 * Manager used for loading security configuration properties. Does all the logic to obtain the correct property from
 * correct source. Uses following system properties to find configuration files:
 * 
 * - org.owasp.esapi.devteam - lower priority dev file path
 * - org.owasp.esapi.opsteam - higher priority ops file path
 * 
* * @since 2.2 */ public class EsapiPropertyManager implements EsapiPropertyLoader { protected TreeSet loaders; public EsapiPropertyManager() { initLoaders(); } /** * {@inheritDoc} */ @Override public int getIntProp(String propertyName) throws ConfigurationException { for (AbstractPrioritizedPropertyLoader loader : loaders) { try { return loader.getIntProp(propertyName); } catch (ConfigurationException e) { System.err.println("Property not found in " + loader.name()); } } throw new ConfigurationException("Could not find property " + propertyName + " in configuration"); } /** * {@inheritDoc} */ @Override public byte[] getByteArrayProp(String propertyName) throws ConfigurationException { for (AbstractPrioritizedPropertyLoader loader : loaders) { try { return loader.getByteArrayProp(propertyName); } catch (ConfigurationException e) { System.err.println("Property not found in " + loader.name()); } } throw new ConfigurationException("Could not find property " + propertyName + " in configuration"); } /** * {@inheritDoc} */ @Override public Boolean getBooleanProp(String propertyName) throws ConfigurationException { for (AbstractPrioritizedPropertyLoader loader : loaders) { try { return loader.getBooleanProp(propertyName); } catch (ConfigurationException e) { System.err.println("Property not found in " + loader.name()); } } throw new ConfigurationException("Could not find property " + propertyName + " in configuration"); } /** * {@inheritDoc} */ @Override public String getStringProp(String propertyName) throws ConfigurationException { for (AbstractPrioritizedPropertyLoader loader : loaders) { try { return loader.getStringProp(propertyName); } catch (ConfigurationException e) { System.err.println("Property : " + propertyName + " not found in " + loader.name()); } } throw new ConfigurationException("Could not find property " + propertyName + " in configuration"); } private void initLoaders() { loaders = new TreeSet(); try { loaders.add(createPropertyLoader(EsapiConfiguration.OPSTEAM_ESAPI_CFG)); } catch (Exception e) { System.err.println(e.getMessage()); } try { loaders.add(createPropertyLoader(EsapiConfiguration.DEVTEAM_ESAPI_CFG)); } catch (Exception e) { System.err.println(e.getMessage()); } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy