Skip to content

Commit 08333cb

Browse files
authored
feat: fix javadoc (casbin#432)
1 parent 89b4c56 commit 08333cb

12 files changed

+159
-36
lines changed

pom.xml

+5-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,11 @@
8585
<source>11</source>
8686
<detectJavaApiLink>false</detectJavaApiLink>
8787
<!-- Turn off Java 8 strict Javadoc checking -->
88-
<additionalparam>-Xdoclint:none</additionalparam>
88+
<!-- <additionalparam>-Xdoclint:none</additionalparam>-->
89+
<doclint>none</doclint>
90+
<sourceFileIncludes>
91+
<sourceFileInclude>**/*.java</sourceFileInclude>
92+
</sourceFileIncludes>
8993
<tags>
9094
<tag>
9195
<name>notnull</name>

src/main/java/org/casbin/jcasbin/main/CoreEnforcer.java

+57-5
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ public void enableAutoBuildRoleLinks(boolean autoBuildRoleLinks) {
486486
/**
487487
* EnableAcceptJsonRequest controls whether to accept json as a request parameter
488488
*
489-
* @param acceptJsonRequest
489+
* @param acceptJsonRequest a boolean that indicates whether JSON requests are accepted.
490490
*/
491491
public void enableAcceptJsonRequest(boolean acceptJsonRequest) {
492492
this.acceptJsonRequest = acceptJsonRequest;
@@ -782,6 +782,11 @@ public EnforceResult enforceExWithMatcher(String matcher, Object... rvals) {
782782

783783
/**
784784
* addNamedMatchingFunc add MatchingFunc by ptype RoleManager
785+
*
786+
* @param ptype the type of the role manager.
787+
* @param name the name of the matching function to be added.
788+
* @param fn the matching function.
789+
* @return whether the matching function was successfully added.
785790
*/
786791
public boolean addNamedMatchingFunc(String ptype, String name, BiPredicate<String, String> fn) {
787792
if (rmMap.containsKey(ptype)) {
@@ -798,6 +803,11 @@ public boolean addNamedMatchingFunc(String ptype, String name, BiPredicate<Strin
798803

799804
/**
800805
* addNamedMatchingFunc add MatchingFunc by ptype RoleManager
806+
*
807+
* @param ptype the type of the role manager.
808+
* @param name the name of the matching function to be added.
809+
* @param fn the domain matching function.
810+
* @return whether the matching function was successfully added.
801811
*/
802812
public boolean addNamedDomainMatchingFunc(String ptype, String name, BiPredicate<String, String> fn) {
803813
if (rmMap.containsKey(ptype)) {
@@ -813,8 +823,14 @@ public boolean addNamedDomainMatchingFunc(String ptype, String name, BiPredicate
813823
}
814824

815825
/**
816-
* addNamedLinkConditionFunc Add condition function fn for Link userName->roleName,
826+
* addNamedLinkConditionFunc Add condition function fn for Link userName-&gt;roleName,
817827
* when fn returns true, Link is valid, otherwise invalid
828+
*
829+
* @param ptype the type of the role manager.
830+
* @param user the username for which the link condition is being added.
831+
* @param role the role associated with the user for which the condition is evaluated.
832+
* @param fn a function that takes an array of parameters (e.g., [user, role]) and returns a Boolean indicating the validity of the link.
833+
* @return whether the Link is valid.
818834
*/
819835
public boolean addNamedLinkConditionFunc(String ptype, String user, String role, Function<String[], Boolean> fn){
820836
if (condRmMap.containsKey(ptype)){
@@ -826,8 +842,15 @@ public boolean addNamedLinkConditionFunc(String ptype, String user, String role,
826842
}
827843

828844
/**
829-
* addNamedDomainLinkConditionFunc Add condition function fn for Link userName-> {roleName, domain},
845+
* addNamedDomainLinkConditionFunc Add condition function fn for Link userName-&gt; {roleName, domain},
830846
* when fn returns true, Link is valid, otherwise invalid
847+
*
848+
* @param ptype the type of the conditional role manager.
849+
* @param user the username for which the link condition is being added.
850+
* @param role the role associated with the user for which the condition is evaluated.
851+
* @param domain the domain associated with the role.
852+
* @param fn a function that takes an array of parameters (e.g., [user, role, domain]) and returns a Boolean indicating the validity of the link.
853+
* @return whether the Link is valid.
831854
*/
832855
public boolean addNamedDomainLinkConditionFunc(String ptype, String user, String role, String domain, Function<String[], Boolean> fn) {
833856
if (condRmMap.containsKey(ptype)){
@@ -839,7 +862,13 @@ public boolean addNamedDomainLinkConditionFunc(String ptype, String user, String
839862
}
840863

841864
/**
842-
* setNamedLinkConditionFuncParams Sets the parameters of the condition function fn for Link userName->roleName
865+
* setNamedLinkConditionFuncParams Sets the parameters of the condition function fn for Link userName-&gt;roleName
866+
*
867+
* @param ptype the type of the conditional role manager.
868+
* @param user the username for which the link condition parameters are being set.
869+
* @param role the role associated with the user for which the parameters are being configured.
870+
* @param params an array of parameters to be passed to the condition function.
871+
* @return whether the Link is valid.
843872
*/
844873
public boolean setNamedLinkConditionFuncParams(String ptype, String user, String role, String... params){
845874
if (condRmMap.containsKey(ptype)){
@@ -852,7 +881,14 @@ public boolean setNamedLinkConditionFuncParams(String ptype, String user, String
852881

853882
/**
854883
* setNamedDomainLinkConditionFuncParams Sets the parameters of the condition function fn
855-
* for Link userName->{roleName, domain}
884+
* for Link userName-&gt;{roleName, domain}
885+
*
886+
* @param ptype the type of the conditional role manager.
887+
* @param user the username for which the link condition parameters are being set.
888+
* @param role the role associated with the user for which the parameters are being configured.
889+
* @param domain the domain associated with the role and user.
890+
* @param params an array of parameters to be passed to the condition function, allowing customization of the condition logic.
891+
* @return whether the parameters were successfully set.
856892
*/
857893
public boolean setNamedDomainLinkConditionFuncParams(String ptype, String user, String role, String domain, String... params){
858894
if (condRmMap.containsKey(ptype)){
@@ -863,6 +899,14 @@ public boolean setNamedDomainLinkConditionFuncParams(String ptype, String user,
863899
return false;
864900
}
865901

902+
/***
903+
* getRTokens Retrieves request tokens and populates them into the provided parameters map.
904+
*
905+
* @param parameters a map to store the request tokens and their corresponding values.
906+
* @param rType the type of the request for which tokens are being retrieved, used to access the appropriate model.
907+
* @param rvals the request needs to be mediated, usually an array
908+
* of strings, can be class instances if ABAC is used.
909+
*/
866910
private void getRTokens(Map<String, Object> parameters, String rType, Object... rvals) {
867911
String[] requestTokens = model.model.get("r").get(rType).tokens;
868912
if(requestTokens.length != rvals.length) {
@@ -874,6 +918,14 @@ private void getRTokens(Map<String, Object> parameters, String rType, Object...
874918
}
875919
}
876920

921+
/***
922+
* getPTokens Retrieves policy tokens and populates them into the provided parameters map.
923+
*
924+
* @param parameters a map to store the policy tokens and their corresponding values.
925+
* @param pType the type of the policy for which tokens are being retrieved, used for context.
926+
* @param pvals a list of values corresponding to the policy tokens.
927+
* @param pTokens an array of tokens associated with the policy.
928+
*/
877929
private void getPTokens(Map<String, Object> parameters, String pType, List<String> pvals, String[] pTokens) {
878930
if (pTokens.length != pvals.size()) {
879931
throw new CasbinMatcherException("invalid policy size: expected " + pTokens.length +

src/main/java/org/casbin/jcasbin/main/DistributedEnforcer.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public DistributedEnforcer(String modelPath, String policyFile, boolean enableLo
101101
* AddPolicySelf provides a method for dispatcher to add authorization rules to the current policy.
102102
* The function returns the rules affected and error.
103103
*
104-
* @param shouldPersist
104+
* @param shouldPersist whether the changes should be persisted.
105105
* @param sec the section, "p" or "g".
106106
* @param ptype the policy type, "p", "p2", .. or "g", "g2", ..
107107
* @param rules the rules.
@@ -146,7 +146,7 @@ public List<List<String>> addPolicySelf(BooleanSupplier shouldPersist, String se
146146
* RemovePolicySelf provides a method for dispatcher to remove policies from current policy.
147147
* The function returns the rules affected and error.
148148
*
149-
* @param shouldPersist
149+
* @param shouldPersist whether the changes should be persisted.
150150
* @param sec the section, "p" or "g".
151151
* @param ptype the policy type, "p", "p2", .. or "g", "g2", ..
152152
* @param rules the rules.
@@ -184,7 +184,7 @@ public List<List<String>> removePolicySelf(BooleanSupplier shouldPersist, String
184184
* field filters can be specified.
185185
* The function returns the rules affected and error.
186186
*
187-
* @param shouldPersist
187+
* @param shouldPersist whether the changes should be persisted.
188188
* @param sec the section, "p" or "g".
189189
* @param ptype the policy type, "p", "p2", .. or "g", "g2", ..
190190
* @param fieldIndex the policy rule's start index to be matched.
@@ -220,7 +220,7 @@ public List<List<String>> removeFilteredPolicySelf(BooleanSupplier shouldPersist
220220
/**
221221
* ClearPolicySelf provides a method for dispatcher to clear all rules from the current policy.
222222
*
223-
* @param shouldPersist
223+
* @param shouldPersist whether the changes should be persisted.
224224
*/
225225
public void clearPolicySelf(BooleanSupplier shouldPersist) {
226226
if (shouldPersist.getAsBoolean()) {
@@ -239,7 +239,7 @@ public void clearPolicySelf(BooleanSupplier shouldPersist) {
239239
/**
240240
* UpdatePolicySelf provides a method for dispatcher to update an authorization rule from the current policy.
241241
*
242-
* @param shouldPersist
242+
* @param shouldPersist whether the changes should be persisted.
243243
* @param sec the section, "p" or "g".
244244
* @param ptype the policy type, "p", "p2", .. or "g", "g2", ..
245245
* @param oldRule the old rule.

src/main/java/org/casbin/jcasbin/model/Model.java

+9
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ private void loadSections(Config cfg) {
165165

166166
/**
167167
* SetLogger sets the model's logger.
168+
*
169+
* @param logger the logger to be set for the model.
168170
*/
169171
public void setLogger(Logger logger) {
170172
for (Map<String, Assertion> astMap : model.values()) {
@@ -177,6 +179,8 @@ public void setLogger(Logger logger) {
177179

178180
/**
179181
* NewModel creates an empty model.
182+
*
183+
* @return a new instance of the Model.
180184
*/
181185
public static Model newModel() {
182186
Model model = new Model();
@@ -188,6 +192,7 @@ public static Model newModel() {
188192
* NewModelFromString creates a model from a string which contains model text.
189193
*
190194
* @param path the path of the model file.
195+
* @return the model loaded from file.
191196
*/
192197
public static Model newModelFromFile(String path) {
193198
Model model = new Model();
@@ -199,6 +204,7 @@ public static Model newModelFromFile(String path) {
199204
* NewModelFromString creates a model from a string which contains model text.
200205
*
201206
* @param text the path of the file.
207+
* @return the model loaded from text.
202208
*/
203209
public static Model newModelFromString(String text) {
204210
Model model = new Model();
@@ -250,6 +256,9 @@ public void loadModelFromConfig(Config cfg) {
250256

251257
/**
252258
* hasSection checks if the section exists in the model.
259+
*
260+
* @param sec the section name to check, such as "p" or "g".
261+
* @return whether the section exists in the model.
253262
*/
254263
public boolean hasSection(String sec) {
255264
Map<String, Assertion> section = model.get(sec);

src/main/java/org/casbin/jcasbin/model/Policy.java

+8
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,12 @@ public boolean hasPolicies(String sec, String ptype, List<List<String>> rules) {
392392

393393
/**
394394
* buildIncrementalConditionalRoleLinks provides incremental build the role inheritance relations.
395+
*
396+
* @param condRmMap a map of conditional role managers used for role link management.
397+
* @param op the operation to perform, such as adding or removing role links.
398+
* @param sec the section of the policy, typically "g" for role inheritance.
399+
* @param ptype the policy type, which specifies the kind of roles being managed.
400+
* @param rules the rules that define the role links to be built.
395401
*/
396402
public void buildIncrementalConditionalRoleLinks(Map<String, ConditionalRoleManager> condRmMap, Model.PolicyOperations op, String sec, String ptype, List<List<String>> rules){
397403
if ("g".equals(sec) && condRmMap.containsKey(ptype)) {
@@ -401,6 +407,8 @@ public void buildIncrementalConditionalRoleLinks(Map<String, ConditionalRoleMana
401407

402408
/**
403409
* buildConditionalRoleLinks initializes the roles in RBAC.
410+
*
411+
* @param condRmMap a map of conditional role managers that manage the role links and their conditions.
404412
*/
405413
public void buildConditionalRoleLinks(Map<String, ConditionalRoleManager> condRmMap){
406414
printPolicy();

src/main/java/org/casbin/jcasbin/persist/Dispatcher.java

+19-15
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,30 @@
2222
*/
2323
public interface Dispatcher {
2424
/**
25-
* // AddPolicies adds policies rule to all instance.
26-
* @param sec
27-
* @param ptype
28-
* @param rules
25+
* AddPolicies adds policies rule to all instance.
26+
*
27+
* @param sec the section to which the policies belong, e.g., "p" or "g".
28+
* @param ptype the policy type, such as "p" for permissions or "g" for roles.
29+
* @param rules the list of policy rules to be added, where each rule is represented as a list of strings.
2930
*/
3031
void addPolicies(String sec, String ptype, List<List<String>> rules);
3132

3233
/**
3334
* RemovePolicies removes policies rule from all instance.
34-
* @param sec
35-
* @param ptype
36-
* @param rules
35+
*
36+
* @param sec the section from which to remove policies, e.g., "p" or "g".
37+
* @param ptype the policy type to remove, such as "p" or "g".
38+
* @param rules the list of policy rules to be removed, where each rule is represented as a list of strings.
3739
*/
3840
void removePolicies(String sec, String ptype, List<List<String>> rules);
3941

4042
/**
4143
* RemoveFilteredPolicy removes policy rules that match the filter from all instance.
42-
* @param sec
43-
* @param ptype
44-
* @param fieldIndex
45-
* @param fieldValues
44+
*
45+
* @param sec the section from which to remove policies, e.g., "p" or "g".
46+
* @param ptype the policy type to filter, such as "p" or "g".
47+
* @param fieldIndex the index of the field to filter on.
48+
* @param fieldValues the values to filter by for the specified field index.
4649
*/
4750
void removeFilteredPolicy(String sec, String ptype, int fieldIndex, String... fieldValues);
4851

@@ -53,10 +56,11 @@ public interface Dispatcher {
5356

5457
/**
5558
* UpdatePolicy updates policy rule from all instance.
56-
* @param sec
57-
* @param ptype
58-
* @param oldRule
59-
* @param newRule
59+
*
60+
* @param sec the section containing the policy, e.g., "p" or "g".
61+
* @param ptype the policy type to update, such as "p" or "g".
62+
* @param oldRule the existing policy rule to be updated, represented as a list of strings.
63+
* @param newRule the new policy rule that will replace the old one, represented as a list of strings.
6064
*/
6165
void updatePolicy(String sec, String ptype, List<String> oldRule, List<String> newRule);
6266
}

0 commit comments

Comments
 (0)