Class SealedSystemPropertiesStringProperty
- java.lang.Object
-
- com.mchange.v2.cfg.SealedSystemPropertiesStringProperty
-
public class SealedSystemPropertiesStringProperty extends java.lang.ObjectA security-sensitive String setting -- in practice a class name -- read from System properties as of the seal, from supplied configuration live, or from a default.The String member of the family that includes
SealedSystemPropertiesBooleanPropertyandSealedSystemPropertiesWhitelistManager, and it shares their reason for treating the two sources differently. System properties are an ambient channel any code in the process can write, unguarded since SecurityManager's removal, so they are read fromSealedSystemPropertiesand later mutation is invisible. APropertiesConfigis a parameter the application chose to pass, and implementations are read-only views of configuration the application manages, so it is honored per call. Either may be null.Precedence, and how it differs from the others
A sealed System property wins; failing that, the supplied configuration; failing that, the default. That is a plain precedence rule, and it is not what the boolean and whitelist members do. Those resolve disagreement conservatively -- the safer of two answers stands, whichever source offered it -- because a boolean has a safe polarity and a whitelist has a narrower reading. A String has neither, so there is nothing to be conservative toward, and the question becomes simply whose word counts. The operator's does.
Do not read this as a weaker guarantee. Nothing an attacker writes to System properties after the seal is visible here at all, which is the property that matters; what is given up is only the ability to resolve a genuine disagreement toward safety, which for an opaque String is not a meaningful notion.
Whitespace
The intended values are class names handed to
Class.forName, andProperties.loadpreserves trailing whitespace, sosomeKey=com.example.Fooin a properties file yields a name that cannot resolve -- failing as a ClassNotFoundException for a class that looks correct in the file. Each source is therefore passed through aSealedSystemPropertiesStringProperty.Whitespacepolicy, chosen at construction:SealedSystemPropertiesStringProperty.Whitespace.TRIM_BLANKS_ARE_NULL(the default) trims, and treats a value that is blank after trimming as absent, so it falls through to the next source. This is what a class name wants: a straysomeKey=line yields the default rather thanClass.forName("").SealedSystemPropertiesStringProperty.Whitespace.TRIM_BLANKS_ARE_EMPTYtrims but returns the empty String, for a setting where "explicitly nothing" differs from "unset".SealedSystemPropertiesStringProperty.Whitespace.NO_TRIMreturns what was configured, for a setting whose values may carry significant whitespace.
Because trimming happens at each source rather than once at the end, a blank System property yields to a real configured value rather than masking it.
The default is used as-is
A default is a literal supplied by the calling code, not configuration, so it is returned unprocessed -- the whitespace policy does not apply to it. A default that is blank or carries surrounding whitespace is therefore almost certainly an authoring mistake, and is reported once, at the first lookup, whether or not the default is ever actually used: it is a defect in code rather than a condition of the deployment, and the person who can fix it should hear about it either way. An empty default under
SealedSystemPropertiesStringProperty.Whitespace.TRIM_BLANKS_ARE_EMPTYis exempt, that policy having declared the empty String meaningful.High-security defaults
Falling back to the default is reported too, once, and again if configuration appears and is later withdrawn -- a deployment running on the library's choice rather than its own should know it. But not every default is a concession. Some are the most restrictive setting available, and a setting whose default already refuses everything it ought to refuse is one almost nobody configures, so reporting the fallback would put a warning in front of nearly every user for being correctly configured. Constructing with
highSecurityDefaulttrue declares a default to be of that kind, and suppresses the notice.SealedSystemPropertiesBooleanPropertyneeds no such flag. A boolean has a safe polarity, so it can see for itself whether its default is the safe one and warn only when it is not. A String has no polarity, so only the caller knows.The flag suppresses that one notice and nothing else. A default carrying stray whitespace is still reported -- that is a mistake in code whatever the setting's security posture, and
Class.forNamewill not care how the author characterized it -- and a sealed System property taking over is still noted.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSealedSystemPropertiesStringProperty.Whitespace
-
Constructor Summary
Constructors Constructor Description SealedSystemPropertiesStringProperty(java.lang.String property)SealedSystemPropertiesStringProperty(java.lang.String property, java.lang.String defaultValue, boolean highSecurityDefault)SealedSystemPropertiesStringProperty(java.lang.String property, java.lang.String defaultValue, boolean highSecurityDefault, SealedSystemPropertiesStringProperty.Whitespace whitespace)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.StringgetDefaultValue()java.lang.StringgetProperty()java.lang.StringgetValue(PropertiesConfig pcfg, MLogger logger)SealedSystemPropertiesStringProperty.WhitespacegetWhitespace()booleanisHighSecurityDefault()
-
-
-
Constructor Detail
-
SealedSystemPropertiesStringProperty
public SealedSystemPropertiesStringProperty(java.lang.String property, java.lang.String defaultValue, boolean highSecurityDefault, SealedSystemPropertiesStringProperty.Whitespace whitespace)
-
SealedSystemPropertiesStringProperty
public SealedSystemPropertiesStringProperty(java.lang.String property, java.lang.String defaultValue, boolean highSecurityDefault)
-
SealedSystemPropertiesStringProperty
public SealedSystemPropertiesStringProperty(java.lang.String property)
-
-
Method Detail
-
getProperty
public java.lang.String getProperty()
-
getDefaultValue
public java.lang.String getDefaultValue()
-
isHighSecurityDefault
public boolean isHighSecurityDefault()
-
getWhitespace
public SealedSystemPropertiesStringProperty.Whitespace getWhitespace()
-
getValue
public java.lang.String getValue(PropertiesConfig pcfg, MLogger logger)
-
-