Class RegexSuffixSubjectMapper

java.lang.Object
com.caplin.permissioning.RegexSuffixSubjectMapper
All Implemented Interfaces:
SubjectMapper

public class RegexSuffixSubjectMapper extends Object implements SubjectMapper

This implementation of the SubjectMapper interface maps subjects in the same manner as the default SubjectMapper (see the section on Mapping Logic, below), but unlike the default SubjectMapper it permits multiple mappings to be added to it.

To use this SubjectMapper you must call User.setSubjectMapper, passing in the String value com.caplin.permissioning.RegexSuffixSubjectMapper (this class' fully qualified name).

Data Passed to RegexSuffixSubjectMapper

To pass mapping data to instances of this class you must use the User.addSubjectMapping method, just as you would for any other custom SubjectMapper implementation.

The subject mappings that are passed into the mapper will have been aggregated by their identifier when they are added on the User. Subsequently, for a given identifier, the mappings for keys passed in earlier to User.addSubjectMapping are overwritten by mappings with duplicate keys that are passed in later.

The identifier is not used for mapping purposes: it is only used for the purpose of identifying mappings for the sake of overwriting older mappings with newer mappings and removal of mappings by key (which can be performed by calling methods on the User).

Mapping Logic

The mapSubject(String) method maps an RTTP subject if the subject passed to it matches one of the patterns (one of the keys) in the maps that have been passed to updateMappings (which receives the data that is passed in to User.addSubjectMapping). If a match is found, the value that the matching pattern maps to in the stored mappings is appended to the passed in subject to produce the subject that it is mapped to. If no matching pattern is found, this SubjectMapper returns null to indicate the passed in subject is not mapped.

When mapSubject is called, the order that the mappings are checked against the passed in subject is not predictable. You should not count on the order that you add the mappings to be the order that they are checked for a match.

  • Constructor Details

    • RegexSuffixSubjectMapper

      public RegexSuffixSubjectMapper()
  • Method Details

    • mapSubject

      public String mapSubject(String subject)
      You do not call this method directly; it is called in the Permissioning Auth Module to map objects each time a new RTTP object is requested or contributed to. The behaviour of this method (how it maps the subject passed in) is described in the description at the top of this class' documentation.
      Specified by:
      mapSubject in interface SubjectMapper
      Parameters:
      subject - the subject to be mapped
      Returns:
      the subject that the passed in subject is mapped to, or null is this SubjectMapper does not map the passed in subject
    • setGlobalContext

      public void setGlobalContext(GlobalContext globalContext)
      This method is a no-op as RegexSuffixSubjectMapper's do not utilise data from the GlobalContext.
      Specified by:
      setGlobalContext in interface SubjectMapper
      Parameters:
      globalContext -
    • updateMappings

      public void updateMappings(String identifier, Map<String,String> updateMap)

      You do not call this method directly; it is called when you invoke User.addSubjectMapping(String, Map) on a User that is using this type of SubjectMapper class.

      Specified by:
      updateMappings in interface SubjectMapper
      Parameters:
      identifier - the identifier used to store the updateMap mappings .
      updateMap - The keys from the mappings will be used to create regexp patterns and the values they map to will be used as the mapped subjects' suffixes when a regexp matches the subject passed in to mapSubject.
      See Also:
    • toString

      public String toString()
      Overrides:
      toString in class Object