Skip to content

Commit 16b32bc

Browse files
jglickuhafner
authored andcommitted
Check either Acegi or Spring Security version of AccessDeniedException, or AccessDeniedException2 or AccessDeniedException3
1 parent af5fdc8 commit 16b32bc

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/main/java/io/jenkins/plugins/util/JenkinsFacade.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import java.util.Set;
77
import java.util.stream.Collectors;
88

9-
import org.acegisecurity.AccessDeniedException;
109
import org.apache.commons.lang3.StringUtils;
1110

1211
import org.kohsuke.stapler.Stapler;
@@ -91,8 +90,12 @@ public boolean hasPermission(final Permission permission) {
9190
try {
9291
return Optional.ofNullable(getJenkins().getItemByFullName(name, Job.class));
9392
}
94-
catch (AccessDeniedException ignore) {
95-
return Optional.empty();
93+
catch (RuntimeException x) { // TODO switch to simple catch (AccessDeniedException) when baseline includes Spring Security
94+
if (x.getClass().getSimpleName().startsWith("AccessDeniedException")) {
95+
return Optional.empty();
96+
} else {
97+
throw x;
98+
}
9699
}
97100
}
98101

@@ -108,10 +111,13 @@ public boolean hasPermission(final Permission permission) {
108111
try {
109112
return Optional.ofNullable(Run.fromExternalizableId(id));
110113
}
111-
catch (AccessDeniedException ignore) {
112-
// ignore
114+
catch (RuntimeException x) { // TODO switch to simple catch (AccessDeniedException) when baseline includes Spring Security
115+
if (x.getClass().getSimpleName().startsWith("AccessDeniedException")) {
116+
return Optional.empty();
117+
} else {
118+
throw x;
119+
}
113120
}
114-
return Optional.empty();
115121
}
116122

117123
/**

0 commit comments

Comments
 (0)