Class SealedSystemProperties
- java.lang.Object
-
- com.mchange.v2.cfg.SealedSystemProperties
-
public final class SealedSystemProperties extends java.lang.ObjectA snapshot of this JVM's System properties, taken once and never retaken, for configuration whose meaning must not change after an application has started.Why this exists
System properties are writable by any code in the process, at any time. That was once checked --
System.setPropertyrequired aPropertyPermission(..., "write")under a SecurityManager -- but SecurityManager was deprecated by JEP 411 and permanently disabled by JEP 486, so on a current JVM there is no check at all. Security configuration read live from System properties therefore means only what it meant at the instant it was read, and can be rewritten afterward by anything running in the same process.The platform solves this for itself the same way: the JVM keeps its own snapshot of the properties it was launched with, and several security-sensitive values (the serialization filter, the temporary directory, various TLS and RMI settings) are captured once and are simply not re-read. This class offers that to library and application code.
When the snapshot is taken
The snapshot is taken at the first call to
get(), and there is exactly one for the lifetime of the JVM. Two consequences follow, and both matter:- Reading seals.
get()is not a passive accessor; the first call fixes the snapshot as a side effect. Any consumer anywhere in the process can therefore be the one that seals, simply by consulting configuration. - Sealing is global. One snapshot serves every consumer, so they cannot disagree about what the properties were -- but equally, whoever reads first decides the instant for everyone.
A deployment that wants to choose that instant should call
seal()at the end of its own startup, once it has set every property it intends to set.seal()returnstrueif the call is what sealed the snapshot andfalse-- with a warning -- if something had already sealed it, which is worth attending to: it means the effective snapshot was taken at a moment the caller did not choose.isSealed()answers the same question without causing a seal.What this does and does not do
It does not prevent anything.
System.setPropertycontinues to work, and code that callsSystem.getPropertydirectly continues to see live values. What the snapshot provides is a source of configuration that a later write cannot alter, for the consumers that choose to read from it. Late writes are not rejected; they are invisible here.Nor does this class decide policy. It holds the properties; what to do when current configuration disagrees with them belongs to the consumer.
EarliestOrNarrowestWhitelistManageris the one in this library today: it honors later changes that narrow a whitelist and ignores those that would widen it.MConfig.sealSystemProperties(),MConfig.getSealedSystemProperties()andMConfig.isSealedSystemProperties()forward to these methods, for callers who reach for MConfig first.A constraint on logging
Initializing
com.mchange.v2.logmust never consult this class. Sealing reads configuration and logs what it did, so a logger that sealed in order to initialize would re-enter its own initialization. That is why MLog resolves its backend with a direct reflective construction rather than through a whitelist-gated one, and why the logger here is obtained lazily rather than in a static initializer. - Reading seals.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringNOTIONAL_RESOURCE_PATH
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static MultiPropertiesConfigcapCurrentThenSealAndCombine(MultiPropertiesConfig[] overrides)NOT safe for use on/before mlog initialization pathwaystatic java.lang.String[]capCurrentThenSealed(java.lang.String[] resources)safe for use on/before mlog initialization pathwaystatic MultiPropertiesConfigget()NOT safe for use on/before mlog initialization pathwaystatic MultiPropertiesConfiginitCapCurrentThenSealAndCombine(MultiPropertiesConfig[] overrides, java.util.List<DelayedLogItem> delayedLogItems)safe for use on/before mlog initialization pathwaystatic MultiPropertiesConfiginitGet(java.util.List<DelayedLogItem> delayedLogItems)safe for use on/before mlog initialization pathwaystatic booleaninitSeal(java.util.List<DelayedLogItem> delayedLogItems)safe for use on/before mlog initialization pathwaystatic booleanisSealed()safe for use on/before mlog initialization pathwaystatic booleanseal()NOT safe for use on/before mlog initialization pathway
-
-
-
Field Detail
-
NOTIONAL_RESOURCE_PATH
public static final java.lang.String NOTIONAL_RESOURCE_PATH
- See Also:
- Constant Field Values
-
-
Method Detail
-
initCapCurrentThenSealAndCombine
public static MultiPropertiesConfig initCapCurrentThenSealAndCombine(MultiPropertiesConfig[] overrides, java.util.List<DelayedLogItem> delayedLogItems)
safe for use on/before mlog initialization pathway
-
initGet
public static MultiPropertiesConfig initGet(java.util.List<DelayedLogItem> delayedLogItems)
safe for use on/before mlog initialization pathway
-
initSeal
public static boolean initSeal(java.util.List<DelayedLogItem> delayedLogItems)
safe for use on/before mlog initialization pathway
-
isSealed
public static boolean isSealed()
safe for use on/before mlog initialization pathway
-
capCurrentThenSealed
public static java.lang.String[] capCurrentThenSealed(java.lang.String[] resources)
safe for use on/before mlog initialization pathway
-
capCurrentThenSealAndCombine
public static MultiPropertiesConfig capCurrentThenSealAndCombine(MultiPropertiesConfig[] overrides)
NOT safe for use on/before mlog initialization pathway
-
get
public static MultiPropertiesConfig get()
NOT safe for use on/before mlog initialization pathway
-
seal
public static boolean seal()
NOT safe for use on/before mlog initialization pathway
-
-