public class CoreEnforcer
extends java.lang.Object
| Constructor and Description |
|---|
CoreEnforcer() |
| Modifier and Type | Method and Description |
|---|---|
boolean |
addNamedDomainLinkConditionFunc(java.lang.String ptype,
java.lang.String user,
java.lang.String role,
java.lang.String domain,
java.util.function.Function<java.lang.String[],java.lang.Boolean> fn)
addNamedDomainLinkConditionFunc Add condition function fn for Link userName-> {roleName, domain},
when fn returns true, Link is valid, otherwise invalid
|
boolean |
addNamedDomainMatchingFunc(java.lang.String ptype,
java.lang.String name,
java.util.function.BiPredicate<java.lang.String,java.lang.String> fn)
addNamedMatchingFunc add MatchingFunc by ptype RoleManager
|
boolean |
addNamedLinkConditionFunc(java.lang.String ptype,
java.lang.String user,
java.lang.String role,
java.util.function.Function<java.lang.String[],java.lang.Boolean> fn)
addNamedLinkConditionFunc Add condition function fn for Link userName->roleName,
when fn returns true, Link is valid, otherwise invalid
|
boolean |
addNamedMatchingFunc(java.lang.String ptype,
java.lang.String name,
java.util.function.BiPredicate<java.lang.String,java.lang.String> fn)
addNamedMatchingFunc add MatchingFunc by ptype RoleManager
|
void |
buildConditionalRoleLinks() |
void |
buildRoleLinks()
buildRoleLinks manually rebuild the
role inheritance relations.
|
void |
clearPolicy()
clearPolicy clears all policy.
|
void |
enableAcceptJsonRequest(boolean acceptJsonRequest)
EnableAcceptJsonRequest controls whether to accept json as a request parameter
|
void |
enableAutoBuildRoleLinks(boolean autoBuildRoleLinks)
enableAutoBuildRoleLinks controls whether to save a policy rule
automatically to the adapter when it is added or removed.
|
void |
enableAutoSave(boolean autoSave)
enableAutoSave controls whether to save a policy rule automatically to
the adapter when it is added or removed.
|
void |
enableEnforce(boolean enable)
enableEnforce changes the enforcing state of Casbin, when Casbin is
disabled, all access will be allowed by the enforce() function.
|
void |
enableLog(boolean enable)
enableLog changes whether to print Casbin log to the standard output.
|
boolean |
enforce(java.lang.Object... rvals)
enforce decides whether a "subject" can access a "object" with
the operation "action", input parameters are usually: (sub, obj, act).
|
EnforceResult |
enforceEx(java.lang.Object... rvals)
enforceEx decides whether a "subject" can access "object" with
the operation "action", input parameters are usually: (sub, obj, act).
|
EnforceResult |
enforceExWithMatcher(java.lang.String matcher,
java.lang.Object... rvals)
enforceExWithMatcher use a custom matcher to decide whether a "subject" can access a "object" with the operation "action",
input parameters are usually: (matcher, sub, obj, act), use model matcher by default when matcher is "" or null.
|
boolean |
enforceWithMatcher(java.lang.String matcher,
java.lang.Object... rvals)
enforceWithMatcher use a custom matcher to decide whether a "subject" can access a "object" with the operation "action",
input parameters are usually: (matcher, sub, obj, act), use model matcher by default when matcher is "" or null.
|
Adapter |
getAdapter()
getAdapter gets the current adapter.
|
com.googlecode.aviator.AviatorEvaluatorInstance |
getAviatorEval()
gets the current Aviator Evaluator instance
|
Model |
getModel()
getModel gets the current model.
|
RoleManager |
getNamedRoleManager(java.lang.String ptype)
getNamedRoleManager gets the role manager for the named policy.
|
java.util.Map<java.lang.String,RoleManager> |
getRmMap()
getRmMap gets the current role manager map.
|
RoleManager |
getRoleManager()
getRoleManager gets the current role manager.
|
boolean |
isAutoNotifyDispatcher() |
boolean |
isAutoNotifyWatcher() |
boolean |
isFiltered()
isFiltered returns true if the loaded policy has been filtered.
|
void |
loadFilteredPolicy(java.lang.Object filter)
loadFilteredPolicy reloads a filtered policy from file/database.
|
void |
loadModel()
loadModel reloads the model from the model CONF file.
|
void |
loadPolicy()
loadPolicy reloads the policy from file/database.
|
protected boolean |
mustUseDispatcher() |
static Model |
newModel()
newModel creates a model.
|
static Model |
newModel(java.lang.String text)
newModel creates a model.
|
static Model |
newModel(java.lang.String modelPath,
java.lang.String unused)
newModel creates a model.
|
void |
resetExpressionEvaluator()
Invalidate cache of compiled model matcher expression.
|
void |
savePolicy()
savePolicy saves the current policy (usually after changed with
Casbin API) back to file/database.
|
void |
setAdapter(Adapter adapter)
setAdapter sets the current adapter.
|
void |
setAutoNotifyDispatcher(boolean autoNotifyDispatcher) |
void |
setAutoNotifyWatcher(boolean autoNotifyWatcher) |
void |
setAviatorEvaluator(com.googlecode.aviator.AviatorEvaluatorInstance evaluator)
set the aviator evaluator
|
void |
setDispatcher(Dispatcher dispatcher)
setDispatcher sets the current dispatcher.
|
void |
setEffector(Effector eft)
setEffector sets the current effector.
|
void |
setModel(Model model)
setModel sets the current model.
|
boolean |
setNamedDomainLinkConditionFuncParams(java.lang.String ptype,
java.lang.String user,
java.lang.String role,
java.lang.String domain,
java.lang.String... params)
setNamedDomainLinkConditionFuncParams Sets the parameters of the condition function fn
for Link userName->{roleName, domain}
|
boolean |
setNamedLinkConditionFuncParams(java.lang.String ptype,
java.lang.String user,
java.lang.String role,
java.lang.String... params)
setNamedLinkConditionFuncParams Sets the parameters of the condition function fn for Link userName->roleName
|
void |
setNamedRoleManager(java.lang.String ptype,
RoleManager rm)
setNamedRoleManager sets the role manager for the named policy.
|
void |
setRoleManager(RoleManager rm)
setRoleManager sets the current role manager for g.
|
void |
setRoleManager(java.lang.String ptype,
RoleManager rm)
setRoleManager sets role manager for ptype.
|
void |
setWatcher(Watcher watcher)
setWatcher sets the current watcher.
|
boolean |
validateEnforce(java.lang.Object... rvals) |
public static Model newModel()
public static Model newModel(java.lang.String text)
text - the model text.public static Model newModel(java.lang.String modelPath, java.lang.String unused)
modelPath - the path of the model file.unused - unused parameter, just for differentiating with
newModel(String text).public void loadModel()
public Model getModel()
public void setModel(Model model)
model - the model.public void setAviatorEvaluator(com.googlecode.aviator.AviatorEvaluatorInstance evaluator)
evaluator - aviator evaluatorpublic com.googlecode.aviator.AviatorEvaluatorInstance getAviatorEval()
public Adapter getAdapter()
public void setAdapter(Adapter adapter)
adapter - the adapter.public void setWatcher(Watcher watcher)
watcher - the watcher.public void setDispatcher(Dispatcher dispatcher)
dispatcher - jCasbin dispatcherpublic java.util.Map<java.lang.String,RoleManager> getRmMap()
public RoleManager getRoleManager()
public RoleManager getNamedRoleManager(java.lang.String ptype)
ptype - the policy type.public void setRoleManager(RoleManager rm)
rm - the role manager.public void setNamedRoleManager(java.lang.String ptype,
RoleManager rm)
ptype - the policy type.rm - the role manager.public void setEffector(Effector eft)
eft - the effector.public void clearPolicy()
public void loadPolicy()
public void loadFilteredPolicy(java.lang.Object filter)
filter - the filter used to specify which type of policy should be loaded.public boolean isFiltered()
public void savePolicy()
public void setRoleManager(java.lang.String ptype,
RoleManager rm)
ptype - the policy type, can be "g", "g2", "g3", ..rm - the role manager.public void enableEnforce(boolean enable)
enable - whether to enable the enforcer.public void enableLog(boolean enable)
enable - whether to enable Casbin's log.public void enableAutoSave(boolean autoSave)
autoSave - whether to enable the AutoSave feature.public void enableAutoBuildRoleLinks(boolean autoBuildRoleLinks)
autoBuildRoleLinks - whether to automatically build the role links.public void enableAcceptJsonRequest(boolean acceptJsonRequest)
acceptJsonRequest - a boolean that indicates whether JSON requests are accepted.public void buildRoleLinks()
public void buildConditionalRoleLinks()
public boolean enforce(java.lang.Object... rvals)
rvals - the request needs to be mediated, usually an array
of strings, can be class instances if ABAC is used.public boolean enforceWithMatcher(java.lang.String matcher,
java.lang.Object... rvals)
matcher - the custom matcher.rvals - the request needs to be mediated, usually an array
of strings, can be class instances if ABAC is used.public EnforceResult enforceEx(java.lang.Object... rvals)
rvals - the request needs to be mediated, usually an array
of strings, can be class instances if ABAC is used.public EnforceResult enforceExWithMatcher(java.lang.String matcher, java.lang.Object... rvals)
matcher - the custom matcher.rvals - the request needs to be mediated, usually an array
of strings, can be class instances if ABAC is used.public boolean addNamedMatchingFunc(java.lang.String ptype,
java.lang.String name,
java.util.function.BiPredicate<java.lang.String,java.lang.String> fn)
ptype - the type of the role manager.name - the name of the matching function to be added.fn - the matching function.public boolean addNamedDomainMatchingFunc(java.lang.String ptype,
java.lang.String name,
java.util.function.BiPredicate<java.lang.String,java.lang.String> fn)
ptype - the type of the role manager.name - the name of the matching function to be added.fn - the domain matching function.public boolean addNamedLinkConditionFunc(java.lang.String ptype,
java.lang.String user,
java.lang.String role,
java.util.function.Function<java.lang.String[],java.lang.Boolean> fn)
ptype - the type of the role manager.user - the username for which the link condition is being added.role - the role associated with the user for which the condition is evaluated.fn - a function that takes an array of parameters (e.g., [user, role]) and returns a Boolean indicating the validity of the link.public boolean addNamedDomainLinkConditionFunc(java.lang.String ptype,
java.lang.String user,
java.lang.String role,
java.lang.String domain,
java.util.function.Function<java.lang.String[],java.lang.Boolean> fn)
ptype - the type of the conditional role manager.user - the username for which the link condition is being added.role - the role associated with the user for which the condition is evaluated.domain - the domain associated with the role.fn - a function that takes an array of parameters (e.g., [user, role, domain]) and returns a Boolean indicating the validity of the link.public boolean setNamedLinkConditionFuncParams(java.lang.String ptype,
java.lang.String user,
java.lang.String role,
java.lang.String... params)
ptype - the type of the conditional role manager.user - the username for which the link condition parameters are being set.role - the role associated with the user for which the parameters are being configured.params - an array of parameters to be passed to the condition function.public boolean setNamedDomainLinkConditionFuncParams(java.lang.String ptype,
java.lang.String user,
java.lang.String role,
java.lang.String domain,
java.lang.String... params)
ptype - the type of the conditional role manager.user - the username for which the link condition parameters are being set.role - the role associated with the user for which the parameters are being configured.domain - the domain associated with the role and user.params - an array of parameters to be passed to the condition function, allowing customization of the condition logic.public boolean validateEnforce(java.lang.Object... rvals)
public void resetExpressionEvaluator()
public boolean isAutoNotifyWatcher()
public void setAutoNotifyWatcher(boolean autoNotifyWatcher)
public boolean isAutoNotifyDispatcher()
public void setAutoNotifyDispatcher(boolean autoNotifyDispatcher)
protected boolean mustUseDispatcher()
Copyright © 2017–2025. All rights reserved.