Skip to content

JSPWIKI-1210 Advanced access rules with AND, OR, NOT and parentheses - #655

Open
arturobernalg wants to merge 3 commits into
apache:masterfrom
arturobernalg:feature/JSPWIKI-1210-acl-rules
Open

arturobernalg wants to merge 3 commits into
apache:masterfrom
arturobernalg:feature/JSPWIKI-1210-acl-rules

Conversation

@arturobernalg

@arturobernalg arturobernalg commented Nov 21, 2026 •

Copy link
Copy Markdown
Member

This takes over #484 (JSPWIKI-1210). The first commit is the original work of Alex O'Ree, rebased on master. The next two rework it after the problems found in the review of #484 and in a second review of this change.

An access rule can now combine roles, groups and users, for example [{ALLOW edit Editors AND (Reviewers OR NOT Banned)}].

What changed on top of the first commit:

  • The advanced rules are kept by the AclImpl of the page, next to its entries, and no longer in a class that replaces the Acl. A page can mix simple and advanced rules in any order, and the rules of the same action add up, as the simple ones do. This fixes the lost simple rule and the "Not supported yet." error when saving a page. Parsing the same page again does not add its rules again.
  • DefaultAuthorizationManager grants a permission to the users that satisfy any rule that implies it, and denies it when none does. A page with only [{ALLOW edit Admin OR Editors}] is no longer readable by anonymous users, as with a simple rule.
  • A name counts as held only if the user has that role, group or user principal. The first version added the login name of the session, so an asserted name (a cookie) satisfied a rule.
  • AND, OR and NOT are read only in upper case. A rule without commas is advanced when one of them is a word of its own, or is next to a parenthesis. Names such as ANDY or ORACLE and lower case words stay names. A list with commas is always a simple rule, as before. A rule that does not parse is reported as an invalid access rule.
  • DefaultAclManager.printAcl writes the advanced rules too, and renaming a user profile changes the name in the advanced rules as it does in the entries.
  • A page restricted only by advanced rules is not notified to the subscribers by mail, as a page with a simple view rule is not.
  • The jspwiki.authZManager property and the protected engine field are removed, as nothing needs them now.

Cost and limits:

  • A rule without commas whose name has spaces and an upper case AND, OR or NOT inside it (for example a group called Sales OR Marketing) is now read as an advanced rule. I did not find such a rule in the default pages. With commas it stays a simple rule.
  • NOT is true for every user that does not hold the name, anonymous users included, and for a name that does not exist. Use Authenticated AND NOT Banned, not only NOT Banned, to grant to logged in users. The policy file still has to grant the permission.
  • Names with spaces cannot be used in an advanced rule.
  • As with a simple rule that is not valid, a rule that does not parse is shown as an error and is ignored, so a page whose only rule is not valid is not restricted.

Tests: new AdvancedAclAuthorizationTest with anonymous, asserted and authenticated sessions and wiki groups, new cases in DefaultAclManagerTest and DefaultSubscriptionManagerTest, and a stricter RuleParserTest. The whole jspwiki-main module passes (1222 tests). I also ran the war in Tomcat 10.1 with registered users and checked an advanced rule alone, a simple one before an advanced one, an advanced one before a simple one, and Authenticated AND NOT: anonymous users go to the login page, the allowed users view and edit, the others cannot edit, and the page text is shown.

spyhunter99 and others added 2 commits November 21, 2026 16:42
The advanced rules are kept by the AclImpl of the page, together with its entries, instead of
in a class that replaces the Acl. A page can mix simple and advanced rules in any order, and
the rules of the same action add up, as the simple ones do.

The AuthorizationManager grants a permission to the users that satisfy any rule that implies
it, and denies it when no rule does, so a page with only an advanced rule for edit is not
readable by anonymous users either. A name counts as held only when the user has the role,
group or user principal, so a name that is only asserted does not satisfy a rule.

AND, OR and NOT are read only in upper case, a comma cannot be mixed with them, and a rule that
does not parse is reported as an invalid access rule. printAcl writes the advanced rules too.

The jspwiki.authZManager property and the protected engine of the authorization manager are
dropped, as nothing needs them now.
A list of names with commas is always a simple rule, as it was before, so a name with an upper
case AND, OR or NOT inside it does not turn the whole line into an advanced rule that fails.
AND, OR and NOT next to parentheses are operators, as the parser reads them.

Parsing the same page again does not add its advanced rules again. A page that is restricted
only by advanced rules is not notified to the subscribers. Renaming a user profile changes the
name in the advanced rules too.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants