Skip to content

Commit

Permalink
enh: make assertAuthorized() method more readable
Browse files Browse the repository at this point in the history
fixes #1057
  • Loading branch information
lprimak committed Sep 3, 2023
1 parent 711ffe3 commit c92b82a
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,12 @@ public void assertAuthorized(Annotation a) throws AuthorizationException {
if (Logical.OR.equals(rpAnnotation.logical())) {
// Avoid processing exceptions unnecessarily - "delay" throwing the exception by calling hasRole first
boolean hasAtLeastOnePermission = false;
for (String permission : perms) if (getSubject().isPermitted(permission)) hasAtLeastOnePermission = true;
for (String permission : perms) {
if (getSubject().isPermitted(permission)) {
hasAtLeastOnePermission = true;
break;
}
}
// Cause the exception if none of the role match, note that the exception message will be a bit misleading
if (!hasAtLeastOnePermission) getSubject().checkPermission(perms[0]);

Expand Down

0 comments on commit c92b82a

Please sign in to comment.