Interface GlobalContext
-
- All Known Implementing Classes:
DefaultGlobalContext
public interface GlobalContext
A custom
SubjectMapper
can call one of theget()
methods of this interface to access data that is common all subject mappers. TheDefaultGlobalContext
class implements this interface and is deployed at the Permissioning Auth Module.A
PermissioningDataSource
adds data to theGlobalContext
by callingupdateGlobalContext()
as part of a transaction, and a reference to theGlobalContext
is passed to aSubjectMapper
when theSubjectMapper
is created. This allows a customSubjectMapper
to map subjects based onGlobalContext
data, and not just on subject mappings defined for theUser
.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 theGlobalContext
than to the subject mappings of everyUser
.You can also write a custom class that implements the
GlobalContext
interface, or extend theDefaultGlobalContext
to provide additional methods that a customSubjectMapper
can call. For example, a custom implementation ofGlobalContext
could provide complex objects that would otherwise require multipleget()
calls to theDefaultGlobalContext
. 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 thePermissioningDataSource
, as thePermissioningDataSource
never loads theGlobalContext
.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 theDefaultGlobalContext
or a customGlobalContext
, and it is shared by everyPermissioningDataSource
. Therefore if you have more than onePermissioningDataSource
, make sure they do not overwrite each other's data.Thread Safety: Methods of the
GlobalContext
will never be called concurrently with anySubjectMapper
method, and noGlobalContext
method will ever be called concurrently with anotherGlobalContext
method. Therefore there are no concurrency issues when implementing a customGlobalContext
.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description java.util.Map<java.lang.String,java.lang.String>
get(java.lang.String identifier)
Returns theMap
of key-value pairs that are saved for the passed inidentifier
.java.lang.String
get(java.lang.String identifier, java.lang.String key)
Returns the value that is saved for the passed inidentifier
andkey
.void
remove(java.lang.String identifier)
Removes from theGlobalContext
, the passed inidentifier
and theMap
of key-value pairs for thatidentifier
.void
update(java.lang.String identifier, java.util.Map<java.lang.String,java.lang.String> data)
Saves the passed inidentifier
anddata
, and makes thedata
available to theget()
methods of this interface.
-
-
-
Method Detail
-
update
void update(java.lang.String identifier, java.util.Map<java.lang.String,java.lang.String> data)
Saves the passed in
identifier
anddata
, and makes thedata
available to theget()
methods of this interface.The method is called by the Permissioning Auth Module when data for the
GlobalContext
is received from aPermissioningDataSource
. APermissioningDataSource
sends theidentifier
anddata
to the Permissioning Auth Module when it callsupdateGlobalContext()
as part of a transaction.- Parameters:
identifier
- AString
that identifies the passed indata
.data
- aMap
of key-value pairs for the passed inidentifier
.
-
get
java.util.Map<java.lang.String,java.lang.String> get(java.lang.String identifier)
Returns the
Map
of key-value pairs that are saved for the passed inidentifier
. This method is typically called by themapSubject()
method of a customSubjectMapper
.- Parameters:
identifier
- aString
that identifies theMap
to be returned.- Returns:
- the
Map
of key-value pairs for the passed inidentifier
, ornull
if noMap
has been saved for thisidentifier
.
-
get
java.lang.String get(java.lang.String identifier, java.lang.String key)
Returns the value that is saved for the passed in
identifier
andkey
. 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 returnedMap
of key-value pairs.- Parameters:
identifier
- AString
that identifies theMap
of key-value pairs.key
- Akey
that identifies the value to be returned.- Returns:
- the value that is saved for the passed in
identifier
andkey
, ornull
if no value has been saved for thisidentifier
andkey
.
-
remove
void remove(java.lang.String identifier)
Removes from the
GlobalContext
, the passed inidentifier
and theMap
of key-value pairs for thatidentifier
. This method is called by the Permissioning Auth Module when aPermissioningDataSource
callsremoveGlobalContextData()
as part of a transaction.The method does not remove any data from the
GlobalContext
if there is noMap
for thisidentifier
.- Parameters:
identifier
- AString
that identifies theMap
to be removed.
-
-