Class AuthorizationEntity

java.lang.Object
org.opengrok.indexer.authorization.AuthorizationEntity
All Implemented Interfaces:
Serializable, Cloneable, Nameable
Direct Known Subclasses:
AuthorizationStack

public abstract class AuthorizationEntity extends Object implements Nameable, Serializable, Cloneable
This class covers authorization entities used in opengrok. Currently there are two:
  • stack of plugins
  • plugin
The purpose is to extract common member variables and methods into an class, namely:
  • name
  • role - sufficient/required/requisite
  • state - working/failed
  • setup - from configuration
and let the subclasses implement the important abstract methods. This class is intended to be read from a configuration.
Author:
Krystof Tulinger
See Also:
  • Field Details

    • flag

      protected AuthControlFlag flag
      One of "required", "requisite", "sufficient".
    • name

      protected String name
    • setup

      protected transient Map<String,Object> setup
    • currentSetup

      protected transient Map<String,Object> currentSetup
      Hold current setup - merged with all ancestor's stacks.
    • working

      protected transient boolean working
  • Constructor Details

    • AuthorizationEntity

      protected AuthorizationEntity()
    • AuthorizationEntity

      protected AuthorizationEntity(AuthorizationEntity x)
      Copy constructor for the entity.
      • copy flag
      • copy name
      • deep copy of the setup
      • copy the working attribute
      Parameters:
      x - the entity to be copied
    • AuthorizationEntity

      protected AuthorizationEntity(AuthControlFlag flag, String name)
  • Method Details

    • load

      public abstract void load(Map<String,Object> parameters)
      Load this entity with given parameters.
      Parameters:
      parameters - given parameters passed to the plugin's load method
      See Also:
    • unload

      public abstract void unload()
      Unload this entity.
      See Also:
    • isAllowed

      public abstract boolean isAllowed(Nameable entity, AuthorizationEntity.PluginDecisionPredicate pluginPredicate, AuthorizationEntity.PluginSkippingPredicate skippingPredicate)
      Test the given entity if it should be allowed with this authorization check.
      Parameters:
      entity - the given entity - this is either group or project and is passed just for the logging purposes.
      pluginPredicate - predicate returning true or false for the given entity which determines if the authorization for such entity is successful or failed
      skippingPredicate - predicate returning true if this authorization entity should be omitted from the authorization process
      Returns:
      true if successful; false otherwise
    • setPlugin

      public abstract boolean setPlugin(IAuthorizationPlugin plugin)
      Set the plugin to all classes which requires this class in the configuration. This creates a new instance of the plugin for each class which needs it.
      Parameters:
      plugin - the new instance of a plugin
      Returns:
      true if there is such case; false otherwise
    • clone

      public abstract AuthorizationEntity clone()
      Perform a deep copy of the entity.
      Overrides:
      clone in class Object
      Returns:
      the new instance of this entity
    • hierarchyToString

      public abstract String hierarchyToString(String prefix, String colorElement)
      Print the entity hierarchy.
      Parameters:
      prefix - this prefix should be prepended to every line produced by this entity
      colorElement - a possible element where any occurrence of %color% will be replaced with a HTML HEX color representing this entity state.
      Returns:
      the string containing this entity representation
    • getFlag

      public AuthControlFlag getFlag()
      Get the value of flag.
      Returns:
      the value of flag
    • setFlag

      public void setFlag(AuthControlFlag flag)
      Set the value of flag.
      Parameters:
      flag - new value of flag
    • setFlag

      public void setFlag(String flag)
      Set the value of flag.
      Parameters:
      flag - new value of flag
    • getName

      public String getName()
      Get the value of name.
      Specified by:
      getName in interface Nameable
      Returns:
      the value of name
    • setName

      public void setName(String name)
      Set the value of name.
      Specified by:
      setName in interface Nameable
      Parameters:
      name - new value of name
    • getSetup

      public Map<String,Object> getSetup()
      Get the value of setup.
      Returns:
      the value of setup
    • setSetup

      public void setSetup(Map<String,Object> setup)
      Set the value of setup.
      Parameters:
      setup - new value of setup
    • getCurrentSetup

      public Map<String,Object> getCurrentSetup()
      Get the value of current setup.
      Returns:
      the value of current setup
    • setCurrentSetup

      public void setCurrentSetup(Map<String,Object> currentSetup)
      Set the value of current setup.
      Parameters:
      currentSetup - new value of current setup
    • forProjects

      public Set<String> forProjects()
      Get the value of forProjects.
      Returns:
      the value of forProjects
    • getForProjects

      public Set<String> getForProjects()
      Get the value of forProjects.
      Returns:
      the value of forProjects
    • setForProjects

      public void setForProjects(Set<String> forProjects)
      Set the value of forProjects.
      Parameters:
      forProjects - new value of forProjects
    • setForProjects

      public void setForProjects(String project)
      Set the value of forProjects.
      Parameters:
      project - add this project into the set
    • setForProjects

      public void setForProjects(String[] projects)
      Set the value of forProjects.
      Parameters:
      projects - add all projects in this array into the set
      See Also:
    • forGroups

      public Set<String> forGroups()
      Get the value of forGroups.
      Returns:
      the value of forGroups
    • getForGroups

      public Set<String> getForGroups()
      Get the value of forGroups.
      Returns:
      the value of forGroups
    • setForGroups

      public void setForGroups(Set<String> forGroups)
      Set the value of forGroups.
      Parameters:
      forGroups - new value of forGroups
    • setForGroups

      public void setForGroups(String group)
      Set the value of forGroups.
      Parameters:
      group - add this group into the set
    • setForGroups

      public void setForGroups(String[] groups)
      Set the value of forGroups.
      Parameters:
      groups - add all groups in this array into the set
      See Also:
    • processTargetGroupsAndProjects

      protected void processTargetGroupsAndProjects()
      Discover all targeted groups and projects for every group given by forGroups().
      • add to the forGroups() all groups which are descendant groups to the group
      • add to the forGroups() all groups which are parent groups to the group
      • add to the forProjects() all projects and repositories which are in the descendant groups or in the group itself
      • issue a warning for non-existent groups
      • issue a warning for non-existent projects
    • isWorking

      public boolean isWorking()
      Check if the plugin exists and has not failed while loading.
      Returns:
      true if working, false otherwise
    • setWorking

      public void setWorking()
      Mark this entity as working.
    • isFailed

      public boolean isFailed()
      Check if this plugin has failed during loading or is missing. This method has the same effect as !isWorking().
      Returns:
      true if failed, true otherwise
      See Also:
    • setFailed

      public void setFailed()
      Set this plugin as failed. This plugin will no more call the underlying plugin isAllowed methods.
      See Also:
    • isRequired

      public boolean isRequired()
      Check if this plugin is marked as required.
      Returns:
      true if is required; false otherwise
    • isSufficient

      public boolean isSufficient()
      Check if this plugin is marked as sufficient.
      Returns:
      true if is sufficient; false otherwise
    • isRequisite

      public boolean isRequisite()
      Check if this plugin is marked as requisite.
      Returns:
      true if is requisite; false otherwise
    • isOptional

      public boolean isOptional()
      Check if this plugin is marked as optional.
      Returns:
      true if is optional; false otherwise
    • hierarchyToString

      public String hierarchyToString()
      Print the entity hierarchy.
      Returns:
      the string containing this entity representation
    • colorToString

      protected String colorToString(String colorElement)
      Print the color element for this entity. Replace all occurrences of %color% in the input string by the current state color in the HTML HEX format.
      Parameters:
      colorElement - the string, possibly an HTML element, describing the color (can use %color%) to inject the true color of this entity state.
      Returns:
      the color element with filled color
    • infoToString

      protected String infoToString(String prefix)
      Print the basic information about this entity.
      Parameters:
      prefix - prepend this value to each line produced
      Returns:
      the string containing the information.
    • setupToString

      protected String setupToString(String prefix)
      Print the setup into a string.
      Parameters:
      prefix - prepend this value to each line produced
      Returns:
      the string representing the entity setup
    • targetsToString

      protected String targetsToString(String prefix)
      Print the targets for groups and projects into a string.
      Parameters:
      prefix - prepend this value to each line produced
      Returns:
      the string representing targeted the groups and projects