Interface SubjectData
This container updates live, and provides raw data for a subject not
taking into account any sort of inheritance. This interface is meant to
represent what's 'in the file', rather than the higher-level query methods
available in Subject
.
Methods which modify the state of the data return
CompletableFuture
s. This allows for the time which is taken to apply
and persist the change to the implementations storage backend. These futures
should return quickly for changes made to transient subject data, but may
take longer to return for changes made to a subjects persistent data. Methods
which use this data in Subject
may not reflect the change until the
future has returned.
CompletableFuture.allOf(CompletableFuture[])
can be used to
combine multiple futures into one, if the result of methods is not
needed.
-
Field Summary
Modifier and TypeFieldDescriptionA convenience constant for the global context combination (the empty set), if you want your code to look especially fancy. -
Method Summary
Modifier and TypeMethodDescriptionaddParent
(Set<Context> contexts, SubjectReference parent) Adds a parent in a particular context combination.Get all fallback permission values set on this subject dataReturn all options for all context combinations currently registered.Map<Set<Context>,
? extends List<? extends SubjectReference>> Return all registered parent subjects for all contexts.Return all permissions associated with this data object.Clear all fallback permission values from this subjectClear all options.clearOptions
(Set<Context> contexts) Clear all options in the given context combination.Remove all parents in any context combination.clearParents
(Set<Context> contexts) Remove all parents in a given context combination.Clear all permissions set in any context.clearPermissions
(Set<Context> contexts) Clear all permissions set in a given context combination.copyFrom
(SubjectData other, TransferMethod method) Copy all data from another subject data instance into this one, preserving the original subject.fallbackPermissionValue
(Set<Context> contexts) Get the permission value that will be returned if no more specific permission setting matches.boolean
Return if this SubjectData is transient.moveFrom
(SubjectData other, TransferMethod method) Move all data from another subject data instance into this one, clearing the source It is expected that the other subject data is provided by the same permissions service.Gets options for a specific context combination.List<? extends SubjectReference>
Return all registered parent subjects for a given context.permissions
(Set<Context> contexts) Returns the list of permissions set for the given context.removeParent
(Set<Context> contexts, SubjectReference parent) Removes a parent in a particular context combination.setFallbackPermissionValue
(Set<Context> contexts, Tristate fallback) Set the permission value at the root of the node tree, that will be returned as a response to permissions queries when no more specific permission matches.Sets a specific option to a value.setOptions
(Set<Context> contexts, Map<String, String> options, TransferMethod method) Sets all options in a particular context.setParents
(Set<Context> contexts, List<? extends SubjectReference> parents, TransferMethod method) Sets the parents in a particular context combination.setPermission
(Set<Context> contexts, String permission, Tristate value) Sets a permission to a given value.setPermissions
(Set<Context> contexts, Map<String, Boolean> permissions, TransferMethod method) Sets permissions in a given context combination.subject()
Gets theSubject
which holds this data.
-
Field Details
-
GLOBAL_CONTEXT
A convenience constant for the global context combination (the empty set), if you want your code to look especially fancy.
-
-
Method Details
-
subject
Subject subject()Gets theSubject
which holds this data.- Returns:
- The subject which holds this data
-
isTransient
boolean isTransient()Return if this SubjectData is transient.- Returns:
- If this SubjectData is transient
- See Also:
-
allPermissions
Return all permissions associated with this data object.- Returns:
- An immutable copy of the mappings between contexts and lists of permissions containing every permission registered
-
permissions
Returns the list of permissions set for the given context.This list is immutable and is not a live view. If no permissions have been set, it returns an empty list.
- Parameters:
contexts
- The particular context combination to check- Returns:
- Any permissions set
-
setPermission
Sets a permission to a given value.Setting value as
Tristate.UNDEFINED
unsets the permission.An empty set of contexts applies this permission to the global context.
- Parameters:
contexts
- The particular combination of contexts to set this permission inpermission
- The permission to setvalue
- The value to set this permission to- Returns:
- Whether the operation was successful
-
setPermissions
CompletableFuture<Boolean> setPermissions(Set<Context> contexts, Map<String, Boolean> permissions, TransferMethod method) Sets permissions in a given context combination.An empty set of contexts applies these permissions to the global context.
Depending on the
TransferMethod
chosen, this will either replace all existing options or add to the existing options.- Parameters:
contexts
- The particular combination of contexts to set these permissions inpermissions
- The permissions to setmethod
- How to treat existing values in this subject- Returns:
- Whether the operation was successful
-
fallbackPermissionValue
Get the permission value that will be returned if no more specific permission setting matches.- Parameters:
contexts
- The context combination to set this permission in.- Returns:
- The tristate
-
allFallbackPermissionValues
Get all fallback permission values set on this subject data- Returns:
- An immutable map from context combination to fallback value
-
setFallbackPermissionValue
Set the permission value at the root of the node tree, that will be returned as a response to permissions queries when no more specific permission matches.- Parameters:
contexts
- The context combinationfallback
- The new fallback value.Tristate.UNDEFINED
unsets the fallback value.- Returns:
- A future completing when the change has been applied
-
clearFallbackPermissionValues
CompletableFuture<Boolean> clearFallbackPermissionValues()Clear all fallback permission values from this subject- Returns:
- A future completing when the change has been applied
-
clearPermissions
CompletableFuture<Boolean> clearPermissions()Clear all permissions set in any context.- Returns:
- Whether any change occurred
-
clearPermissions
Clear all permissions set in a given context combination.Passing an empty context set clears permissions in the global context.
- Parameters:
contexts
- The context combination to clear permissions in- Returns:
- Whether any change occurred
-
allParents
Map<Set<Context>,? extends List<? extends SubjectReference>> allParents()Return all registered parent subjects for all contexts.The returned map is immutable and not a live view. The results of this method do not traverse any sort of inheritance structure a permissions plugin may implement.
- Returns:
- All registered parents and the context they are registered in
-
parents
Return all registered parent subjects for a given context.The returned list is immutable and not a live view. The results of this method do not traverse any sort of inheritance structure a permissions plugin may implement.
- Parameters:
contexts
- The context to check- Returns:
- names of parents valid in the given context
-
setParents
CompletableFuture<Boolean> setParents(Set<Context> contexts, List<? extends SubjectReference> parents, TransferMethod method) Sets the parents in a particular context combination.Passing an empty context combination means the parents are set in the global context.
Depending on the
TransferMethod
chosen, this will either replace all existing options or add to the existing options.- Parameters:
contexts
- The context combination this operation is applicable toparents
- A list of the parents this subject should have- Returns:
- Whether the operation was successful
-
addParent
Adds a parent in a particular context combination.Passing an empty context combination means the parent is added in the global context.
- Parameters:
contexts
- The context combination this operation is applicable toparent
- The name of the parent to add- Returns:
- Whether the operation was successful
-
removeParent
Removes a parent in a particular context combination.Passing an empty context combination means the parent is removed in the global context.
- Parameters:
contexts
- The context combination this operation is applicable toparent
- The name of the parent to remove- Returns:
- Whether the operation was successful
-
clearParents
CompletableFuture<Boolean> clearParents()Remove all parents in any context combination.- Returns:
- Whether any change occurred
-
clearParents
Remove all parents in a given context combination.Passing an empty context set clears parents in the global context.
- Parameters:
contexts
- The context combination to clear the parents of- Returns:
- Whether any change occurred
-
allOptions
Return all options for all context combinations currently registered.- Returns:
- An immutable snapshot of all options data
-
options
Gets options for a specific context combination.- Parameters:
contexts
- The context combination to get options for- Returns:
- All available options, returning an empty map if none are present
-
setOption
Sets a specific option to a value.Passing a null value will unset the option.
- Parameters:
contexts
- The context combination to set the given option inkey
- The key to set. Case-insensitive.value
- The value to set.- Returns:
- Whether the operation was successful
-
setOptions
CompletableFuture<Boolean> setOptions(Set<Context> contexts, Map<String, String> options, TransferMethod method) Sets all options in a particular context.Depending on the
TransferMethod
chosen, this will either replace all existing options or add to the existing options.- Parameters:
contexts
- The context combination to set the options inoptions
- The map of options to set- Returns:
- Whether the operation was successful
-
clearOptions
CompletableFuture<Boolean> clearOptions()Clear all options.- Returns:
- Whether the operation was successful
-
clearOptions
Clear all options in the given context combination.Passing an empty context set clears options in the global context.
- Parameters:
contexts
- The context combination- Returns:
- Whether the operation was successful (any options were removed)
-
copyFrom
Copy all data from another subject data instance into this one, preserving the original subject. It is expected that the other subject data is provided by the same permissions service. This methods's behaviour is undefined otherwise.- Parameters:
other
- The other subject to copy data frommethod
- How to treat existing values in this subject- Returns:
- A future completing with
true
if the operation is successful
-
moveFrom
Move all data from another subject data instance into this one, clearing the source It is expected that the other subject data is provided by the same permissions service. This methods's behaviour is undefined otherwise.- Parameters:
other
- The other subject to move data frommethod
- How to treat existing values in this subject- Returns:
- A future completing with
true
if the operation is successful
-