Class SwitchByKeySubjectPatternMapper

java.lang.Object
com.caplin.permissioning.SwitchByKeySubjectPatternMapper
All Implemented Interfaces:
SubjectMapper, SwitchableSubjectMapper

@Deprecated public class SwitchByKeySubjectPatternMapper extends Object implements SwitchableSubjectMapper
Deprecated.
See the deprecation warning in SwitchableSubjectMapper.

An implementation of the SwitchableSubjectMapper and SubjectMapper interfaces, this class switches the subject mappings that are being applied for a user when requested to do so by the client application.

To use SwitchByKeySubjectPatternMapper you must;

  • Configure Liberator, set User permissions, and create a Permissioning Rule as described in the documentation of the SwitchableSubjectMapper interface.
  • Add sets of subject mappings to SwitchByKeySubjectPatternMapper. These are the sets of subject mappings that SwitchByKeySubjectPatternMapper can apply when requested to do so by the client application.

Sets of subject mappings are added as part of a Permissioning transaction at the Permissioning DataSource. After subject mappings have been added, the client application can send a request to SwitchByKeySubjectPatternMapper to map subjects using any of the added sets.

The following example shows how three sets of subject mappings are added for three named keys.

        // create the three sets of mappings that will be used by the mapper
        final Map>String,String> mappings1 = new HashMap>String,String>();
        mappings1.put("/ABC.*", "-tier1");
        mappings1.put("/DEF.*", "-tier2");
        mappings1.put("/XYZ.*", "-tier2");
 
        final Map>String,String> mappings2 = new HashMap>String,String>();
        mappings2.put("/ABC.*", "-tier5");
        mappings2.put("/DEF.*", "-tier6");
        mappings2.put("/XYZ.*", "-tier6");
 
        final Map>String,String> mappings3 = new HashMap>String,String>();
        mappings3.put("/ABC.*", "-tier3");
        mappings3.put("/DEF.*", "-tier4");
 
 
        // apply the mapper and mappings to a User in a PermissioningDataSource transaction
        final PermissioningDataSource pds = getPdsReferenceFromSomewhere();
        pds.startUpdateTransaction();
          // select the user that you want to apply this mapper to
          final User user = pds.getUser("John");

          // configure the user to use a SwitchByKeySubjectPatternMapper 
          user.setSubjectMapper(SwitchByKeySubjectPatternMapper.class.getName());
 
          // add the three separate sets of subject mappings
          user.addSubjectMapping("key1", mappings1);
          user.addSubjectMapping("key2", mappings2);
          user.addSubjectMapping("key3", mappings3);
        pds.commitTransaction();
 

When the Permissioning Auth Module receives this transaction it calls updateMappings, passing in the subject mappings for each of the named keys. The SwitchByKeySubjectPatternMapper can now switch subject mappings when requested to do so by the client application.

For example, if the client application sends an RTTP message requesting a named set of subject mappings to be applied, and if the Account field of this message identifies the key for this set, then subjects are mapped as shown below.

  • If value of the Account field is key1, subject mappings from the mappings1 set are applied, and therefore:
    • subject /ABC123 is mapped to /ABC123-tier1
    • subject /DEF123 is mapped to /DEF123-tier2
    • subject /XYZ123 is mapped to /XYZ123-tier2
  • If value of the Account field is key2, subject mappings from the mappings2 set are applied, and therefore:
    • subject /ABC123 is mapped to /ABC123-tier5
    • subject /DEF123 is mapped to /DEF123-tier6
    • subject /XYZ123 is mapped to /XYZ123-tier6
  • If value of the Account field is key3, subject mappings from the mappings3 set are applied, and therefore:
    • subject /ABC123 is mapped to /ABC123-tier3
    • subject /DEF123 is mapped to /DEF123-tier4
    • subject /XYZ123 is not mapped as there is no pattern in the mappings3 set that matches /XYZ123

Note that it is the Permissioning Auth Module that calls the methods of SwitchByKeySubjectPatternMapper, and not the code that you write.

Specifying the default set of subject mappings (optional)

