Package ddf.security.expansion.impl
Class AbstractExpansion
java.lang.Object
ddf.security.expansion.impl.AbstractExpansion
- All Implemented Interfaces:
ddf.security.expansion.Expansion
- Direct Known Subclasses:
RegexExpansion,StraightExpansionImpl
Base class for all expansion services. Provides the generic setting/getting for attribute
separator as well as the actual map of expansion rules. Defines an abstrace
doExpansion
method to be overridden with the appropriate logic.-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringString to mark the line as a comment in the configuration filestatic final StringDefault filename for the user attribute mapping configuration file.static final StringDefault string that separates individual attributes in the replacement strings.protected static final org.slf4j.Loggerstatic final StringSeparator for various parts of the rules when presented as a string.protected Patternstatic final StringString to identify the line containing the attribute separator string in the configuration file. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddExpansionList(String key, List<String[]> list) Adds a list of rules corresponding to the give key in the expansion map.voidaddExpansionRule(String key, String[] rule) Adds an individual expansion rule to the existing (or newly created) expansion map.protected abstract StringdoExpansion(String original, String[] rule) This is the method that will do the actual expansion - interpreting the rules and expanding the values.protected voidloadConfiguration(String filename) Does the work of reading the configuration file and configuring the expansion map and attribute separator.booleanremoveExpansionRule(String key, String[] rule) Removes a single rule from the expansion map (if it exists).voidsetAttributeSeparator(String separator) Sets the separator to be used in splitting up replacement strings.voidsetExpansionFileName(String filename) Sets the name of the configuration file defining the attribute separator and the mapping of attributes to their expanded values.voidsetExpansionMap(Map<String, List<String[]>> table) Sets the expansion map (which includes a set of keys corresponding to attribute names, each with a corresponding list of rules that apply to that attribute.voidsetExpansionRules(List<String> rulesList) Adds a list of rules provided in String form.protected Collection<String>Takes a string with potentially multiple values and splits it into a collection of strings.void
-
Field Details
-
DEFAULT_VALUE_SEPARATOR
Default string that separates individual attributes in the replacement strings.- See Also:
-
RULE_SPLIT_REGEX
Separator for various parts of the rules when presented as a string.- See Also:
-
CFG_COMMENT_STR
String to mark the line as a comment in the configuration file- See Also:
-
SEPARATOR_PREFIX
String to identify the line containing the attribute separator string in the configuration file.- See Also:
-
DEFAULT_CONFIG_FILE_NAME
Default filename for the user attribute mapping configuration file.- See Also:
-
LOGGER
protected static final org.slf4j.Logger LOGGER -
rulePattern
-
expansionTable
-
-
Constructor Details
-
AbstractExpansion
public AbstractExpansion()
-
-
Method Details
-
expand
- Specified by:
expandin interfaceddf.security.expansion.Expansion
-
expand
- Specified by:
expandin interfaceddf.security.expansion.Expansion
-
doExpansion
This is the method that will do the actual expansion - interpreting the rules and expanding the values. It is abstract and will be overridden by each concrete implementation.- Parameters:
original- the original value of the attributerule- the rule that describes the expansion for one specific attribute value- Returns:
- the (possibly) expanded result of applying the rule to the original value
-
getExpansionMap
- Specified by:
getExpansionMapin interfaceddf.security.expansion.Expansion
-
setExpansionMap
Sets the expansion map (which includes a set of keys corresponding to attribute names, each with a corresponding list of rules that apply to that attribute. If the passed in table is null, an empty expansion map is created.- Parameters:
table- the complete map of attributes and their corresponding list of rules
-
addExpansionRule
Adds an individual expansion rule to the existing (or newly created) expansion map. If an entry already exists for the given attribute key, this rule is added to that entry, if an entry doesn't exist, it is created and then this rule added. If invalid input is received, nothing is done.- Parameters:
key- the attribute for which the corresponding rule should be addedrule- the expansion rule to apply to the corresponding attribute
-
removeExpansionRule
Removes a single rule from the expansion map (if it exists). Returns a boolean indicating if the specified rule was successfully removed.- Parameters:
key- the attribute for which the corresponding rule should be removedrule- the rule to be removed from the list of rules for the corresponding attribute- Returns:
- true if the rule was found and removed, false otherwise
-
addExpansionList
Adds a list of rules corresponding to the give key in the expansion map. Convenience method for adding each rule individually.- Parameters:
key- the attribute for which the corresponding list of rules will be addedlist- the list of rules to be added to the corresponding attribute
-
setExpansionRules
Adds a list of rules provided in String form. This is a convenience method for adding each rule individually.- Parameters:
rulesList- list of rules (in String form) to be added to the expansion map
-
split
Takes a string with potentially multiple values and splits it into a collection of strings.- Parameters:
source- input source string potentially containing multiple tokensseparator- the sequence separating the individual tokens- Returns:
- a collection containing the individual tokens extracted from the specified source string
-
setAttributeSeparator
Sets the separator to be used in splitting up replacement strings. If a null or empty value is passed in, the default separator (a space) is used.- Parameters:
separator- the separator to be used to split up replacement strings
-
setExpansionFileName
Sets the name of the configuration file defining the attribute separator and the mapping of attributes to their expanded values. This file is read initially, and whenever the file name is set. If the name is null or empty, the existing map of rules is cleared.- Parameters:
filename- the name of the configuration file to be loaded into the expansion service
-
update
-
loadConfiguration
Does the work of reading the configuration file and configuring the expansion map and attribute separator.- Parameters:
filename- the name of the file to be read and processed
-