public class SafeConfig extends Object
Implements common logic and constants for tools which automatically
locks down the public void configure(Map params)
method after
it is called once.
This keeps application or session scoped tools thread-safe in templates,
which generally have access to the tool after configuration has happened.
It also provides for a separate "safe mode" setting which tells
tools to block any functions that may pose a security threat. This,
of course, is set to true
by default.
Once "locked down", the configure(Map)
may still be called,
however it will do nothing (unless some subclass is foolish enough to
override it and not check if isConfigLocked()
before changing
configurations. The proper method for subclasses to override is
configure(ValueParser)
which will only be called by
configure(Map)
when the isConfigLocked()
is false
(i.e. the first time only).
Modifier and Type | Field and Description |
---|---|
static String |
LOCK_CONFIG_KEY
The key used for specifying whether or not to prevent templates
from reconfiguring this tool.
|
protected org.slf4j.Logger |
log |
static String |
LOGGER_NAME_KEY
Key used to explicitely specify the logger name
|
static String |
SAFE_MODE_KEY
Many tools interested in locking configure() also have other
things they wish to secure.
|
static String |
USE_CLASS_LOGGER_KEY
Key used to specify whether or not tools shall use loggers
named after the tools classes.
|
Constructor and Description |
---|
SafeConfig() |
Modifier and Type | Method and Description |
---|---|
void |
configure(Map params)
If
isConfigLocked() returns true , then this method
does nothing; otherwise, if false , this will create a new
ValueParser from the specified Map of params and call
configure(ValueParser) with it. |
protected void |
configure(ValueParser values)
Does the actual configuration.
|
protected org.slf4j.Logger |
getLog()
Get logger
|
protected void |
initLogger(ValueParser params)
Initialize logger.
|
boolean |
isConfigLocked()
Returns
true if the configure(Map) method
has been locked. |
boolean |
isSafeMode()
Returns
true if this tool is in "safe mode". |
protected void |
setLockConfig(boolean lock)
Only allow subclass access to this.
|
protected void |
setSafeMode(boolean safe)
Set or clear safe mode.
|
public static final String LOCK_CONFIG_KEY
public static final String SAFE_MODE_KEY
public static final String LOGGER_NAME_KEY
public static final String USE_CLASS_LOGGER_KEY
protected org.slf4j.Logger log
protected void setLockConfig(boolean lock)
lock
- whether to lock configprotected void setSafeMode(boolean safe)
safe
- whether to set safe modepublic boolean isConfigLocked()
true
if the configure(Map)
method
has been locked.public boolean isSafeMode()
true
if this tool is in "safe mode".public void configure(Map params)
isConfigLocked()
returns true
, then this method
does nothing; otherwise, if false
, this will create a new
ValueParser
from the specified Map of params and call
configure(ValueParser)
with it. Then this will check
the parameters itself to find out whether or not the configuration
for this tool should be put into safe mode or have its config locked.
The safe mode value should be a boolean under the key
SAFE_MODE_KEY
and the lock value should be a boolean
under the key LOCK_CONFIG_KEY
.params
- configuration values mapprotected void configure(ValueParser values)
values
- configuration valuesprotected void initLogger(ValueParser params)
params
- configuration parametersprotected org.slf4j.Logger getLog()
Copyright © 2002–2018 The Apache Software Foundation. All rights reserved.