From 60d2b06c61c868995893964436f3cf18e1ed06d3 Mon Sep 17 00:00:00 2001 From: Markus Winter Date: Thu, 2 Jan 2025 15:20:05 +0100 Subject: [PATCH] Migration to Jakarta EE --- pom.xml | 10 ++--- .../RoleBasedAuthorizationStrategy.java | 42 ++++++++++--------- .../rolestrategy/RoleStrategyConfig.java | 12 +++--- .../RoleBasedProjectNamingStrategy.java | 6 +-- 4 files changed, 36 insertions(+), 34 deletions(-) diff --git a/pom.xml b/pom.xml index 27ec4878..11ce95c0 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.jenkins-ci.plugins plugin - 4.88 + 5.4 @@ -49,9 +49,9 @@ - 2.440 999999-SNAPSHOT - ${jenkins.base}.3 + 2.479 + ${jenkins.baseline}.1 jenkinsci/${project.artifactId}-plugin 10.20.1 640 @@ -61,8 +61,8 @@ io.jenkins.tools.bom - bom-${jenkins.base}.x - 3221.ve8f7b_fdd149d + bom-${jenkins.baseline}.x + 3850.vb_c5319efa_e29 pom import diff --git a/src/main/java/com/michelin/cio/hudson/plugins/rolestrategy/RoleBasedAuthorizationStrategy.java b/src/main/java/com/michelin/cio/hudson/plugins/rolestrategy/RoleBasedAuthorizationStrategy.java index e5ea1c99..547adcd6 100644 --- a/src/main/java/com/michelin/cio/hudson/plugins/rolestrategy/RoleBasedAuthorizationStrategy.java +++ b/src/main/java/com/michelin/cio/hudson/plugins/rolestrategy/RoleBasedAuthorizationStrategy.java @@ -60,6 +60,8 @@ import hudson.security.SecurityRealm; import hudson.security.SidACL; import hudson.util.FormValidation; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.Writer; import java.util.ArrayList; @@ -78,8 +80,6 @@ import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; import java.util.stream.Collectors; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletResponse; import jenkins.model.Jenkins; import net.sf.json.JSONObject; import org.acegisecurity.acls.sid.PrincipalSid; @@ -91,8 +91,8 @@ import org.kohsuke.accmod.restrictions.NoExternalUse; import org.kohsuke.stapler.QueryParameter; import org.kohsuke.stapler.Stapler; -import org.kohsuke.stapler.StaplerRequest; -import org.kohsuke.stapler.StaplerResponse; +import org.kohsuke.stapler.StaplerRequest2; +import org.kohsuke.stapler.StaplerResponse2; import org.kohsuke.stapler.interceptor.RequirePOST; import org.kohsuke.stapler.verb.GET; import org.kohsuke.stapler.verb.POST; @@ -431,7 +431,7 @@ public void doAddTemplate(@QueryParameter(required = true) String name, Set permissionSet = PermissionHelper.fromStrings(permissionList, true); PermissionTemplate template = new PermissionTemplate(permissionSet, name); if (!overwrite && hasPermissionTemplate(name)) { - Stapler.getCurrentResponse().sendError(HttpServletResponse.SC_BAD_REQUEST, "A template with name " + name + " already exists."); + Stapler.getCurrentResponse2().sendError(HttpServletResponse.SC_BAD_REQUEST, "A template with name " + name + " already exists."); return; } permissionTemplates.put(name, template); @@ -518,7 +518,9 @@ public void doAddRole(@QueryParameter(required = true) String type, if (RoleBasedAuthorizationStrategy.PROJECT.equals(type) && templateName != null) { if (!hasPermissionTemplate(template)) { - Stapler.getCurrentResponse().sendError(HttpServletResponse.SC_BAD_REQUEST, "A template with name " + template + " doesn't exists."); + Stapler.getCurrentResponse2().sendError( + HttpServletResponse.SC_BAD_REQUEST, "A template with name " + template + " doesn't exists." + ); return; } role.setTemplateName(templateName); @@ -844,8 +846,8 @@ public void doGetTemplate(@QueryParameter(required = true) String name) throws I responseJson.put("permissionIds", permissionsMap); responseJson.put("isUsed", template.isUsed()); } - Stapler.getCurrentResponse().setContentType("application/json;charset=UTF-8"); - Writer writer = Stapler.getCurrentResponse().getCompressedWriter(Stapler.getCurrentRequest()); + Stapler.getCurrentResponse2().setContentType("application/json;charset=UTF-8"); + Writer writer = Stapler.getCurrentResponse2().getWriter(); responseJson.write(writer); writer.close(); @@ -907,8 +909,8 @@ public void doGetRole(@QueryParameter(required = true) String type, } } - Stapler.getCurrentResponse().setContentType("application/json;charset=UTF-8"); - Writer writer = Stapler.getCurrentResponse().getCompressedWriter(Stapler.getCurrentRequest()); + Stapler.getCurrentResponse2().setContentType("application/json;charset=UTF-8"); + Writer writer = Stapler.getCurrentResponse2().getWriter(); responseJson.write(writer); writer.close(); } @@ -948,8 +950,8 @@ public void doGetAllRoles(@QueryParameter(fixEmpty = true) String type) throws I responseJson.put(grantedRole.getKey().getName(), grantedRole.getValue()); } - Stapler.getCurrentResponse().setContentType("application/json;charset=UTF-8"); - Writer writer = Stapler.getCurrentResponse().getCompressedWriter(Stapler.getCurrentRequest()); + Stapler.getCurrentResponse2().setContentType("application/json;charset=UTF-8"); + Writer writer = Stapler.getCurrentResponse2().getWriter(); responseJson.write(writer); writer.close(); } @@ -974,9 +976,9 @@ public void doGetMatchingJobs(@QueryParameter(required = true) String pattern, JSONObject responseJson = new JSONObject(); responseJson.put("matchingJobs", matchingItems); responseJson.put("itemCount", itemCount); - StaplerResponse response = Stapler.getCurrentResponse(); + StaplerResponse2 response = Stapler.getCurrentResponse2(); response.setContentType("application/json;charset=UTF-8"); - Writer writer = response.getCompressedWriter(Stapler.getCurrentRequest()); + Writer writer = response.getWriter(); responseJson.write(writer); writer.close(); } @@ -1001,9 +1003,9 @@ public void doGetMatchingAgents(@QueryParameter(required = true) String pattern, JSONObject responseJson = new JSONObject(); responseJson.put("matchingAgents", matchingAgents); responseJson.put("agentCount", agentCount); - StaplerResponse response = Stapler.getCurrentResponse(); + StaplerResponse2 response = Stapler.getCurrentResponse2(); response.setContentType("application/json;charset=UTF-8"); - Writer writer = response.getCompressedWriter(Stapler.getCurrentRequest()); + Writer writer = response.getWriter(); responseJson.write(writer); writer.close(); } @@ -1269,7 +1271,7 @@ public FormValidation doCheckForWhitespace(@QueryParameter String value) { */ @RequirePOST @Restricted(NoExternalUse.class) - public void doRolesSubmit(StaplerRequest req, StaplerResponse rsp) throws ServletException, IOException { + public void doRolesSubmit(StaplerRequest2 req, StaplerResponse2 rsp) throws ServletException, IOException { checkAdminPerm(); req.setCharacterEncoding("UTF-8"); @@ -1285,7 +1287,7 @@ public void doRolesSubmit(StaplerRequest req, StaplerResponse rsp) throws Servle */ @RequirePOST @Restricted(NoExternalUse.class) - public void doAssignSubmit(StaplerRequest req, StaplerResponse rsp) throws ServletException, IOException { + public void doAssignSubmit(StaplerRequest2 req, StaplerResponse2 rsp) throws ServletException, IOException { checkAdminPerm(); req.setCharacterEncoding("UTF-8"); @@ -1330,7 +1332,7 @@ public void doAssignSubmit(StaplerRequest req, StaplerResponse rsp) throws Servl */ @RequirePOST @Restricted(NoExternalUse.class) - public void doTemplatesSubmit(StaplerRequest req, StaplerResponse rsp) throws ServletException, IOException { + public void doTemplatesSubmit(StaplerRequest2 req, StaplerResponse2 rsp) throws ServletException, IOException { checkAdminPerm(); req.setCharacterEncoding("UTF-8"); JSONObject json = req.getSubmittedForm(); @@ -1364,7 +1366,7 @@ public void doTemplatesSubmit(StaplerRequest req, StaplerResponse rsp) throws Se * {@link AuthorizationStrategy} object. */ @Override - public AuthorizationStrategy newInstance(StaplerRequest req, JSONObject formData) { + public AuthorizationStrategy newInstance(StaplerRequest2 req, JSONObject formData) { AuthorizationStrategy oldStrategy = instance().getAuthorizationStrategy(); RoleBasedAuthorizationStrategy strategy; diff --git a/src/main/java/com/michelin/cio/hudson/plugins/rolestrategy/RoleStrategyConfig.java b/src/main/java/com/michelin/cio/hudson/plugins/rolestrategy/RoleStrategyConfig.java index 1e3d935c..f6e10a78 100644 --- a/src/main/java/com/michelin/cio/hudson/plugins/rolestrategy/RoleStrategyConfig.java +++ b/src/main/java/com/michelin/cio/hudson/plugins/rolestrategy/RoleStrategyConfig.java @@ -35,13 +35,13 @@ import hudson.security.AuthorizationStrategy; import hudson.security.Permission; import hudson.util.FormApply; +import jakarta.servlet.ServletException; import java.io.IOException; -import javax.servlet.ServletException; import jenkins.model.Jenkins; import org.kohsuke.accmod.Restricted; import org.kohsuke.accmod.restrictions.NoExternalUse; -import org.kohsuke.stapler.StaplerRequest; -import org.kohsuke.stapler.StaplerResponse; +import org.kohsuke.stapler.StaplerRequest2; +import org.kohsuke.stapler.StaplerResponse2; import org.kohsuke.stapler.interceptor.RequirePOST; /** @@ -149,7 +149,7 @@ public AuthorizationStrategy getStrategy() { */ @RequirePOST @Restricted(NoExternalUse.class) - public void doRolesSubmit(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException { + public void doRolesSubmit(StaplerRequest2 req, StaplerResponse2 rsp) throws IOException, ServletException { Jenkins.get().checkPermission(Jenkins.ADMINISTER); // Let the strategy descriptor handle the form RoleBasedAuthorizationStrategy.DESCRIPTOR.doRolesSubmit(req, rsp); @@ -162,7 +162,7 @@ public void doRolesSubmit(StaplerRequest req, StaplerResponse rsp) throws IOExce */ @RequirePOST @Restricted(NoExternalUse.class) - public void doTemplatesSubmit(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException { + public void doTemplatesSubmit(StaplerRequest2 req, StaplerResponse2 rsp) throws IOException, ServletException { Jenkins.get().checkPermission(Jenkins.ADMINISTER); // Let the strategy descriptor handle the form RoleBasedAuthorizationStrategy.DESCRIPTOR.doTemplatesSubmit(req, rsp); @@ -186,7 +186,7 @@ public void doTemplatesSubmit(StaplerRequest req, StaplerResponse rsp) throws IO */ @RequirePOST @Restricted(NoExternalUse.class) - public void doAssignSubmit(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException { + public void doAssignSubmit(StaplerRequest2 req, StaplerResponse2 rsp) throws IOException, ServletException { Jenkins.get().checkPermission(Jenkins.ADMINISTER); // Let the strategy descriptor handle the form RoleBasedAuthorizationStrategy.DESCRIPTOR.doAssignSubmit(req, rsp); diff --git a/src/main/java/org/jenkinsci/plugins/rolestrategy/RoleBasedProjectNamingStrategy.java b/src/main/java/org/jenkinsci/plugins/rolestrategy/RoleBasedProjectNamingStrategy.java index a2103d51..6b436037 100644 --- a/src/main/java/org/jenkinsci/plugins/rolestrategy/RoleBasedProjectNamingStrategy.java +++ b/src/main/java/org/jenkinsci/plugins/rolestrategy/RoleBasedProjectNamingStrategy.java @@ -28,7 +28,7 @@ import org.apache.commons.lang3.StringUtils; import org.kohsuke.stapler.DataBoundConstructor; import org.kohsuke.stapler.Stapler; -import org.kohsuke.stapler.StaplerRequest; +import org.kohsuke.stapler.StaplerRequest2; import org.springframework.security.core.Authentication; import org.springframework.security.core.GrantedAuthority; @@ -52,14 +52,14 @@ public RoleBasedProjectNamingStrategy(boolean forceExistingJobs) { @Override public void checkName(String name) throws Failure { - StaplerRequest request = Stapler.getCurrentRequest(); + StaplerRequest2 request = Stapler.getCurrentRequest2(); // Workaround until JENKINS-68602 is implemented // This works only for requests via the UI. In case this method is called due to // job creation request via the CLI, we have no way to determine the // the parent so just check the name String parentName = ""; if (request != null) { - ItemGroup i = Stapler.getCurrentRequest().findAncestorObject(ItemGroup.class); + ItemGroup i = Stapler.getCurrentRequest2().findAncestorObject(ItemGroup.class); parentName = i.getFullName(); } checkName(parentName, name);