Class PermissioningDataSource
When a PermissioningDataSource
is constructed it must be
supplied with a DataSource
object. The DataSource
object allows the PermissioningDataSource
to communicate with
Liberator using the DataSource protocol.
-
Constructor Summary
ConstructorDescriptionPermissioningDataSource
(com.caplin.datasource.DataSource dataSource, Role role) Creates a newPermissioningDataSource
having a given role (master or slave) and an associatedDataSource
instance that allows thePermissioningDataSource
to communicate with Liberator. -
Method Summary
Modifier and TypeMethodDescriptionboolean
actionExists
(String action) A convenience method that will tell you if a rule for anaction
has been sent to Liberator.void
Finishes a transaction and sends the data for that transaction to the remote Liberator.void
createActionRefRule
(String subjectNameMatch, String permissionNameSpace, String actionRef, String productRef) void
createActionRefRule
(String subjectNameMatch, Map<String, String> fieldMatchCriteria, String permissionNameSpace, String actionRef, String productRef) void
createActionRule
(String subjectNameMatch, String permissionNameSpace, String action, String productRef) void
createActionRule
(String subjectNameMatch, Map<String, String> fieldMatchCriteria, String permissionNameSpace, String action, String productRef) createGroup
(String name) Creates a newGroup
in thisPermissioningDataSource
.createUser
(String name) Creates a new,KeyMaster
authenticatedUser
that is known to thisPermissioningDataSource
.createUser
(String name, String password) Creates a new, text password authenticatedUser
that is known to thisPermissioningDataSource
.dump()
Prints structure of cached permission data, used for debuggingRetrieve an existingGroup
that is already known to thisPermissioningDataSource
.getName()
Gets the name of thePermissioningDataSource
.Retrieve an existingUser
that is already known to thisPermissioningDataSource
.boolean
isMaster()
Indicates the role of thePermissioningDataSource
.boolean
Determine whether an underlying transaction is already in progress - use before invokingstartTransaction
to guard against aTransactionInProgressException
void
removeGlobalContextData
(String identifier) Removes from theGlobalContext
, the data identified byidentifier
.void
removeGroup
(Group group) Removes a given group and implicitly removes the group from all groups of which it is a member.void
removeUser
(User user) Removes a givenUser
and implicitly removes theUser
from anyGroup
s of which it is a member.void
Reverts thePermissioningDataSource
data to its state before the current transaction was started.void
setUserRequestListener
(UserRequestListener listener) Registers a UserRequestListener to be called back when a user container is requested or discarded.void
Starts an image transaction, which should be used to set the permissioning data.void
startImageTransaction
(boolean rollbackSupported) Starts an image transaction, which should be used to set the permissioning data.void
Starts an update transaction, which should be used to make changes to the existing permissioning data.void
startUpdateTransaction
(boolean rollbackSupported) Starts an update transaction, which should be used to make changes to the existing permissioning data.toString()
Returns a string that describes thisPermissioningDataSource
, including its master/slave role and the message protocol that it uses.void
updateGlobalContext
(String identifier, Map<String, String> data) Addsdata
to theGlobalContext
.
-
Constructor Details
-
PermissioningDataSource
Creates a newPermissioningDataSource
having a given role (master or slave) and an associatedDataSource
instance that allows thePermissioningDataSource
to communicate with Liberator.- Parameters:
dataSource
- TheDataSource
used to communicate with the Liberator.role
- TheRole
can be set to either master or slave. There can only be one master but there can be zero or more slaves. If the role is SLAVE, the slave name must be set by giving theDataSource
the--permission.rolename
argument when theDataSource
is instantiated. For more information on roles, see the documents Caplin Permissioning: Permissioning Overview and Concepts and Caplin Permissioning: How To Create A Permissioning DataSource Adapter. The second document contains example code that shows how to construct both master and slavePermissioningDataSources
.
-
-
Method Details
-
startUpdateTransaction
Starts an update transaction, which should be used to make changes to the existing permissioning data. An update transaction is a transaction in which one can make changes to the existing permissioning data - a relative change. If one wishes to reset all of the permissioning data and provide a new absolute set of permissioning data, one should start an
image
transaction using thestartImageTransaction()
method.Transactions must be used in order to atomically send a set of changes to the permissioning data to the remote Liberator. A transaction must be started in order to create, remove or mutate
Note: by default this will enable/disable rollback based on the global rollbackEnalbed flag.Users
,Groups
orRules
.Note: Only one transaction can be in progress at any time.
- Throws:
TransactionInProgressException
- if a transaction is already in progress.
-
startUpdateTransaction
Starts an update transaction, which should be used to make changes to the existing permissioning data. An update transaction is a transaction in which one can make changes to the existing permissioning data - a relative change. If one wishes to reset all of the permissioning data and provide a new absolute set of permissioning data, one should start an
image
transaction using thestartImageTransaction()
method.Transactions must be used in order to atomically send a set of changes to the permissioning data to the remote Liberator. A transaction must be started in order to create, remove or mutate
Users
,Groups
orRules
.Note: Only one transaction can be in progress at any time.
- Parameters:
rollbackSupported
- if this is specified to true changes will be tracked and rollback will be permitted. If not changes will not be tracked and a call to commit will trigger a commit instead. The primary reason for disabling rollback is to remove the impact on performance in environments where it is known that rollback functionality will not be needed.- Throws:
TransactionInProgressException
- if a transaction is already in progress.
-
startImageTransaction
Starts an image transaction, which should be used to set the permissioning data. After an
image
transaction completes, only data that was added in that transaction will be present in the system. All data that was in the system before is removed, unless it is re-added in the image transaction. If one wishes to merely change the existing permissioning data one should use anupdate
transaction, which is created using thestartUpdateTransaction()
method.Transactions must be used in order to automatically send a set of changes to the permissioning data to the remote Permissioning Auth Module. A transaction must be started in order to create, remove or mutate
Note: by default this will enable/disable rollback based on the global rollbackEnalbed flag.Users
,Groups
orRules
.Note: Only one transaction can be in progress at any time.
- Throws:
TransactionInProgressException
- if a transaction is already in progress.
-
startImageTransaction
Starts an image transaction, which should be used to set the permissioning data. After an
image
transaction completes, only data that was added in that transaction will be present in the system. All data that was in the system before is removed, unless it is re-added in the image transaction. If one wishes to merely change the existing permissioning data one should use anupdate
transaction, which is created using thestartUpdateTransaction()
method.Transactions must be used in order to automatically send a set of changes to the permissioning data to the remote Permissioning Auth Module. A transaction must be started in order to create, remove or mutate
Users
,Groups
orRules
.Note: Only one transaction can be in progress at any time.
- Parameters:
rollbackSupported
- if this is specified to true changes will be tracked and rollback will be permitted. If not changes will not be tracked and a call to commit will trigger a commit instead. The primary reason for disabling rollback is to remove the impact on performance in environments where it is known that rollback functionality will not be needed.- Throws:
TransactionInProgressException
- if a transaction is already in progress.
-
commitTransaction
Finishes a transaction and sends the data for that transaction to the remote Liberator. This method is used to commit both types of transaction;image
transactions andupdate
transactions. Invoke this method after creating, removing or mutatingUsers
,Groups
orRules
in order to atomically send all the changes to the Liberator- Throws:
NoTransactionInProgressException
- if there is no in-progress transaction to commit.
-
rollbackTransaction
public void rollbackTransaction()Reverts the
PermissioningDataSource
data to its state before the current transaction was started. This can be used to effectively cancel all the changes made in both types of transaction.WARNING: During rollback, all permissioning objects within the
PermissioningDataSource
are replaced with a copy of the objects from when the transaction was started. This means that if you are holding any permissioning objects you should throw them away and retrieve new objects usinggetGroup(String)
andgetUser(String)
. If you try to use the old objects they will no longer be valid and throw anIllegalStateException
.- Throws:
NoTransactionInProgressException
- if there is no in-progress transaction to commit.
-
isTransactionInProgress
public boolean isTransactionInProgress()Determine whether an underlying transaction is already in progress - use before invokingstartTransaction
to guard against aTransactionInProgressException
- Returns:
- true if an underlying transaction is already in progress. Otherwise returns false.
-
createUser
Creates a new,KeyMaster
authenticatedUser
that is known to thisPermissioningDataSource
. The createdUser
will be sent to the Liberator upon the committing the current transaction. TheUser
can only be removed from thisPermissioningDataSource
by callingremoveUser(User)
after which theUser
object is useless (you must create it again if you wish to re-add theUser
).- Parameters:
name
- the newUser
's login name.- Returns:
- the newly created
User
. - Throws:
NoTransactionInProgressException
- if this method is called outside the scope of a transaction.
-
createUser
Creates a new, text password authenticatedUser
that is known to thisPermissioningDataSource
. The createdUser
will be sent to the Liberator upon the committing the current transaction. TheUser
can only be removed from thisPermissioningDataSource
by callingremoveUser(User)
after which theUser
object is useless (you must create it again if you wish to re-add theUser
).Note: Only a master
PermissioningDataSource
can set theUser
's password.- Parameters:
name
- the newUser
's login name.password
- the newUser
's login password.- Returns:
- the newly created
User
. - Throws:
NoTransactionInProgressException
- if this method is called outside the scope of a transaction.
-
createGroup
Creates a new
Group
in thisPermissioningDataSource
. TheGroup
is sent to the Liberator when the current transaction is committed.To remove (detach) a
Group
from aPermissioningDataSource
, callremoveGroup(Group)
. If you want to re-use a group after it has been removed, you must callcreateGroup
again to re-create theGroup
.This method must be called as part of a transaction.
- Parameters:
name
- the name of the newGroup
.- Returns:
- The created
Group
- Throws:
NoTransactionInProgressException
- if this method is called outside the scope of a transaction.
-
getUser
Retrieve an existingUser
that is already known to thisPermissioningDataSource
.- Parameters:
userName
- The name of the user for which the permissioning data will be returned.- Returns:
- A
User
object containing permissioning data foruserName
.null
if theUser
userName
does not exist.
-
getGroup
Retrieve an existingGroup
that is already known to thisPermissioningDataSource
.- Parameters:
groupName
- The name of the group for which the permissioning data will be returned.- Returns:
- A
Group
object containing permissioning data forgroupName
.null
ifGroup
groupName
does not exist.
-
removeUser
Removes a givenUser
and implicitly removes theUser
from anyGroup
s of which it is a member. Upon commit of this transaction, the Liberator is notified of the deletion. If theUser
is logged in, they will be ejected. TheUser
will not be able to log in to the Liberator.- Parameters:
user
- theUser
to be removed.- Throws:
NoTransactionInProgressException
- if this method is called outside the scope of a transaction.
-
removeGroup
Removes a given group and implicitly removes the group from all groups of which it is a member. Furthermore, any members of the group being removed remain on the system but are no longer members of this group.
Upon commit of this transaction, the Liberator is notified of the deletion and re-checks all permissions for affected
Users
.- Parameters:
group
- theGroup
to be removed- Throws:
NoTransactionInProgressException
- if this method is called outside the scope of a transaction.
-
createActionRefRule
public void createActionRefRule(String subjectNameMatch, String permissionNameSpace, String actionRef, String productRef) Creates a new Rule for an
action
on aproduct
. Call this method if a field in the RTTP message contains theaction
for thisRule
.When a
User
attempts to trade aproduct
, the Permissioning Auth Module inspects the content of the received RTTP message and tries to match the message subject with one or moreRules
. If aRule
matches the message subject, the permission for theaction
specified by theRule
determines whether or not the request is allowed or denied.Note: Only a master
PermissioningDataSource
can create aRule
.This method must be called as part of an image transaction (
startImageTransaction()
). TheRule
is sent to the Liberator when the transaction is committed.- Parameters:
subjectNameMatch
- A regular expression that is used to match the subject of the RTTP message. The regular expression can contain the substitution tokens%u
or%U
. When a subject is being matched to aRule
, the Permissioning Auth Module replaces%u
with the username of the logged inUser
, and%U
with the allocated session name. To match against the literal value of a token, escape the token with '\' (as in\%u
).permissionNameSpace
- The namespace of the permission that either allows or denies theaction
.actionRef
- Permission for theaction
specified in this RTTP message field is checked to see if the message is allowed or denied.productRef
- Permission for theproduct
specified in this RTTP message field is checked to see if the message is allowed or denied.- Throws:
NoTransactionInProgressException
- if this method is called outside the scope of a transaction.- See Also:
-
createActionRefRule
public void createActionRefRule(String subjectNameMatch, Map<String, String> fieldMatchCriteria, String permissionNameSpace, String actionRef, String productRef) Creates a new Rule for an
action
on aproduct
. Call this method if a field in the RTTP message contains theaction
for thisRule
, and if theRule
must match other known message fields and values.When a
User
attempts to trade aproduct
, the Permissioning Auth Module inspects the content of the received RTTP message and tries to match the message subject with one or moreRules
. If aRule
matches the message subject, the permission for theaction
specified by theRule
determines whether or not the request is allowed or denied.Note: Only a master
PermissioningDataSource
can create aRule
.This method must be called as part of an image transaction (
startImageTransaction()
). TheRule
is sent to the Liberator when the transaction is committed.- Parameters:
subjectNameMatch
- A regular expression that is used to match the subject of the RTTP message. The regular expression can contain the substitution tokens%u
or%U
. When a subject is being matched to aRule
, the Permissioning Auth Module replaces%u
with the username of the logged inUser
, and%U
with the allocated session name. To match against the literal value of a token, escape the token with '\' (as in\%u
).fieldMatchCriteria
- A map of RTTP message fields and values. TheRule
will only match the message if the message contains these fields and values.The fieldMatchCriteria can contain some special values as detailed below:
Special Field Name Description *APPLICATION_ID Match the users StreamLink Application Id against the regular expression given as the value. *KEYMASTER_TOKEN:<token> Match the users KeyMaster extra parameters token against the regular expression given as the value.
For example given a field of *KEYMASTER_TOKEN:TRADING and a value of TRUE, then the rule would only fire if the KeyMaster password token contained an extra data parameter for TRADING=TRUE.
permissionNameSpace
- The namespace of the permission that either allows or denies theaction
.actionRef
- Permission for theaction
specified in this RTTP message field is checked to see if the message is allowed or denied.productRef
- Permission for theproduct
specified in this RTTP message field is checked to see if the message is allowed or denied.- Throws:
NoTransactionInProgressException
- if this method is called outside the scope of a transaction.- See Also:
-
createActionRule
public void createActionRule(String subjectNameMatch, String permissionNameSpace, String action, String productRef) Creates a new Rule for an
action
on aproduct
. Call this method if you want to pass in theaction
as a parameter.When a
User
attempts to trade aproduct
, the Permissioning Auth Module inspects the content of the received RTTP message and tries to match the message subject with thesubjectNameMatch
of one or moreRules
. If aRule
created with anaction
matches the message subject, the permission for theaction
specified by theRule
determines whether or not the message is allowed or denied.Note: Only a master
PermissioningDataSource
can create aRule
.This method must be called as part of an image transaction (
startImageTransaction()
). TheRule
is sent to the Liberator when the transaction is committed.- Parameters:
subjectNameMatch
- A regular expression that is used to match the subject of the RTTP message. The regular expression can contain the substitution tokens%u
or%U
. When a subject is being matched to aRule
, the Permissioning Auth Module replaces%u
with the username of the logged inUser
, and%U
with the allocated session name. To match against the literal value of a token, escape the token with '\' (as in\%u
).permissionNameSpace
- The namespace of the permission that either allows or denies theaction
.action
- permission for thisaction
is checked to see if the message is allowed or denied.productRef
- permission for theproduct
specified in this RTTP message field is checked to see if the message is allowed or denied.- Throws:
NoTransactionInProgressException
- if this method is called outside the scope of a transaction.- See Also:
-
createActionRule
public void createActionRule(String subjectNameMatch, Map<String, String> fieldMatchCriteria, String permissionNameSpace, String action, String productRef) Creates a new Rule for an
action
on aproduct
. Call this method if you want to pass in theaction
as a parameter, and if theRule
must match known RTTP message fields and values.When a
User
attempts to trade aproduct
, the Permissioning Auth Module inspects the content of the received RTTP message and tries to match the message subject with thesubjectNameMatch
of one or moreRules
. If aRule
created with anaction
matches the message subject, the permission for theaction
specified by theRule
determines whether or not the message is allowed or denied.Note: Only a master
PermissioningDataSource
can create aRule
.This method must be called as part of an image transaction (
startImageTransaction()
). TheRule
is sent to the Liberator when the transaction is committed.- Parameters:
subjectNameMatch
- A regular expression that is used to match the subject of the RTTP message. The regular expression can contain the substitution tokens%u
or%U
. When a subject is being matched to aRule
, the Permissioning Auth Module replaces%u
with the username of the logged inUser
, and%U
with the allocated session name. To match against the literal value of a token, escape the token with '\' (as in\%u
).fieldMatchCriteria
- A map of RTTP message fields and values. TheRule
will only match the message if the message contains these fields and values.The fieldMatchCriteria can contain some special values as detailed below:
Special Field Name Description *APPLICATION_ID Match the users StreamLink Application Id against the regular expression given as the value. *KEYMASTER_TOKEN:<token> Match the users KeyMaster extra parameters token against the regular expression given as the value.
For example given a field of *KEYMASTER_TOKEN:TRADING and a value of TRUE, then the rule would only fire if the KeyMaster password token contained an extra data parameter for TRADING=TRUE.
permissionNameSpace
- The namespace of the permission that either allows or denies theaction
.action
- permission for thisaction
is checked to see if the message is allowed or denied.productRef
- permission for theproduct
specified in this RTTP message field is checked to see if the message is allowed or denied.- Throws:
NoTransactionInProgressException
- if this method is called outside the scope of a transaction.- See Also:
-
actionExists
A convenience method that will tell you if a rule for anaction
has been sent to Liberator. You send anaction
to Liberator when you send the rule that identifies theaction
.- Parameters:
action
- Theaction
that you want to check.- Returns:
true
if the rule exists, otherwisefalse
.
-
getName
Gets the name of thePermissioningDataSource
. A name is assigned when thepermission.rolename
argument is set on theDataSource
.- Returns:
- the name of the
PermissioningDataSource
.
-
isMaster
public boolean isMaster()Indicates the role of thePermissioningDataSource
.- Returns:
- true if the role is master, or false if the role is slave.
- Throws:
NullPointerException
- if the role of thePermissioningDataSource
has not been set.
-
toString
Returns a string that describes thisPermissioningDataSource
, including its master/slave role and the message protocol that it uses. -
dump
Prints structure of cached permission data, used for debugging- Returns:
- a string containing the formatted cached data
-
updateGlobalContext
Adds
data
to theGlobalContext
. This method must be called as part of an image or update transaction, and the request to add thedata
andidentifier
is sent to Liberator when the transaction is committed.Note that unlike other permissioning data, an image transaction does not remove
GlobalContext
data that was added in previous transactions (seestartImageTransaction()
).To remove data from the
GlobalContext
, pass theidentifier
for that data toremoveGlobalContextData()
. BecauseremoveGlobalContextData()
removes all data for anidentifier
, it is recommended that twoPermissioningDataSources
do not add or remove data for the sameidentifier
.- Parameters:
identifier
- AString
that uniquely identifies data in theGlobalContext
.data
- AMap
of key-value pairs.
-
removeGlobalContextData
Removes from theGlobalContext
, the data identified byidentifier
. This method must be called as part of an image or update transaction. The signal to remove the data is sent to Liberator when the transaction is committed.Note that this method removes all data for this
identifier
, including any data that was added by anotherPermissioningDataSource
(seeupdateGlobalContext()
).- Parameters:
identifier
- AString
that uniquely identifies the data in theGlobalContext
.
-
setUserRequestListener
Registers a UserRequestListener to be called back when a user container is requested or discarded. This can be used to add users to the store on demand. The datasource response to the request is delayed until the callback returns. All callbacks will occur synchronously on a single thread. Setting the value to null removes the listener.- Parameters:
listener
- a listener for the request and discard events.
-