Class AbstractExpansion

java.lang.Object
ddf.security.expansion.impl.AbstractExpansion
All Implemented Interfaces:
ddf.security.expansion.Expansion
Direct Known Subclasses:
RegexExpansion, StraightExpansionImpl

public abstract class AbstractExpansion extends Object implements ddf.security.expansion.Expansion
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 Details

    • DEFAULT_VALUE_SEPARATOR

      public static final String DEFAULT_VALUE_SEPARATOR
      Default string that separates individual attributes in the replacement strings.
      See Also:
    • RULE_SPLIT_REGEX

      public static final String RULE_SPLIT_REGEX
      Separator for various parts of the rules when presented as a string.
      See Also:
    • CFG_COMMENT_STR

      public static final String CFG_COMMENT_STR
      String to mark the line as a comment in the configuration file
      See Also:
    • SEPARATOR_PREFIX

      public static final String SEPARATOR_PREFIX
      String to identify the line containing the attribute separator string in the configuration file.
      See Also:
    • DEFAULT_CONFIG_FILE_NAME

      public static final String DEFAULT_CONFIG_FILE_NAME
      Default filename for the user attribute mapping configuration file.
      See Also:
    • LOGGER

      protected static final org.slf4j.Logger LOGGER
    • rulePattern

      protected Pattern rulePattern
    • expansionTable

      protected Map<String,List<String[]>> expansionTable
  • Constructor Details

    • AbstractExpansion

      public AbstractExpansion()
  • Method Details

    • expand

      public Map<String,Set<String>> expand(Map<String,Set<String>> map)
      Specified by:
      expand in interface ddf.security.expansion.Expansion
    • expand

      public Set<String> expand(String key, Set<String> values)
      Specified by:
      expand in interface ddf.security.expansion.Expansion
    • doExpansion

      protected abstract String doExpansion(String original, String[] rule)
      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 attribute
      rule - 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

      public Map<String,List<String[]>> getExpansionMap()
      Specified by:
      getExpansionMap in interface ddf.security.expansion.Expansion
    • setExpansionMap

      public void setExpansionMap(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. 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

      public void addExpansionRule(String key, String[] rule)
      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 added
      rule - the expansion rule to apply to the corresponding attribute
    • removeExpansionRule

      public boolean removeExpansionRule(String key, String[] rule)
      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 removed
      rule - 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

      public void addExpansionList(String key, List<String[]> list)
      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 added
      list - the list of rules to be added to the corresponding attribute
    • setExpansionRules

      public void setExpansionRules(List<String> rulesList)
      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

      protected Collection<String> split(String source, String separator)
      Takes a string with potentially multiple values and splits it into a collection of strings.
      Parameters:
      source - input source string potentially containing multiple tokens
      separator - the sequence separating the individual tokens
      Returns:
      a collection containing the individual tokens extracted from the specified source string
    • setAttributeSeparator

      public void setAttributeSeparator(String separator)
      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

      public void setExpansionFileName(String filename)
      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

      public void update(Map<String,String> properties)
    • loadConfiguration

      protected void loadConfiguration(String filename)
      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