spring-projects / spring-projects/spring-security
DefaultPermissionGrantingStrategy.isGranted(...) optimization
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 9.6k
- Forks
- 6.3k
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 52
Description
Expected Behavior
DefaultPermissionGrantingStrategy.isGranted(...) should check if the ACL entries collection is empty before looping.
Current Behavior
Unnecessary nested loops over permission and sids when the ACL has no entries.
This is a minor optimization. But it's worth it if you imagine a scenario with Hierarchical roles + ACL with inheritance + @PreFilter / @PostFilter
Context
Spring Security 6.5.6
DefaultPermissionGrantingStrategy line 75
Actual code
public boolean isGranted(Acl acl, List<Permission> permission, List<Sid> sids, boolean administrativeMode)
throws NotFoundException {
List<AccessControlEntry> aces = acl.getEntries();
AccessControlEntry firstRejection = null;
for (Permission p : permission) {
...
}
Suggested patch
public boolean isGranted(Acl acl, List<Permission> permission, List<Sid> sids, boolean administrativeMode)
throws NotFoundException {
List<AccessControlEntry> aces = acl.getEntries();
AccessControlEntry firstRejection = null;
// null + empty check
if (aces != null && !aces.isEmpty())
for (Permission p : permission) {
...
}
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at DefaultPermissionGrantingStrategy.isGranted(...) around line 75 and inspect how acl.getEntries() is used before the permission and SID loops. Verify the empty-entry case, including the proposed null check, and add or update coverage so the method avoids unnecessary looping while preserving existing permission behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- authorization, security
- Issue type
- Refactor
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100