Interface SubjectData
-
public interface SubjectData
Container for a subject's data.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 inSubject
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
Fields Modifier and Type Field Description static java.util.Set<Context>
GLOBAL_CONTEXT
A convenience constant for the global context combination (the empty set), if you want your code to look especially fancy.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description java.util.concurrent.CompletableFuture<java.lang.Boolean>
addParent(java.util.Set<Context> contexts, SubjectReference parent)
Adds a parent in a particular context combination.java.util.Map<java.util.Set<Context>,Tristate>
allFallbackPermissionValues()
Get all fallback permission values set on this subject datajava.util.Map<java.util.Set<Context>,java.util.Map<java.lang.String,java.lang.String>>
allOptions()
Return all options for all context combinations currently registered.java.util.Map<java.util.Set<Context>,? extends java.util.List<? extends SubjectReference>>
allParents()
Return all registered parent subjects for all contexts.java.util.Map<java.util.Set<Context>,java.util.Map<java.lang.String,java.lang.Boolean>>
allPermissions()
Return all permissions associated with this data object.java.util.concurrent.CompletableFuture<java.lang.Boolean>
clearFallbackPermissionValues()
Clear all fallback permission values from this subjectjava.util.concurrent.CompletableFuture<java.lang.Boolean>
clearOptions()
Clear all options.java.util.concurrent.CompletableFuture<java.lang.Boolean>
clearOptions(java.util.Set<Context> contexts)
Clear all options in the given context combination.java.util.concurrent.CompletableFuture<java.lang.Boolean>
clearParents()
Remove all parents in any context combination.java.util.concurrent.CompletableFuture<java.lang.Boolean>
clearParents(java.util.Set<Context> contexts)
Remove all parents in a given context combination.java.util.concurrent.CompletableFuture<java.lang.Boolean>
clearPermissions()
Clear all permissions set in any context.java.util.concurrent.CompletableFuture<java.lang.Boolean>
clearPermissions(java.util.Set<Context> contexts)
Clear all permissions set in a given context combination.java.util.concurrent.CompletableFuture<java.lang.Boolean>
copyFrom(SubjectData other, TransferMethod method)
Copy all data from another subject data instance into this one, preserving the original subject.Tristate
fallbackPermissionValue(java.util.Set<Context> contexts)
Get the permission value that will be returned if no more specific permission setting matches.boolean
isTransient()
Return if this SubjectData is transient.java.util.concurrent.CompletableFuture<java.lang.Boolean>
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.java.util.Map<java.lang.String,java.lang.String>
options(java.util.Set<Context> contexts)
Gets options for a specific context combination.java.util.List<? extends SubjectReference>
parents(java.util.Set<Context> contexts)
Return all registered parent subjects for a given context.java.util.Map<java.lang.String,java.lang.Boolean>
permissions(java.util.Set<Context> contexts)
Returns the list of permissions set for the given context.java.util.concurrent.CompletableFuture<java.lang.Boolean>
removeParent(java.util.Set<Context> contexts, SubjectReference parent)
Removes a parent in a particular context combination.java.util.concurrent.CompletableFuture<java.lang.Boolean>
setFallbackPermissionValue(java.util.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.java.util.concurrent.CompletableFuture<java.lang.Boolean>
setOption(java.util.Set<Context> contexts, java.lang.String key, @Nullable java.lang.String value)
Sets a specific option to a value.java.util.concurrent.CompletableFuture<java.lang.Boolean>
setOptions(java.util.Set<Context> contexts, java.util.Map<java.lang.String,java.lang.String> options, TransferMethod method)
Sets all options in a particular context.java.util.concurrent.CompletableFuture<java.lang.Boolean>
setParents(java.util.Set<Context> contexts, java.util.List<? extends SubjectReference> parents, TransferMethod method)
Sets the parents in a particular context combination.java.util.concurrent.CompletableFuture<java.lang.Boolean>
setPermission(java.util.Set<Context> contexts, java.lang.String permission, Tristate value)
Sets a permission to a given value.java.util.concurrent.CompletableFuture<java.lang.Boolean>
setPermissions(java.util.Set<Context> contexts, java.util.Map<java.lang.String,java.lang.Boolean> permissions, TransferMethod method)
Sets permissions in a given context combination.Subject
subject()
Gets theSubject
which holds this data.
-
-
-
Field Detail
-
GLOBAL_CONTEXT
static final java.util.Set<Context> GLOBAL_CONTEXT
A convenience constant for the global context combination (the empty set), if you want your code to look especially fancy.
-
-
Method Detail
-
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:
Subject.transientSubjectData()
-
allPermissions
java.util.Map<java.util.Set<Context>,java.util.Map<java.lang.String,java.lang.Boolean>> 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
java.util.Map<java.lang.String,java.lang.Boolean> permissions(java.util.Set<Context> contexts)
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
java.util.concurrent.CompletableFuture<java.lang.Boolean> setPermission(java.util.Set<Context> contexts, java.lang.String permission, Tristate value)
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
java.util.concurrent.CompletableFuture<java.lang.Boolean> setPermissions(java.util.Set<Context> contexts, java.util.Map<java.lang.String,java.lang.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
Tristate fallbackPermissionValue(java.util.Set<Context> contexts)
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
java.util.Map<java.util.Set<Context>,Tristate> allFallbackPermissionValues()
Get all fallback permission values set on this subject data- Returns:
- An immutable map from context combination to fallback value
-
setFallbackPermissionValue
java.util.concurrent.CompletableFuture<java.lang.Boolean> setFallbackPermissionValue(java.util.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.- 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
java.util.concurrent.CompletableFuture<java.lang.Boolean> clearFallbackPermissionValues()
Clear all fallback permission values from this subject- Returns:
- A future completing when the change has been applied
-
clearPermissions
java.util.concurrent.CompletableFuture<java.lang.Boolean> clearPermissions()
Clear all permissions set in any context.- Returns:
- Whether any change occurred
-
clearPermissions
java.util.concurrent.CompletableFuture<java.lang.Boolean> clearPermissions(java.util.Set<Context> contexts)
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
java.util.Map<java.util.Set<Context>,? extends java.util.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
java.util.List<? extends SubjectReference> parents(java.util.Set<Context> contexts)
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
java.util.concurrent.CompletableFuture<java.lang.Boolean> setParents(java.util.Set<Context> contexts, java.util.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
java.util.concurrent.CompletableFuture<java.lang.Boolean> addParent(java.util.Set<Context> contexts, SubjectReference parent)
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
java.util.concurrent.CompletableFuture<java.lang.Boolean> removeParent(java.util.Set<Context> contexts, SubjectReference parent)
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
java.util.concurrent.CompletableFuture<java.lang.Boolean> clearParents()
Remove all parents in any context combination.- Returns:
- Whether any change occurred
-
clearParents
java.util.concurrent.CompletableFuture<java.lang.Boolean> clearParents(java.util.Set<Context> contexts)
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
java.util.Map<java.util.Set<Context>,java.util.Map<java.lang.String,java.lang.String>> allOptions()
Return all options for all context combinations currently registered.- Returns:
- An immutable snapshot of all options data
-
options
java.util.Map<java.lang.String,java.lang.String> options(java.util.Set<Context> contexts)
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
java.util.concurrent.CompletableFuture<java.lang.Boolean> setOption(java.util.Set<Context> contexts, java.lang.String key, @Nullable java.lang.String value)
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
java.util.concurrent.CompletableFuture<java.lang.Boolean> setOptions(java.util.Set<Context> contexts, java.util.Map<java.lang.String,java.lang.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
java.util.concurrent.CompletableFuture<java.lang.Boolean> clearOptions()
Clear all options.- Returns:
- Whether the operation was successful
-
clearOptions
java.util.concurrent.CompletableFuture<java.lang.Boolean> clearOptions(java.util.Set<Context> contexts)
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
java.util.concurrent.CompletableFuture<java.lang.Boolean> copyFrom(SubjectData other, TransferMethod method)
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
java.util.concurrent.CompletableFuture<java.lang.Boolean> 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. 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
-
-