[JENKINS-61465] Make checkAnyPermission work on non-AccessControlled

This commit is contained in:
Daniel Beck committed 2020-03-13 12:31:45 +01:00
1 parent a79101ce54
commit 7259d8698c
3 files changed
+114

No files matched your search

+25
View File
@@ -1172,6 +1172,31 @@ public class Functions {
ac.checkAnyPermission(permissions);
}
/**
* This version is so that the 'checkAnyPermission' on {@code layout.jelly}
* degrades gracefully if "it" is not an {@link AccessControlled} object.
* Otherwise it will perform no check and that problem is hard to notice.
*/
public static void checkAnyPermission(Object object, Permission[] permissions) throws IOException, ServletException {
if (permissions == null || permissions.length == 0) {
return;
}
if (object instanceof AccessControlled)
checkAnyPermission((AccessControlled) object, permissions);
else {
List<Ancestor> ancs = Stapler.getCurrentRequest().getAncestors();
for(Ancestor anc : Iterators.reverse(ancs)) {
Object o = anc.getObject();
if (o instanceof AccessControlled) {
checkAnyPermission((AccessControlled) o, permissions);
return;
}
}
checkAnyPermission(Jenkins.get(), permissions);
}
}
private static class Tag implements Comparable<Tag> {
double ordinal;
String hierarchy;