Class PermissioningDataSource
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
ConstructorsConstructorDescriptionPermissioningDataSource(com.caplin.datasource.DataSource dataSource, Role role) Creates a newPermissioningDataSourcehaving a given role (master or slave) and an associatedDataSourceinstance that allows thePermissioningDataSourceto communicate with Liberator. -
Method Summary
Modifier and TypeMethodDescriptionbooleanactionExists(String action) A convenience method that will tell you if a rule for anactionhas been sent to Liberator.voidFinishes a transaction and sends the data for that transaction to the remote Liberator.voidcreateActionRefRule(String subjectNameMatch, String permissionNameSpace, String actionRef, String productRef) voidcreateActionRefRule(String subjectNameMatch, Map<String, String> fieldMatchCriteria, String permissionNameSpace, String actionRef, String productRef) voidcreateActionRule(String subjectNameMatch, String permissionNameSpace, String action, String productRef) voidcreateActionRule(String subjectNameMatch, Map<String, String> fieldMatchCriteria, String permissionNameSpace, String action, String productRef) createGroup(String name) Creates a newGroupin thisPermissioningDataSource.createUser(String name) Creates a new,KeyMasterauthenticatedUserthat is known to thisPermissioningDataSource.createUser(String name, String password) Creates a new, text password authenticatedUserthat is known to thisPermissioningDataSource.dump()Prints structure of cached permission data, used for debuggingRetrieve an existingGroupthat is already known to thisPermissioningDataSource.getName()Gets the name of thePermissioningDataSource.Retrieve an existingUserthat is already known to thisPermissioningDataSource.booleanisMaster()Indicates the role of thePermissioningDataSource.booleanDetermine whether an underlying transaction is already in progress - use before invokingstartTransactionto guard against aTransactionInProgressExceptionvoidremoveGlobalContextData(String identifier) Removes from theGlobalContext, the data identified byidentifier.voidremoveGroup(Group group) Removes a given group and implicitly removes the group from all groups of which it is a member.voidremoveUser(User user) Removes a givenUserand implicitly removes theUserfrom anyGroups of which it is a member.voidReverts thePermissioningDataSourcedata to its state before the current transaction was started.voidsetUserRequestListener(UserRequestListener listener) Registers a UserRequestListener to be called back when a user container is requested or discarded.voidStarts an image transaction, which should be used to set the permissioning data.voidstartImageTransaction(boolean rollbackSupported) Starts an image transaction, which should be used to set the permissioning data.voidStarts an update transaction, which should be used to make changes to the existing permissioning data.voidstartUpdateTransaction(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.voidupdateGlobalContext(String identifier, Map<String, String> data) Addsdatato theGlobalContext.
-
Constructor Details
-
PermissioningDataSource
Creates a newPermissioningDataSourcehaving a given role (master or slave) and an associatedDataSourceinstance that allows thePermissioningDataSourceto communicate with Liberator.- Parameters:
dataSource- TheDataSourceused to communicate with the Liberator.role- TheRolecan 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 theDataSourcethe--permission.rolenameargument when theDataSourceis 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 animagetransaction 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,GroupsorRules. Note: by default this will enable/disable rollback based on the global rollbackEnalbed flag.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 animagetransaction 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,GroupsorRules.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 animagetransaction 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 anupdatetransaction, 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,GroupsorRules. Note: by default this will enable/disable rollback based on the global rollbackEnalbed flag.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 animagetransaction 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 anupdatetransaction, 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,GroupsorRules.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;imagetransactions andupdatetransactions. Invoke this method after creating, removing or mutatingUsers,GroupsorRulesin 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 thePermissioningDataSourcedata 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
PermissioningDataSourceare 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 invokingstartTransactionto guard against aTransactionInProgressException- Returns:
- true if an underlying transaction is already in progress. Otherwise returns false.
-
createUser
Creates a new,KeyMasterauthenticatedUserthat is known to thisPermissioningDataSource. The createdUserwill be sent to the Liberator upon the committing the current transaction. TheUsercan only be removed from thisPermissioningDataSourceby callingremoveUser(User)after which theUserobject 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 authenticatedUserthat is known to thisPermissioningDataSource. The createdUserwill be sent to the Liberator upon the committing the current transaction. TheUsercan only be removed from thisPermissioningDataSourceby callingremoveUser(User)after which theUserobject is useless (you must create it again if you wish to re-add theUser).Note: Only a master
PermissioningDataSourcecan 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 newGroupin thisPermissioningDataSource. TheGroupis sent to the Liberator when the current transaction is committed.To remove (detach) a
Groupfrom aPermissioningDataSource, callremoveGroup(Group). If you want to re-use a group after it has been removed, you must callcreateGroupagain 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 existingUserthat is already known to thisPermissioningDataSource.- Parameters:
userName- The name of the user for which the permissioning data will be returned.- Returns:
- A
Userobject containing permissioning data foruserName.nullif theUseruserNamedoes not exist.
-
getGroup
Retrieve an existingGroupthat is already known to thisPermissioningDataSource.- Parameters:
groupName- The name of the group for which the permissioning data will be returned.- Returns:
- A
Groupobject containing permissioning data forgroupName.nullifGroupgroupNamedoes not exist.
-
removeUser
Removes a givenUserand implicitly removes theUserfrom anyGroups of which it is a member. Upon commit of this transaction, the Liberator is notified of the deletion. If theUseris logged in, they will be ejected. TheUserwill not be able to log in to the Liberator.- Parameters:
user- theUserto 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- theGroupto 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 anactionon aproduct. Call this method if a field in the RTTP message contains theactionfor thisRule.When a
Userattempts 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 aRulematches the message subject, the permission for theactionspecified by theRuledetermines whether or not the request is allowed or denied.Note: Only a master
PermissioningDataSourcecan create aRule.This method must be called as part of an image transaction (
startImageTransaction()). TheRuleis 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%uor%U. When a subject is being matched to aRule, the Permissioning Auth Module replaces%uwith the username of the logged inUser, and%Uwith 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 theactionspecified in this RTTP message field is checked to see if the message is allowed or denied.productRef- Permission for theproductspecified 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 anactionon aproduct. Call this method if a field in the RTTP message contains theactionfor thisRule, and if theRulemust match other known message fields and values.When a
Userattempts 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 aRulematches the message subject, the permission for theactionspecified by theRuledetermines whether or not the request is allowed or denied.Note: Only a master
PermissioningDataSourcecan create aRule.This method must be called as part of an image transaction (
startImageTransaction()). TheRuleis 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%uor%U. When a subject is being matched to aRule, the Permissioning Auth Module replaces%uwith the username of the logged inUser, and%Uwith 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. TheRulewill 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 theactionspecified in this RTTP message field is checked to see if the message is allowed or denied.productRef- Permission for theproductspecified 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 anactionon aproduct. Call this method if you want to pass in theactionas a parameter.When a
Userattempts to trade aproduct, the Permissioning Auth Module inspects the content of the received RTTP message and tries to match the message subject with thesubjectNameMatchof one or moreRules. If aRulecreated with anactionmatches the message subject, the permission for theactionspecified by theRuledetermines whether or not the message is allowed or denied.Note: Only a master
PermissioningDataSourcecan create aRule.This method must be called as part of an image transaction (
startImageTransaction()). TheRuleis 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%uor%U. When a subject is being matched to aRule, the Permissioning Auth Module replaces%uwith the username of the logged inUser, and%Uwith 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 thisactionis checked to see if the message is allowed or denied.productRef- permission for theproductspecified 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 anactionon aproduct. Call this method if you want to pass in theactionas a parameter, and if theRulemust match known RTTP message fields and values.When a
Userattempts to trade aproduct, the Permissioning Auth Module inspects the content of the received RTTP message and tries to match the message subject with thesubjectNameMatchof one or moreRules. If aRulecreated with anactionmatches the message subject, the permission for theactionspecified by theRuledetermines whether or not the message is allowed or denied.Note: Only a master
PermissioningDataSourcecan create aRule.This method must be called as part of an image transaction (
startImageTransaction()). TheRuleis 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%uor%U. When a subject is being matched to aRule, the Permissioning Auth Module replaces%uwith the username of the logged inUser, and%Uwith 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. TheRulewill 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 thisactionis checked to see if the message is allowed or denied.productRef- permission for theproductspecified 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 anactionhas been sent to Liberator. You send anactionto Liberator when you send the rule that identifies theaction.- Parameters:
action- Theactionthat you want to check.- Returns:
trueif the rule exists, otherwisefalse.
-
getName
Gets the name of thePermissioningDataSource. A name is assigned when thepermission.rolenameargument 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 thePermissioningDataSourcehas 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
Addsdatato theGlobalContext. This method must be called as part of an image or update transaction, and the request to add thedataandidentifieris sent to Liberator when the transaction is committed.Note that unlike other permissioning data, an image transaction does not remove
GlobalContextdata that was added in previous transactions (seestartImageTransaction()).To remove data from the
GlobalContext, pass theidentifierfor that data toremoveGlobalContextData(). BecauseremoveGlobalContextData()removes all data for anidentifier, it is recommended that twoPermissioningDataSourcesdo not add or remove data for the sameidentifier.- Parameters:
identifier- AStringthat uniquely identifies data in theGlobalContext.data- AMapof 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- AStringthat 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.
-