|
1 | 1 | /* |
2 | | - * Copyright 2002-2016 the original author or authors. |
| 2 | + * Copyright 2002-2018 the original author or authors. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * 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, |
87 | 87 |
|
88 | 88 | for (AccessControlEntry ace : aces) { |
89 | 89 |
|
90 | | - if ((ace.getPermission().getMask() == p.getMask()) |
| 90 | + if (comparePermissionMasks(ace, p) |
91 | 91 | && ace.getSid().equals(sid)) { |
92 | 92 | // Found a matching ACE, so its authorization decision will |
93 | 93 | // prevail |
@@ -142,4 +142,25 @@ public boolean isGranted(Acl acl, List<Permission> permission, List<Sid> sids, |
142 | 142 | } |
143 | 143 | } |
144 | 144 |
|
| 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 | + |
145 | 166 | } |
0 commit comments