SwitchableSubjectMapper
.public class SwitchByKeySubjectPatternMapper extends java.lang.Object implements 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;
User
permissions, and create a Permissioning Rule
as described in the
documentation of the SwitchableSubjectMapper
interface.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 Mapmappings1 = new HashMap (); mappings1.put("/ABC.*", "-tier1"); mappings1.put("/DEF.*", "-tier2"); mappings1.put("/XYZ.*", "-tier2"); final Map mappings2 = new HashMap (); mappings2.put("/ABC.*", "-tier5"); mappings2.put("/DEF.*", "-tier6"); mappings2.put("/XYZ.*", "-tier6"); final Map mappings3 = new HashMap (); 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.
Account
field is key1
, subject mappings from the mappings1
set are applied, and therefore:
/ABC123
is mapped to /ABC123-tier1
/DEF123
is mapped to /DEF123-tier2
/XYZ123
is mapped to /XYZ123-tier2
Account
field is key2
, subject mappings from the mappings2
set are applied, and therefore:
/ABC123
is mapped to /ABC123-tier5
/DEF123
is mapped to /DEF123-tier6
/XYZ123
is mapped to /XYZ123-tier6
Account
field is key3
, subject mappings from the mappings3
set are applied, and therefore:
/ABC123
is mapped to /ABC123-tier3
/DEF123
is mapped to /DEF123-tier4
/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.
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:
DEFAULT_MAPPINGS
to the name of the key that you want to define as the default.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 MapconfigurationMap = new HashMap (); 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.
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).
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
CONFIGURATION
Deprecated.
Used in calls to
User.addSubjectMapping() as the key that identifies passed in mappings as configuration settings. |
static java.lang.String |
DEFAULT_MAPPINGS
Deprecated.
Used in calls to
User.addSubjectMapping() to identify the configuration setting for the default key mapping. |
Constructor and Description |
---|
SwitchByKeySubjectPatternMapper()
Deprecated.
|
Modifier and Type | Method and Description |
---|---|
java.lang.String |
mapSubject(java.lang.String subject)
Deprecated.
Called by the Permissioning Auth Module to map the passed in
subject using the current set of subject mappings. |
void |
setGlobalContext(GlobalContext globalContext)
Deprecated.
This method is a no-op as
SwitchByKeySubjectPatternMapper 's do not utilise data from the GlobalContext . |
boolean |
switchMappings(java.lang.String keyField,
java.util.Map<java.lang.String,java.lang.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 |
switchToDefaultMappings()
Deprecated.
Called by the Permissioning Auth Module to switch the current set of subject mappings to the default set.
|
void |
updateMappings(java.lang.String key,
java.util.Map<java.lang.String,java.lang.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.
|
public static final java.lang.String DEFAULT_MAPPINGS
User.addSubjectMapping()
to identify the configuration setting for the default key mapping.public static final java.lang.String CONFIGURATION
User.addSubjectMapping()
as the key that identifies passed in mappings as configuration settings.public SwitchByKeySubjectPatternMapper()
public boolean switchMappings(java.lang.String keyField, java.util.Map<java.lang.String,java.lang.String> fields)
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:
switchMappings
in interface SwitchableSubjectMapper
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.public void switchToDefaultMappings()
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
.
switchToDefaultMappings
in interface SwitchableSubjectMapper
public void setGlobalContext(GlobalContext globalContext)
SwitchByKeySubjectPatternMapper
's do not utilise data from the GlobalContext
.setGlobalContext
in interface SubjectMapper
globalContext
- public java.lang.String mapSubject(java.lang.String subject)
subject
using the current set of subject mappings.mapSubject
in interface SubjectMapper
subject
- the subject of the RTTP message received by Liberator.null
if a mapping was not found.public void updateMappings(java.lang.String key, java.util.Map<java.lang.String,java.lang.String> mappingsForKey)
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
).
updateMappings
in interface SubjectMapper
key
- that identifies the added set of mappings.mappingsForKey
- the mappings that are added for the key
identifier.Please send bug reports and comments to Caplin support