Interface GlobalContext
- All Known Implementing Classes:
DefaultGlobalContext
SubjectMapper can call one of the get() methods
of this interface to access data that is common all subject mappers. The
DefaultGlobalContext class implements this interface and is
deployed at the Permissioning Auth Module.
A PermissioningDataSource adds data to the
GlobalContext by calling updateGlobalContext() as part of a transaction, and a reference to the GlobalContext is passed to a
SubjectMapper when the SubjectMapper is created. This allows a custom SubjectMapper
to map subjects based on GlobalContext data, and not just on subject mappings defined for the
User.
For example, if a custom SubjectMapper uses FX rates to map a subject, it is a more efficient use of
memory and bandwidth to add these rates to the GlobalContext than to the subject mappings of every
User.
You can also write a custom class that implements the GlobalContext interface, or extend the
DefaultGlobalContext to provide additional methods that a custom SubjectMapper can call. For
example, a custom implementation of GlobalContext could provide complex objects that would otherwise
require multiple get() calls to the DefaultGlobalContext. Another example is a custom
implementation that provides the same complex object to several subject mappers, reducing the processing required by
each.
If you write a custom GlobalContext, the class must be available on a classpath of the Permissioning
Auth Module. It does not need to be deployed on a classpath of the PermissioningDataSource, as the
PermissioningDataSource never loads the GlobalContext.
The document Permissioning 6.0: How To Create A Permissioning Adapter describes how to write, deploy, and
configure a custom GlobalContext, and is included in the Permissioning DataSource kit.
The Global Context and Multiple Permissioning DataSources
Note that there is only one GlobalContext at the Permissioning Auth Module, either the
DefaultGlobalContext or a custom GlobalContext, and it is shared by every
PermissioningDataSource. Therefore if you have more than one PermissioningDataSource, make sure
they do not overwrite each other's data.
Thread Safety: Methods of the GlobalContext will never be called concurrently with
any SubjectMapper method, and no GlobalContext method will ever be called concurrently with
another GlobalContext method. Therefore there are no concurrency issues when implementing a custom
GlobalContext.
-
Method Summary
Modifier and TypeMethodDescriptionReturns theMapof key-value pairs that are saved for the passed inidentifier.Returns the value that is saved for the passed inidentifierandkey.voidRemoves from theGlobalContext, the passed inidentifierand theMapof key-value pairs for thatidentifier.voidSaves the passed inidentifieranddata, and makes thedataavailable to theget()methods of this interface.
-
Method Details
-
update
Saves the passed inidentifieranddata, and makes thedataavailable to theget()methods of this interface.The method is called by the Permissioning Auth Module when data for the
GlobalContextis received from aPermissioningDataSource. APermissioningDataSourcesends theidentifieranddatato the Permissioning Auth Module when it callsupdateGlobalContext()as part of a transaction.- Parameters:
identifier- AStringthat identifies the passed indata.data- aMapof key-value pairs for the passed inidentifier.
-
get
Returns theMapof key-value pairs that are saved for the passed inidentifier. This method is typically called by themapSubject()method of a customSubjectMapper.- Parameters:
identifier- aStringthat identifies theMapto be returned.- Returns:
- the
Mapof key-value pairs for the passed inidentifier, ornullif noMaphas been saved for thisidentifier.
-
get
Returns the value that is saved for the passed inidentifierandkey. This method is typically called by themapSubject()method of a customSubjectMapper.A call to this method is equivalent to calling
get(String), and then callingget(key)on the returnedMapof key-value pairs.- Parameters:
identifier- AStringthat identifies theMapof key-value pairs.key- Akeythat identifies the value to be returned.- Returns:
- the value that is saved for the passed in
identifierandkey, ornullif no value has been saved for thisidentifierandkey.
-
remove
Removes from theGlobalContext, the passed inidentifierand theMapof key-value pairs for thatidentifier. This method is called by the Permissioning Auth Module when aPermissioningDataSourcecallsremoveGlobalContextData()as part of a transaction.The method does not remove any data from the
GlobalContextif there is noMapfor thisidentifier.- Parameters:
identifier- AStringthat identifies theMapto be removed.
-