The Permissioning Auth Module calls switchToDefaultMappings() when the end user logs in, or if the currently applied set of subject mappings are removed while the user is logged in. After this method is called, SwitchByKeySubjectPatternMapper maps subjects using the default set of subject mappings (see mapSubject(java.lang.String). If a default set is not defined, then mapSubject() returns null when called, which indicates that the passed in subject has no mapping.

To define a default set of mappings:

  • Map the reserved work DEFAULT_MAPPINGS to the name of the key that you want to define as the default.
  • Add this mapping at the Pemrissioning DataSource as part of a Permissioning transaction, using the reserved word CONFIGURATION

The following code could be added to the example code shown above to specify that the subject mappings for key3 are to be used as the default of set of subject mappings.

          ...
          // set mappings3 as the default set of mappings by naming key3 as the default set in the configuration map
          final Map>String,String> configurationMap = new HashMap>String,String>();
          configurationMap.put(SwitchByKeySubjectPatternMapper.DEFAULT_MAPPINGS, "key3");
          user.addSubjectMapping(SwitchByKeySubjectPatternMapper.CONFIGURATION, configurationMap);
        pds.commitTransaction();
 
 

If the default set of mappings is removed, or if a non-existent set of mappings is defined as the default, SwitchByKeySubjectPatternMapper will not map any subjects by default. If the specified set of default mappings are then added later, the next call to switchToDefaultMappings() will make the specified set the default set.

Deploying the SwitchByKeySubjectPatternMapper to the Permissioning Auth Module

As SwitchByKeySubjectPatternMapper is included in the Permissioning Auth Module kit (it is in the permissioning-common-xxx.jar and the permissioning-auth-module-jar-with-dependencies-xxx.jar), you do not need to take any action to deploy it on the classpath of the Permissioning Auth Module (it is already there).

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Deprecated.
    Used in calls to User.addSubjectMapping() as the key that identifies passed in mappings as configuration settings.
    static final String
    Deprecated.
    Used in calls to User.addSubjectMapping() to identify the configuration setting for the default key mapping.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Deprecated.
     
  • Method Summary

    Modifier and Type
    Method
    Description
    mapSubject(String subject)
    Deprecated.
    Called by the Permissioning Auth Module to map the passed in subject using the current set of subject mappings.
    void
    Deprecated.
    This method is a no-op as SwitchByKeySubjectPatternMapper's do not utilise data from the GlobalContext.
    boolean
    switchMappings(String keyField, Map<String,String> fields)
    Deprecated.
    Called by the Permissioning Auth Module to switch the current set of subject mappings to the set requested by the client application.
    void
    Deprecated.
    Called by the Permissioning Auth Module to switch the current set of subject mappings to the default set.
    void
    updateMappings(String key, Map<String,String> mappingsForKey)
    Deprecated.
    Called by the Permissioning Auth Module to add the passed in set of subject mappings to any existing sets of subject mappings.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • DEFAULT_MAPPINGS

      public static final String DEFAULT_MAPPINGS
      Deprecated.
      Used in calls to User.addSubjectMapping() to identify the configuration setting for the default key mapping.
      See Also:
    • CONFIGURATION

      public static final String CONFIGURATION
      Deprecated.
      Used in calls to User.addSubjectMapping() as the key that identifies passed in mappings as configuration settings.
      See Also:
  • Constructor Details

    • SwitchByKeySubjectPatternMapper

      public SwitchByKeySubjectPatternMapper()
      Deprecated.
  • Method Details

    • switchMappings

      public boolean switchMappings(String keyField, Map<String,String> fields)
      Deprecated.

      Called by the Permissioning Auth Module to switch the current set of subject mappings to the set requested by the client application.

      The switch will only succeed if:

      • Subject mappings for the switch key have been added at the Permissioning Auth Module as part of a Permissioning transaction.
      • The end user is permitted to switch to the requested set of subject mappings.
      Specified by:
      switchMappings in interface SwitchableSubjectMapper
      Parameters:
      keyField - the name of the field that contains the switch key in the passed in fields Map.
      fields - the fields of the RTTP message that requested the switch.
      Returns:
      true if the switch was successfully, false otherwise.
    • switchToDefaultMappings

      public void switchToDefaultMappings()
      Deprecated.

      Called by the Permissioning Auth Module to switch the current set of subject mappings to the default set.

      If a default is not defined, then subjects will not be mapped until the client application requests a switch and the Permissioning Auth Module calls switchMappings.

      Specified by:
      switchToDefaultMappings in interface SwitchableSubjectMapper
    • setGlobalContext

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

      public String mapSubject(String subject)
      Deprecated.
      Called by the Permissioning Auth Module to map the passed in subject using the current set of subject mappings.
      Specified by:
      mapSubject in interface SubjectMapper
      Parameters:
      subject - the subject of the RTTP message received by Liberator.
      Returns:
      the modified subject if a mapping was found, or null if a mapping was not found.
    • updateMappings

      public void updateMappings(String key, Map<String,String> mappingsForKey)
      Deprecated.

      Called by the Permissioning Auth Module to add the passed in set of subject mappings to any existing sets of subject mappings.

      The Permissioning Auth Module calls this method when the Permissioning DataSource adds subject mappings as part of a Permissioning transaction. Each set is added independently of the other sets, and only one set can be used as the current set.

      If mappings already exist for the key passed to this method, then the new mappings are added to the existing mappings. If an added pattern mapping already exists for this key, then the new pattern mapping replaces the existing pattern mapping (much like the way that Map.put(pattern1, suffix1) overwrites previous mappings for pattern1).

      Specified by:
      updateMappings in interface SubjectMapper
      Parameters:
      key - that identifies the added set of mappings.
      mappingsForKey - the mappings that are added for the key identifier.