Skip to content

Commit a449d6c

Browse files
Metavirulenteleftherias
authored andcommitted
extract permission mask comparison for subclasses to override
1 parent 6ad328f commit a449d6c

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

acl/src/main/java/org/springframework/security/acls/domain/DefaultPermissionGrantingStrategy.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -87,7 +87,7 @@ public boolean isGranted(Acl acl, List<Permission> permission, List<Sid> sids,
8787

8888
for (AccessControlEntry ace : aces) {
8989

90-
if ((ace.getPermission().getMask() == p.getMask())
90+
if (comparePermissionMasks(ace, p)
9191
&& ace.getSid().equals(sid)) {
9292
// Found a matching ACE, so its authorization decision will
9393
// prevail
@@ -142,4 +142,25 @@ public boolean isGranted(Acl acl, List<Permission> permission, List<Sid> sids,
142142
}
143143
}
144144

145+
/**
146+
* Compares an ACE Permission to the given Permission.
147+
* By default, we compare the Permission masks for exact match.
148+
* Subclasses of this strategy can override this behavior and implement
149+
* more sophisticated comparisons, e.g. a bitwise comparison for ACEs that grant access.
150+
* <pre>{@code
151+
* if (ace.isGranting() && p.getMask() != 0) {
152+
* return (ace.getPermission().getMask() & p.getMask()) != 0;
153+
* } else {
154+
* return ace.getPermission().getMask() == p.getMask();
155+
* }
156+
* }</pre>
157+
*
158+
* @param ace the ACE from the Acl holding the mask.
159+
* @param p the Permission we are checking against.
160+
* @return true, if the respective masks are considered to be equal.
161+
*/
162+
protected boolean comparePermissionMasks(AccessControlEntry ace, Permission p) {
163+
return ace.getPermission().getMask() == p.getMask();
164+
}
165+
145166
}

0 commit comments

Comments
 (0)