Skip to content

Commit 184e9d2

Browse files
authored
Removing throws IOException, ServletException from most Permission-related methods in Functions; deleting adminCheck (#10844)
2 parents 83fa8cc + 2b1a5d4 commit 184e9d2

File tree

2 files changed

+7
-65
lines changed

2 files changed

+7
-65
lines changed

core/src/main/java/hudson/Functions.java

Lines changed: 7 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
import hudson.model.Describable;
4242
import hudson.model.Descriptor;
4343
import hudson.model.DescriptorVisibilityFilter;
44-
import hudson.model.Hudson;
4544
import hudson.model.Item;
4645
import hudson.model.ItemGroup;
4746
import hudson.model.Items;
@@ -97,11 +96,9 @@
9796
import hudson.views.MyViewsTabBar;
9897
import hudson.views.ViewsTabBar;
9998
import hudson.widgets.RenderOnDemandClosure;
100-
import io.jenkins.servlet.ServletExceptionWrapper;
10199
import io.jenkins.servlet.http.CookieWrapper;
102100
import io.jenkins.servlet.http.HttpServletRequestWrapper;
103101
import io.jenkins.servlet.http.HttpServletResponseWrapper;
104-
import jakarta.servlet.ServletException;
105102
import jakarta.servlet.http.Cookie;
106103
import jakarta.servlet.http.HttpServletRequest;
107104
import jakarta.servlet.http.HttpServletResponse;
@@ -190,8 +187,6 @@
190187
import org.kohsuke.stapler.Stapler;
191188
import org.kohsuke.stapler.StaplerRequest;
192189
import org.kohsuke.stapler.StaplerRequest2;
193-
import org.kohsuke.stapler.StaplerResponse;
194-
import org.kohsuke.stapler.StaplerResponse2;
195190
import org.springframework.security.access.AccessDeniedException;
196191

197192
/**
@@ -921,11 +916,11 @@ public static String htmlAttributeEscape(String text) {
921916
return buf.toString();
922917
}
923918

924-
public static void checkPermission(Permission permission) throws IOException, ServletException {
919+
public static void checkPermission(Permission permission) {
925920
checkPermission(Jenkins.get(), permission);
926921
}
927922

928-
public static void checkPermission(AccessControlled object, Permission permission) throws IOException, ServletException {
923+
public static void checkPermission(AccessControlled object, Permission permission) {
929924
if (permission != null) {
930925
object.checkPermission(permission);
931926
}
@@ -936,7 +931,7 @@ public static void checkPermission(AccessControlled object, Permission permissio
936931
* degrades gracefully if "it" is not an {@link AccessControlled} object.
937932
* Otherwise it will perform no check and that problem is hard to notice.
938933
*/
939-
public static void checkPermission(Object object, Permission permission) throws IOException, ServletException {
934+
public static void checkPermission(Object object, Permission permission) {
940935
if (permission == null)
941936
return;
942937

@@ -961,15 +956,15 @@ public static void checkPermission(Object object, Permission permission) throws
961956
* @param permission
962957
* If null, returns true. This defaulting is convenient in making the use of this method terse.
963958
*/
964-
public static boolean hasPermission(Permission permission) throws IOException, ServletException {
959+
public static boolean hasPermission(Permission permission) {
965960
return hasPermission(Jenkins.get(), permission);
966961
}
967962

968963
/**
969964
* This version is so that the 'hasPermission' can degrade gracefully
970965
* if "it" is not an {@link AccessControlled} object.
971966
*/
972-
public static boolean hasPermission(Object object, Permission permission) throws IOException, ServletException {
967+
public static boolean hasPermission(Object object, Permission permission) {
973968
if (permission == null)
974969
return true;
975970
if (object instanceof AccessControlled)
@@ -986,36 +981,6 @@ public static boolean hasPermission(Object object, Permission permission) throws
986981
}
987982
}
988983

989-
/**
990-
* @since 2.475
991-
*/
992-
public static void adminCheck(StaplerRequest2 req, StaplerResponse2 rsp, Object required, Permission permission) throws IOException, ServletException {
993-
// this is legacy --- all views should be eventually converted to
994-
// the permission based model.
995-
if (required != null && !Hudson.adminCheck(StaplerRequest.fromStaplerRequest2(req), StaplerResponse.fromStaplerResponse2(rsp))) {
996-
// check failed. commit the FORBIDDEN response, then abort.
997-
rsp.setStatus(HttpServletResponse.SC_FORBIDDEN);
998-
rsp.getOutputStream().close();
999-
throw new ServletException("Unauthorized access");
1000-
}
1001-
1002-
// make sure the user owns the necessary permission to access this page.
1003-
if (permission != null)
1004-
checkPermission(permission);
1005-
}
1006-
1007-
/**
1008-
* @deprecated use {@link #adminCheck(StaplerRequest2, StaplerResponse2, Object, Permission)}
1009-
*/
1010-
@Deprecated
1011-
public static void adminCheck(StaplerRequest req, StaplerResponse rsp, Object required, Permission permission) throws IOException, javax.servlet.ServletException {
1012-
try {
1013-
adminCheck(StaplerRequest.toStaplerRequest2(req), StaplerResponse.toStaplerResponse2(rsp), required, permission);
1014-
} catch (ServletException e) {
1015-
throw ServletExceptionWrapper.fromJakartaServletException(e);
1016-
}
1017-
}
1018-
1019984
/**
1020985
* Infers the hudson installation URL from the given request.
1021986
*
@@ -1298,7 +1263,7 @@ public static boolean hasAnyPermission(AccessControlled ac, Permission[] permiss
12981263
*
12991264
* @since 2.238
13001265
*/
1301-
public static boolean hasAnyPermission(Object object, Permission[] permissions) throws IOException, ServletException {
1266+
public static boolean hasAnyPermission(Object object, Permission[] permissions) {
13021267
if (permissions == null || permissions.length == 0) {
13031268
return true;
13041269
}
@@ -1336,7 +1301,7 @@ public static void checkAnyPermission(AccessControlled ac, Permission[] permissi
13361301
* degrades gracefully if "it" is not an {@link AccessControlled} object.
13371302
* Otherwise it will perform no check and that problem is hard to notice.
13381303
*/
1339-
public static void checkAnyPermission(Object object, Permission[] permissions) throws IOException, ServletException {
1304+
public static void checkAnyPermission(Object object, Permission[] permissions) {
13401305
if (permissions == null || permissions.length == 0) {
13411306
return;
13421307
}

core/src/main/java/hudson/model/Hudson.java

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
import io.jenkins.servlet.ServletExceptionWrapper;
4343
import jakarta.servlet.ServletContext;
4444
import jakarta.servlet.ServletException;
45-
import jakarta.servlet.http.HttpServletResponse;
4645
import java.io.File;
4746
import java.io.IOException;
4847
import java.text.NumberFormat;
@@ -51,7 +50,6 @@
5150
import jenkins.model.Jenkins;
5251
import org.jvnet.hudson.reactor.ReactorException;
5352
import org.kohsuke.stapler.QueryParameter;
54-
import org.kohsuke.stapler.Stapler;
5553
import org.kohsuke.stapler.StaplerRequest;
5654
import org.kohsuke.stapler.StaplerResponse;
5755
import org.kohsuke.stapler.interceptor.RequirePOST;
@@ -293,27 +291,6 @@ public static boolean isDarwin() {
293291
return Platform.isDarwin();
294292
}
295293

296-
/**
297-
* @deprecated since 2007-12-18.
298-
* Use {@link #checkPermission(hudson.security.Permission)}
299-
*/
300-
@Deprecated
301-
public static boolean adminCheck() throws IOException {
302-
return adminCheck(Stapler.getCurrentRequest(), Stapler.getCurrentResponse());
303-
}
304-
305-
/**
306-
* @deprecated since 2007-12-18.
307-
* Use {@link #checkPermission(hudson.security.Permission)}
308-
*/
309-
@Deprecated
310-
public static boolean adminCheck(StaplerRequest req, StaplerResponse rsp) throws IOException {
311-
if (isAdmin(req)) return true;
312-
313-
rsp.sendError(HttpServletResponse.SC_FORBIDDEN);
314-
return false;
315-
}
316-
317294
/**
318295
* Checks if the current user (for which we are processing the current request)
319296
* has the admin access.

0 commit comments

Comments
 (0)