Package org.casbin.jcasbin.main
Class SyncedCachedEnforcer
java.lang.Object
org.casbin.jcasbin.main.CoreEnforcer
org.casbin.jcasbin.main.InternalEnforcer
org.casbin.jcasbin.main.ManagementEnforcer
org.casbin.jcasbin.main.Enforcer
org.casbin.jcasbin.main.SyncedEnforcer
org.casbin.jcasbin.main.SyncedCachedEnforcer
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Cache
private final AtomicBoolean
private Duration
private static final ReadWriteLock
Fields inherited from class org.casbin.jcasbin.main.CoreEnforcer
acceptJsonRequest, adapter, autoBuildRoleLinks, autoNotifyDispatcher, autoNotifyWatcher, autoSave, condRmMap, dispatcher, fm, model, modelPath, rmMap, watcher
-
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor.SyncedCachedEnforcer
(String modelPath) Initializes an enforcer with a model file.SyncedCachedEnforcer
(String modelPath, String policyFile) Initializes an enforcer with a model file and a policy file.SyncedCachedEnforcer
(String modelPath, String policyFile, boolean enableLog) Initializes an enforcer with a model file, a policy file, and a logging flag.SyncedCachedEnforcer
(String modelPath, Adapter adapter) Initializes an enforcer with a model file and a database adapter.Initializes an enforcer with a model.SyncedCachedEnforcer
(Model m, Adapter adapter) Initializes an enforcer with a model and a database adapter. -
Method Summary
Modifier and TypeMethodDescriptionboolean
addPolicies
(String[][] rules) Adds multiple policies while checking and removing the cache.boolean
addPolicies
(List<List<String>> rules) Adds multiple policies while checking and removing the cache.boolean
Adds a single policy while checking and removing the cache.private boolean
checkManyAndRemoveCache
(String[][] rules) Checks and removes cache for multiple policies.private boolean
checkManyAndRemoveCache
(List<List<String>> rules) Checks and removes cache for multiple policies.private boolean
checkOneAndRemoveCache
(String... params) Checks and removes cache for a single policy.void
enableCache
(boolean enable) Enables or disables caching.boolean
Performs an enforcement check based on given parameters, using the cache.private Boolean
getCachedResult
(String key) Retrieves a cached result based on the given key.getCacheKey
(Object... params) Retrieves a cache key from the given parameters.private String
Generates a key based on the given parameters.void
Invalidates the cache by clearing it.void
Loads the policy, clearing the cache if enabled.boolean
removePolicies
(String[][] rules) Removes multiple policies while checking and removing the cache.boolean
removePolicies
(List<List<String>> rules) Removes multiple policies while checking and removing the cache.boolean
removePolicy
(String... params) Removes a single policy while checking and removing the cache.void
Sets a custom cache.private void
setCachedResult
(String key, boolean result, Object... extra) Sets the cached result.void
setExpireTime
(Duration expireTime) Sets the cache expiration time.Methods inherited from class org.casbin.jcasbin.main.SyncedEnforcer
addGroupingPolicies, addGroupingPolicies, addGroupingPolicy, addGroupingPolicy, addNamedGroupingPolicies, addNamedGroupingPolicies, addNamedGroupingPolicy, addNamedGroupingPolicy, addNamedPolicies, addNamedPoliciesEx, addNamedPolicy, addNamedPolicy, addPermissionForUser, addPermissionForUser, addPolicy, addRoleForUser, addRoleForUserInDomain, batchEnforce, batchEnforceWithMatcher, buildRoleLinks, clearPolicy, deletePermission, deletePermission, deletePermissionForUser, deletePermissionForUser, deletePermissionsForUser, deleteRole, deleteRoleForUser, deleteRoleForUserInDomain, deleteRolesForUser, deleteUser, enforceEx, enforceExWithMatcher, enforceWithMatcher, getAllActions, getAllNamedActions, getAllNamedObjects, getAllNamedRoles, getAllObjects, getAllRoles, getAllSubjects, getFilteredGroupingPolicy, getFilteredNamedGroupingPolicy, getFilteredNamedPolicy, getFilteredPolicy, getGroupingPolicy, getImplicitPermissionsForUser, getImplicitRolesForUser, getNamedGroupingPolicy, getNamedImplicitPermissionsForUser, getNamedPermissionsForUser, getNamedPolicy, getPermissionsForUser, getPermissionsForUserInDomain, getPolicy, getRolesForUser, getRolesForUserInDomain, getUsersForRole, getUsersForRoleInDomain, hasGroupingPolicy, hasGroupingPolicy, hasNamedGroupingPolicy, hasNamedGroupingPolicy, hasNamedPolicy, hasNamedPolicy, hasPermissionForUser, hasPermissionForUser, hasPolicy, hasPolicy, hasRoleForUser, isAutoLoadingRunning, loadFilteredPolicy, removeFilteredGroupingPolicy, removeFilteredNamedGroupingPolicy, removeFilteredNamedPolicy, removeFilteredPolicy, removeGroupingPolicies, removeGroupingPolicies, removeGroupingPolicy, removeGroupingPolicy, removeNamedGroupingPolicies, removeNamedGroupingPolicies, removeNamedGroupingPolicy, removeNamedGroupingPolicy, removeNamedPolicies, removeNamedPolicy, removeNamedPolicy, removePolicy, savePolicy, setWatcher, startAutoLoadPolicy, stopAutoLoadPolicy, updateGroupingPolicy, updateNamedGroupingPolicy, updateNamedPolicy, updatePolicy
Methods inherited from class org.casbin.jcasbin.main.Enforcer
getImplicitPermissionsForUserInDomain, getImplicitUsersForRole, updatePermissionForUser
Methods inherited from class org.casbin.jcasbin.main.ManagementEnforcer
addFunction, getAllNamedSubjects, getPermittedActions
Methods inherited from class org.casbin.jcasbin.main.InternalEnforcer
addPolicies, addPolicy, buildIncrementalRoleLinks, getDomainIndex, removeFilteredPolicy, removePolicies, removePolicy, updatePolicy
Methods inherited from class org.casbin.jcasbin.main.CoreEnforcer
addNamedDomainLinkConditionFunc, addNamedDomainMatchingFunc, addNamedLinkConditionFunc, addNamedMatchingFunc, buildConditionalRoleLinks, enableAcceptJsonRequest, enableAutoBuildRoleLinks, enableAutoSave, enableEnforce, enableLog, getAdapter, getAviatorEval, getModel, getNamedRoleManager, getRmMap, getRoleManager, initialize, isAutoNotifyDispatcher, isAutoNotifyWatcher, isFiltered, loadModel, mustUseDispatcher, newModel, newModel, newModel, resetExpressionEvaluator, setAdapter, setAutoNotifyDispatcher, setAutoNotifyWatcher, setAviatorEvaluator, setDispatcher, setEffector, setModel, setNamedDomainLinkConditionFuncParams, setNamedLinkConditionFuncParams, setNamedRoleManager, setRoleManager, setRoleManager, validateEnforce
-
Field Details
-
expireTime
-
cache
-
enableCache
-
READ_WRITE_LOCK
-
-
Constructor Details
-
SyncedCachedEnforcer
public SyncedCachedEnforcer()Default constructor. Initializes a new SyncedCachedEnforcer with a default cache. -
SyncedCachedEnforcer
Initializes an enforcer with a model file and a policy file.- Parameters:
modelPath
- The path of the model file.policyFile
- The path of the policy file.
-
SyncedCachedEnforcer
Initializes an enforcer with a model file and a database adapter.- Parameters:
modelPath
- The path of the model file.adapter
- The adapter for the database.
-
SyncedCachedEnforcer
Initializes an enforcer with a model and a database adapter.- Parameters:
m
- The model.adapter
- The adapter for the database.
-
SyncedCachedEnforcer
Initializes an enforcer with a model.- Parameters:
m
- The model.
-
SyncedCachedEnforcer
Initializes an enforcer with a model file.- Parameters:
modelPath
- The path of the model file.
-
SyncedCachedEnforcer
Initializes an enforcer with a model file, a policy file, and a logging flag.- Parameters:
modelPath
- The path of the model file.policyFile
- The path of the policy file.enableLog
- Whether to enable logging for Casbin.
-
-
Method Details
-
enableCache
public void enableCache(boolean enable) Enables or disables caching.- Parameters:
enable
- Whether to enable caching.
-
enforce
Performs an enforcement check based on given parameters, using the cache.- Overrides:
enforce
in classSyncedEnforcer
- Parameters:
rvals
- Parameters for the enforcement check.- Returns:
- The result of the enforcement check.
-
loadPolicy
public void loadPolicy()Loads the policy, clearing the cache if enabled.- Overrides:
loadPolicy
in classSyncedEnforcer
-
addPolicy
Adds a single policy while checking and removing the cache.- Overrides:
addPolicy
in classSyncedEnforcer
- Parameters:
params
- Policy parameters.- Returns:
- Whether the addition was successful.
-
addPolicies
Adds multiple policies while checking and removing the cache.- Overrides:
addPolicies
in classSyncedEnforcer
- Parameters:
rules
- Policy rules.- Returns:
- Whether the addition was successful.
-
addPolicies
Adds multiple policies while checking and removing the cache.- Overrides:
addPolicies
in classSyncedEnforcer
- Parameters:
rules
- Policy rules.- Returns:
- Whether the addition was successful.
-
removePolicy
Removes a single policy while checking and removing the cache.- Overrides:
removePolicy
in classSyncedEnforcer
- Parameters:
params
- Policy parameters.- Returns:
- Whether the removal was successful.
-
removePolicies
Removes multiple policies while checking and removing the cache.- Overrides:
removePolicies
in classSyncedEnforcer
- Parameters:
rules
- Policy rules.- Returns:
- Whether the removal was successful.
-
removePolicies
Removes multiple policies while checking and removing the cache.- Overrides:
removePolicies
in classSyncedEnforcer
- Parameters:
rules
- Policy rules.- Returns:
- Whether the removal was successful.
-
getCachedResult
Retrieves a cached result based on the given key.- Parameters:
key
- The cache key.- Returns:
- The cached result.
-
setExpireTime
Sets the cache expiration time.- Parameters:
expireTime
- The expiration time.
-
setCache
Sets a custom cache.- Parameters:
cache
- The custom cache.
-
setCachedResult
Sets the cached result.- Parameters:
key
- The cache key.result
- The enforcement check result.extra
- Additional parameters.
-
getCacheKey
Retrieves a cache key from the given parameters.- Parameters:
params
- The parameters for generating the key.- Returns:
- The generated cache key as a string.
-
getKey
Generates a key based on the given parameters.- Parameters:
params
- Parameters.- Returns:
- The generated key.
-
invalidateCache
public void invalidateCache()Invalidates the cache by clearing it. -
checkOneAndRemoveCache
Checks and removes cache for a single policy.- Parameters:
params
- Policy parameters.- Returns:
- Whether the check was successful.
-
checkManyAndRemoveCache
Checks and removes cache for multiple policies.- Parameters:
rules
- Policy rules.- Returns:
- Whether the check was successful.
-
checkManyAndRemoveCache
Checks and removes cache for multiple policies.- Parameters:
rules
- Policy rules.- Returns:
- Whether the check was successful.
-