Interface SubjectMapper
- All Known Subinterfaces:
SwitchableSubjectMapper
- All Known Implementing Classes:
RegexSuffixSubjectMapper
,SwitchByKeySubjectPatternMapper
The SubjectMapper interface must be implemented by any custom SubjectMapper
class that
you write.
Subject mapping allows the subject of an RTTP message to be modified by Liberator. Subject mapping is transparent to the user and could be used, for example, to provide preferential data to selected users (see Permissiong 6.0: Permissioning Overview And Concepts for further details).
Subjects are modified for a User
in the Permissioning Auth Module from mappings that you set on the
User
in the PermissioningDataSource
. For example the subject "FX/USDGBR" could be changed to
"FX/USDGBR-tier2", so that the end user is shown tier 2 prices when they request the "FX/USDGBR" instrument.
If a SubjectMapper modifies the subject of an RTTP message, the user must have permission for the modified subject and not the original subject.
A default SubjectMapper
is provided with the Permissioning software that allows one subject mapping to be added for each User
, and
a RegexSuffixSubjectMapper
is provided that allows multiple subject mappings to be added for each User
.
To set the RegexSuffixSubjectMapper
class as the SubjectMapper
for a User
, call User.setSubjectMapper()
,
passing in the fully qualified class name com.caplin.permissionnig.RegexSuffixSubjectMapper
.
If you want to provide customized mapping logic, then you must create a custom SubjectMapper
. To create a custom subject mapper you must:
- Write a custom Java class that implements this
SubjectMapper
interface. - Compile and deploy the custom
SubjectMapper
Java class to the Permissioning Auth Module and configure Liberator to use the compiled code. - Call
User.setSubjectMapper()
so that subjects will be mapped by the customSubjectMapper
for this user.
Because custom SubjectMapper
classes are dynamically loaded and instantiated, all such classes must provide a public
default (zero argument) constructor, or let the compiler create the default constructor.
The document Permissioning 6.0: How To Create A Permissioning Adapter provides an example of a custom
SubjectMapper
class that implements the SubjectMapper
interface, and describes how to deploy the class and
configure Liberator.
SubjectMapper
will never be called concurrently with any other SubjectMapper
method and no
GlobalContext
method will ever be called concurrently with a SubjectMapper
method. Therefore there are no concurrency issues
when implementing a custom SubjectMapper
.
-
Method Summary
Modifier and TypeMethodDescriptionmapSubject
(String subject) This method is called by the Permissioning Auth Module when Liberator receives an RTTP message from the client application.void
setGlobalContext
(GlobalContext globalContext) This method is called by the Permissioning Auth Module when theGlobalContext
is updated at thePermissioningDataSource
as part of a transaction.void
updateMappings
(String key, Map<String, String> updateMap) This method is called by the Permissioning Auth Module when subject mappings are received from thePermissioningDataSource
.
-
Method Details
-
updateMappings
This method is called by the Permissioning Auth Module when subject mappings are received from the
PermissioningDataSource
. The method is passed a key and the subject mappings for that key.Subject mappings are set in the
PermissioningDataSource
using theUser.addSubjectMappings()
method and sent to the Permissioning Auth Module as part of a transaction.The
updateMappings
method of this interface has no return value but allows you to store the received keys and subject mappings, and to make them available tomapSubject()
. Each subject mapping is a name-value pair that typically consists of a subject pattern and subject suffix.Keys can be used by
mapSubject()
to limit the scope of a subject mapping. For example if a key is set to "FX", thenmapSubject()
could limit the scope of the associated subject mappings to FX instruments.- Parameters:
key
- the key associated with the subject mappings at the Permissioning DataSource.updateMap
- the subject mappings received from the Permissioning DataSource.
-
setGlobalContext
This method is called by the Permissioning Auth Module when the
GlobalContext
is updated at thePermissioningDataSource
as part of a transaction. The method is passed the currentGlobalContext
and includes the latest update.If the
SubjectMapper
needs to accessGlobalContext
data to map a subject, this method must store a reference to the currentGlobalContext
and make it available tomapsubject()
. If theSubjectMapper
does not need to accessGlobalContext
data, this method can simply return.The
setGlobalContext()
method can be called at any time in the lifecycle of theSubjectMapper
, and could be called several times.- Parameters:
globalContext
- the currentGlobalContext
object.
-
mapSubject
This method is called by the Permissioning Auth Module when Liberator receives an RTTP message from the client application. The subject passed to this method is the subject of the RTTP message received by Liberator, and the method must determine whether or not the subject is to be mapped.
If the subject is to be mapped, return the modified subject to Liberator as a string. Liberator will use the modified subject to request data from the DataSource and to check user permissions.
If the subject is not to be mapped, return null. In this case Liberator will use the original subject of the RTTP message to request data from the DataSource and to check user permissions.
To map a subject, this method must be able to access the subject mappings and
GlobalContext
that the Permissioning Auth Module passed toupdateMappings()
andsetGlobalContext()
.- Parameters:
subject
- the subject of the original RTTP message that was received by Liberator.- Returns:
- the modified subject if a mapping was found, or
null
if a mapping was not found.
-