From 4028bd5c2af66b48bae03409170eaf821ab87fed Mon Sep 17 00:00:00 2001 From: Mark Waite Date: Thu, 10 Oct 2024 21:20:35 -0600 Subject: [PATCH 1/2] Require Jenkins 2.479.1 or newer Use Jakarta EE 9 and Spring Security 6.x instead of Java EE 8 and Spring Security 5.x. --- pom.xml | 7 ++++--- .../authorizeproject/AuthorizeProjectProperty.java | 9 +++++---- .../authorizeproject/AuthorizeProjectStrategy.java | 4 ++-- .../AuthorizeProjectStrategyDescriptor.java | 4 ++-- .../authorizeproject/AuthorizeProjectUtil.java | 4 ++-- .../ConfigurationPermissionEnforcer.java | 4 ++-- .../GlobalQueueItemAuthenticator.java | 8 ++++---- .../ProjectQueueItemAuthenticator.java | 7 ++++--- .../strategy/SpecificUsersAuthorizationStrategy.java | 6 +++--- .../strategy/SystemAuthorizationStrategy.java | 6 +++--- .../ProjectQueueItemAuthenticatorTest.java | 11 +++++++---- .../SpecificUsersAuthorizationStrategyTest.java | 4 ++-- .../strategy/SystemAuthorizationStrategyTest.java | 4 ++-- 13 files changed, 42 insertions(+), 36 deletions(-) diff --git a/pom.xml b/pom.xml index a5de5e3..7844fe3 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.jenkins-ci.plugins plugin - 4.88 + 5.5 @@ -33,8 +33,9 @@ 1.8.2 -SNAPSHOT jenkinsci/authorize-project-plugin - 2.452 - ${jenkins.baseline}.4 + + 2.479 + ${jenkins.baseline}.1 Max Low false diff --git a/src/main/java/org/jenkinsci/plugins/authorizeproject/AuthorizeProjectProperty.java b/src/main/java/org/jenkinsci/plugins/authorizeproject/AuthorizeProjectProperty.java index 63ab367..b45e33f 100644 --- a/src/main/java/org/jenkinsci/plugins/authorizeproject/AuthorizeProjectProperty.java +++ b/src/main/java/org/jenkinsci/plugins/authorizeproject/AuthorizeProjectProperty.java @@ -40,12 +40,12 @@ import hudson.model.JobPropertyDescriptor; import hudson.model.Queue; import hudson.util.FormApply; +import jakarta.servlet.ServletException; import java.io.IOException; import java.util.Collection; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; -import javax.servlet.ServletException; import jenkins.model.Jenkins; import jenkins.model.TransientActionFactory; import net.sf.json.JSONObject; @@ -55,7 +55,7 @@ import org.kohsuke.accmod.restrictions.NoExternalUse; import org.kohsuke.stapler.DataBoundConstructor; import org.kohsuke.stapler.HttpResponse; -import org.kohsuke.stapler.StaplerRequest; +import org.kohsuke.stapler.StaplerRequest2; import org.kohsuke.stapler.interceptor.RequirePOST; /** @@ -139,7 +139,7 @@ public static void setStrategyCritical() { * {@inheritDoc} */ @Override - public JobProperty reconfigure(StaplerRequest req, JSONObject form) throws Descriptor.FormException { + public JobProperty reconfigure(StaplerRequest2 req, JSONObject form) throws Descriptor.FormException { // This is called when the job configuration is submitted. // authorize-project is preserved in job configuration pages. // It is updated via AuthorizationAction instead. @@ -284,7 +284,8 @@ public String getIconClassName() { @RequirePOST @NonNull @Restricted(NoExternalUse.class) - public synchronized HttpResponse doAuthorize(@NonNull StaplerRequest req) throws IOException, ServletException { + public synchronized HttpResponse doAuthorize(@NonNull StaplerRequest2 req) + throws IOException, ServletException { job.checkPermission(Job.CONFIGURE); JSONObject json = req.getSubmittedForm(); JSONObject o = json.optJSONObject(getPropertyDescriptor().getJsonSafeClassName()); diff --git a/src/main/java/org/jenkinsci/plugins/authorizeproject/AuthorizeProjectStrategy.java b/src/main/java/org/jenkinsci/plugins/authorizeproject/AuthorizeProjectStrategy.java index eba44c4..b0b3979 100644 --- a/src/main/java/org/jenkinsci/plugins/authorizeproject/AuthorizeProjectStrategy.java +++ b/src/main/java/org/jenkinsci/plugins/authorizeproject/AuthorizeProjectStrategy.java @@ -42,7 +42,7 @@ import org.acegisecurity.AccessDeniedException; import org.acegisecurity.Authentication; import org.kohsuke.stapler.Stapler; -import org.kohsuke.stapler.StaplerRequest; +import org.kohsuke.stapler.StaplerRequest2; /** * Extension point to define a new strategy to authorize builds configured in project configuration pages. @@ -182,7 +182,7 @@ private void checkUnsecuredConfiguration() throws ObjectStreamException { // It may not be allowed even if the user is an administrator of the job. return; } - StaplerRequest request = Stapler.getCurrentRequest(); + StaplerRequest2 request = Stapler.getCurrentRequest2(); AccessControlled context = (request != null) ? request.findAncestorObject(AccessControlled.class) : null; if (context == null) { context = Jenkins.get(); diff --git a/src/main/java/org/jenkinsci/plugins/authorizeproject/AuthorizeProjectStrategyDescriptor.java b/src/main/java/org/jenkinsci/plugins/authorizeproject/AuthorizeProjectStrategyDescriptor.java index ec3eb0a..569b4c6 100644 --- a/src/main/java/org/jenkinsci/plugins/authorizeproject/AuthorizeProjectStrategyDescriptor.java +++ b/src/main/java/org/jenkinsci/plugins/authorizeproject/AuthorizeProjectStrategyDescriptor.java @@ -31,7 +31,7 @@ import java.util.List; import jenkins.model.Jenkins; import net.sf.json.JSONObject; -import org.kohsuke.stapler.StaplerRequest; +import org.kohsuke.stapler.StaplerRequest2; /** * Base {@link Descriptor} class for {@link AuthorizeProjectStrategy} instances. @@ -91,7 +91,7 @@ public static List getDescriptorsForGlobalSe * Invoked when configuration is submitted from "Configure Global Security" as a child of {@link ProjectQueueItemAuthenticator}. * You should call save() by yourself. */ - public void configureFromGlobalSecurity(StaplerRequest req, JSONObject js) throws FormException {} + public void configureFromGlobalSecurity(StaplerRequest2 req, JSONObject js) throws FormException {} /** * @return this strategy can be enabled by default. diff --git a/src/main/java/org/jenkinsci/plugins/authorizeproject/AuthorizeProjectUtil.java b/src/main/java/org/jenkinsci/plugins/authorizeproject/AuthorizeProjectUtil.java index 32ce086..6f073e0 100644 --- a/src/main/java/org/jenkinsci/plugins/authorizeproject/AuthorizeProjectUtil.java +++ b/src/main/java/org/jenkinsci/plugins/authorizeproject/AuthorizeProjectUtil.java @@ -30,7 +30,7 @@ import hudson.model.Descriptor.FormException; import jenkins.model.Jenkins; import net.sf.json.JSONObject; -import org.kohsuke.stapler.StaplerRequest; +import org.kohsuke.stapler.StaplerRequest2; /** * @@ -40,7 +40,7 @@ public class AuthorizeProjectUtil { * Create a new {@link Describable} object from user inputs. */ public static > T bindJSONWithDescriptor( - StaplerRequest req, JSONObject formData, String fieldName, Class clazz) throws FormException { + StaplerRequest2 req, JSONObject formData, String fieldName, Class clazz) throws FormException { formData = formData.getJSONObject(fieldName); if (formData == null || formData.isNullObject()) { return null; diff --git a/src/main/java/org/jenkinsci/plugins/authorizeproject/ConfigurationPermissionEnforcer.java b/src/main/java/org/jenkinsci/plugins/authorizeproject/ConfigurationPermissionEnforcer.java index c10b1ae..956ec3d 100644 --- a/src/main/java/org/jenkinsci/plugins/authorizeproject/ConfigurationPermissionEnforcer.java +++ b/src/main/java/org/jenkinsci/plugins/authorizeproject/ConfigurationPermissionEnforcer.java @@ -12,7 +12,7 @@ import org.kohsuke.accmod.Restricted; import org.kohsuke.accmod.restrictions.NoExternalUse; import org.kohsuke.stapler.DataBoundConstructor; -import org.kohsuke.stapler.StaplerRequest; +import org.kohsuke.stapler.StaplerRequest2; /** * A dummy {@link JobProperty} responsible for providing the {@link AuthorizeProjectStrategy} with a veto over job @@ -47,7 +47,7 @@ public String getDisplayName() { * {@inheritDoc} */ @Override - public JobProperty newInstance(@NonNull StaplerRequest req, JSONObject formData) throws FormException { + public JobProperty newInstance(@NonNull StaplerRequest2 req, JSONObject formData) throws FormException { Job job = req.findAncestorObject(Job.class); AccessControlled context = req.findAncestorObject(AccessControlled.class); checkConfigurePermission(job, context); diff --git a/src/main/java/org/jenkinsci/plugins/authorizeproject/GlobalQueueItemAuthenticator.java b/src/main/java/org/jenkinsci/plugins/authorizeproject/GlobalQueueItemAuthenticator.java index c2ffcdd..2949f49 100644 --- a/src/main/java/org/jenkinsci/plugins/authorizeproject/GlobalQueueItemAuthenticator.java +++ b/src/main/java/org/jenkinsci/plugins/authorizeproject/GlobalQueueItemAuthenticator.java @@ -11,7 +11,7 @@ import org.acegisecurity.Authentication; import org.jenkinsci.plugins.authorizeproject.strategy.AnonymousAuthorizationStrategy; import org.kohsuke.stapler.DataBoundConstructor; -import org.kohsuke.stapler.StaplerRequest; +import org.kohsuke.stapler.StaplerRequest2; /** * A global default authenticator to allow changing the default for all projects. @@ -65,13 +65,13 @@ public AuthorizeProjectStrategy getDefaultStrategy() { /** * Creates new {@link GlobalQueueItemAuthenticator} from inputs. - * This is required to call {@link hudson.model.Descriptor#newInstance(StaplerRequest, JSONObject)} + * This is required to call {@link hudson.model.Descriptor#newInstance(StaplerRequest2, JSONObject)} * of {@link AuthorizeProjectProperty}. * - * @see hudson.model.Descriptor#newInstance(org.kohsuke.stapler.StaplerRequest, net.sf.json.JSONObject) + * @see hudson.model.Descriptor#newInstance(org.kohsuke.stapler.StaplerRequest2, net.sf.json.JSONObject) */ @Override - public GlobalQueueItemAuthenticator newInstance(StaplerRequest req, JSONObject formData) throws FormException { + public GlobalQueueItemAuthenticator newInstance(StaplerRequest2 req, JSONObject formData) throws FormException { if (formData == null || formData.isNullObject()) { return null; } diff --git a/src/main/java/org/jenkinsci/plugins/authorizeproject/ProjectQueueItemAuthenticator.java b/src/main/java/org/jenkinsci/plugins/authorizeproject/ProjectQueueItemAuthenticator.java index 917915b..837d714 100644 --- a/src/main/java/org/jenkinsci/plugins/authorizeproject/ProjectQueueItemAuthenticator.java +++ b/src/main/java/org/jenkinsci/plugins/authorizeproject/ProjectQueueItemAuthenticator.java @@ -43,7 +43,7 @@ import net.sf.json.JSONObject; import org.acegisecurity.Authentication; import org.kohsuke.stapler.DataBoundConstructor; -import org.kohsuke.stapler.StaplerRequest; +import org.kohsuke.stapler.StaplerRequest2; /** * Authorize builds of projects configured with {@link AuthorizeProjectProperty}. @@ -179,10 +179,11 @@ public List> getAvailableDescriptorList() { * @param formData the form data. * @return the authenticator. * @throws hudson.model.Descriptor.FormException if the submitted form is invalid. - * @see hudson.model.Descriptor#newInstance(org.kohsuke.stapler.StaplerRequest, net.sf.json.JSONObject) + * @see hudson.model.Descriptor#newInstance(org.kohsuke.stapler.StaplerRequest2, net.sf.json.JSONObject) */ @Override - public ProjectQueueItemAuthenticator newInstance(StaplerRequest req, JSONObject formData) throws FormException { + public ProjectQueueItemAuthenticator newInstance(StaplerRequest2 req, JSONObject formData) + throws FormException { Set enabledStrategies = new HashSet<>(); Set disabledStrategies = new HashSet<>(); diff --git a/src/main/java/org/jenkinsci/plugins/authorizeproject/strategy/SpecificUsersAuthorizationStrategy.java b/src/main/java/org/jenkinsci/plugins/authorizeproject/strategy/SpecificUsersAuthorizationStrategy.java index 95731d1..363af2e 100644 --- a/src/main/java/org/jenkinsci/plugins/authorizeproject/strategy/SpecificUsersAuthorizationStrategy.java +++ b/src/main/java/org/jenkinsci/plugins/authorizeproject/strategy/SpecificUsersAuthorizationStrategy.java @@ -54,7 +54,7 @@ import org.kohsuke.stapler.DataBoundConstructor; import org.kohsuke.stapler.DataBoundSetter; import org.kohsuke.stapler.QueryParameter; -import org.kohsuke.stapler.StaplerRequest; +import org.kohsuke.stapler.StaplerRequest2; /** * Run builds as a user specified in project configuration pages. @@ -290,7 +290,7 @@ public String calcCheckPasswordRequestedUrl() { */ @Restricted(NoExternalUse.class) // used by stapler/jelly @SuppressWarnings("unused") - public String doCheckPasswordRequested(StaplerRequest req, @QueryParameter String userid) { + public String doCheckPasswordRequested(StaplerRequest2 req, @QueryParameter String userid) { return Boolean.toString(isAuthenticationRequired(userid.trim())); } @@ -324,7 +324,7 @@ public FormValidation doCheckUserid(@QueryParameter String userid) { @Restricted(NoExternalUse.class) // used by stapler/jelly @SuppressWarnings("unused") public FormValidation doCheckPassword( - StaplerRequest req, + StaplerRequest2 req, @QueryParameter String userid, @QueryParameter String password, @QueryParameter String apitoken, diff --git a/src/main/java/org/jenkinsci/plugins/authorizeproject/strategy/SystemAuthorizationStrategy.java b/src/main/java/org/jenkinsci/plugins/authorizeproject/strategy/SystemAuthorizationStrategy.java index 2e5aaf7..f66abd4 100644 --- a/src/main/java/org/jenkinsci/plugins/authorizeproject/strategy/SystemAuthorizationStrategy.java +++ b/src/main/java/org/jenkinsci/plugins/authorizeproject/strategy/SystemAuthorizationStrategy.java @@ -40,7 +40,7 @@ import org.kohsuke.accmod.restrictions.NoExternalUse; import org.kohsuke.stapler.DataBoundConstructor; import org.kohsuke.stapler.QueryParameter; -import org.kohsuke.stapler.StaplerRequest; +import org.kohsuke.stapler.StaplerRequest2; /** * Run builds as {@link ACL#SYSTEM}. Using this strategy becomes important when @@ -176,7 +176,7 @@ public boolean isJob(Object it) { * {@inheritDoc} */ @Override - public void configureFromGlobalSecurity(StaplerRequest req, JSONObject js) throws FormException { + public void configureFromGlobalSecurity(StaplerRequest2 req, JSONObject js) throws FormException { setPermitReconfiguration(js.getBoolean("permitReconfiguration")); } @@ -184,7 +184,7 @@ public void configureFromGlobalSecurity(StaplerRequest req, JSONObject js) throw * {@inheritDoc} */ @Override - public SystemAuthorizationStrategy newInstance(StaplerRequest req, JSONObject formData) throws FormException { + public SystemAuthorizationStrategy newInstance(StaplerRequest2 req, JSONObject formData) throws FormException { SystemAuthorizationStrategy result = (SystemAuthorizationStrategy) super.newInstance(req, formData); Jenkins instance = Jenkins.get(); if (!instance.hasPermission(Jenkins.RUN_SCRIPTS)) { diff --git a/src/test/java/org/jenkinsci/plugins/authorizeproject/ProjectQueueItemAuthenticatorTest.java b/src/test/java/org/jenkinsci/plugins/authorizeproject/ProjectQueueItemAuthenticatorTest.java index 639049b..51237b3 100644 --- a/src/test/java/org/jenkinsci/plugins/authorizeproject/ProjectQueueItemAuthenticatorTest.java +++ b/src/test/java/org/jenkinsci/plugins/authorizeproject/ProjectQueueItemAuthenticatorTest.java @@ -70,7 +70,7 @@ import org.jvnet.hudson.test.JenkinsRule.WebClient; import org.jvnet.hudson.test.TestExtension; import org.kohsuke.stapler.DataBoundConstructor; -import org.kohsuke.stapler.StaplerRequest; +import org.kohsuke.stapler.StaplerRequest2; public class ProjectQueueItemAuthenticatorTest { @Rule @@ -284,7 +284,8 @@ public String getDisplayName() { } @Override - public void configureFromGlobalSecurity(StaplerRequest req, JSONObject js) throws Descriptor.FormException { + public void configureFromGlobalSecurity(StaplerRequest2 req, JSONObject js) + throws Descriptor.FormException { throw new FormException("Should not be called for global-security.jelly is not defined.", ""); } } @@ -320,7 +321,8 @@ public String getDisplayName() { } @Override - public void configureFromGlobalSecurity(StaplerRequest req, JSONObject js) throws Descriptor.FormException { + public void configureFromGlobalSecurity(StaplerRequest2 req, JSONObject js) + throws Descriptor.FormException { value = js.getString("value"); save(); } @@ -358,7 +360,8 @@ public String getDisplayName() { } @Override - public void configureFromGlobalSecurity(StaplerRequest req, JSONObject js) throws Descriptor.FormException { + public void configureFromGlobalSecurity(StaplerRequest2 req, JSONObject js) + throws Descriptor.FormException { value = js.getString("value"); save(); } diff --git a/src/test/java/org/jenkinsci/plugins/authorizeproject/strategy/SpecificUsersAuthorizationStrategyTest.java b/src/test/java/org/jenkinsci/plugins/authorizeproject/strategy/SpecificUsersAuthorizationStrategyTest.java index 951b3f0..59b382a 100644 --- a/src/test/java/org/jenkinsci/plugins/authorizeproject/strategy/SpecificUsersAuthorizationStrategyTest.java +++ b/src/test/java/org/jenkinsci/plugins/authorizeproject/strategy/SpecificUsersAuthorizationStrategyTest.java @@ -357,7 +357,7 @@ public void testRestInterfaceSuccess() throws Exception { new URL(wc.getContextPath() + String.format("%s/config.xml", destProject.getUrl())), HttpMethod.POST); req.setAdditionalHeader( j.jenkins.getCrumbIssuer().getCrumbRequestField(), - j.jenkins.getCrumbIssuer().getCrumb(null)); + j.jenkins.getCrumbIssuer().getCrumb((jakarta.servlet.ServletRequest) null)); req.setRequestBody(configXml); wc.getPage(req); @@ -410,7 +410,7 @@ public void testRestInterfaceFailure() throws Exception { new URL(wc.getContextPath() + String.format("%s/config.xml", destProject.getUrl())), HttpMethod.POST); req.setAdditionalHeader( j.jenkins.getCrumbIssuer().getCrumbRequestField(), - j.jenkins.getCrumbIssuer().getCrumb(null)); + j.jenkins.getCrumbIssuer().getCrumb((jakarta.servlet.ServletRequest) null)); req.setRequestBody(configXml); assertThrows(FailingHttpStatusCodeException.class, () -> wc.getPage(req)); diff --git a/src/test/java/org/jenkinsci/plugins/authorizeproject/strategy/SystemAuthorizationStrategyTest.java b/src/test/java/org/jenkinsci/plugins/authorizeproject/strategy/SystemAuthorizationStrategyTest.java index 319f6f9..98eee0b 100644 --- a/src/test/java/org/jenkinsci/plugins/authorizeproject/strategy/SystemAuthorizationStrategyTest.java +++ b/src/test/java/org/jenkinsci/plugins/authorizeproject/strategy/SystemAuthorizationStrategyTest.java @@ -185,7 +185,7 @@ public void testRestInterfaceSuccess() throws Exception { new URL(wc.getContextPath() + String.format("%s/config.xml", destProject.getUrl())), HttpMethod.POST); req.setAdditionalHeader( j.jenkins.getCrumbIssuer().getCrumbRequestField(), - j.jenkins.getCrumbIssuer().getCrumb(null)); + j.jenkins.getCrumbIssuer().getCrumb((jakarta.servlet.ServletRequest) null)); req.setRequestBody(configXml); wc.getPage(req); @@ -235,7 +235,7 @@ public void testRestInterfaceFailure() throws Exception { new URL(wc.getContextPath() + String.format("%s/config.xml", destProject.getUrl())), HttpMethod.POST); req.setAdditionalHeader( j.jenkins.getCrumbIssuer().getCrumbRequestField(), - j.jenkins.getCrumbIssuer().getCrumb(null)); + j.jenkins.getCrumbIssuer().getCrumb((jakarta.servlet.ServletRequest) null)); req.setRequestBody(configXml); assertThrows(FailingHttpStatusCodeException.class, () -> wc.getPage(req)); From 96a5957e002d6812dd91eea7cb96f9bff2afbc7f Mon Sep 17 00:00:00 2001 From: Mark Waite Date: Sun, 20 Oct 2024 16:07:15 -0600 Subject: [PATCH 2/2] Use Java 17 language features Formatted strings --- .../strategy/SpecificUsersAuthorizationStrategyTest.java | 8 ++++---- .../strategy/SystemAuthorizationStrategyTest.java | 8 ++++---- .../testutil/SecurityRealmWithUserFilter.java | 3 +-- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/test/java/org/jenkinsci/plugins/authorizeproject/strategy/SpecificUsersAuthorizationStrategyTest.java b/src/test/java/org/jenkinsci/plugins/authorizeproject/strategy/SpecificUsersAuthorizationStrategyTest.java index 59b382a..dcc481c 100644 --- a/src/test/java/org/jenkinsci/plugins/authorizeproject/strategy/SpecificUsersAuthorizationStrategyTest.java +++ b/src/test/java/org/jenkinsci/plugins/authorizeproject/strategy/SpecificUsersAuthorizationStrategyTest.java @@ -345,7 +345,7 @@ public void testRestInterfaceSuccess() throws Exception { wc.login("test1"); // GET config.xml of srcProject (userid is set to test1) - String configXml = getConfigXml(wc.goToXml(String.format("%s/config.xml", srcProject.getUrl()))); + String configXml = getConfigXml(wc.goToXml("%s/config.xml".formatted(srcProject.getUrl()))); // POST config.xml of srcProject (userid is set to test1) to a new project. // This should success. @@ -354,7 +354,7 @@ public void testRestInterfaceSuccess() throws Exception { String projectName = destProject.getFullName(); WebRequest req = new WebRequest( - new URL(wc.getContextPath() + String.format("%s/config.xml", destProject.getUrl())), HttpMethod.POST); + new URL("%s%s/config.xml".formatted(wc.getContextPath(), destProject.getUrl())), HttpMethod.POST); req.setAdditionalHeader( j.jenkins.getCrumbIssuer().getCrumbRequestField(), j.jenkins.getCrumbIssuer().getCrumb((jakarta.servlet.ServletRequest) null)); @@ -398,7 +398,7 @@ public void testRestInterfaceFailure() throws Exception { wc.login("test1"); // GET config.xml of srcProject (userid is set to admin) - String configXml = getConfigXml(wc.goToXml(String.format("%s/config.xml", srcProject.getUrl()))); + String configXml = getConfigXml(wc.goToXml("%s/config.xml".formatted(srcProject.getUrl()))); // POST config.xml of srcProject (userid is set to admin) to a new project. // This should fail. @@ -407,7 +407,7 @@ public void testRestInterfaceFailure() throws Exception { String projectName = destProject.getFullName(); WebRequest req = new WebRequest( - new URL(wc.getContextPath() + String.format("%s/config.xml", destProject.getUrl())), HttpMethod.POST); + new URL("%s%s/config.xml".formatted(wc.getContextPath(), destProject.getUrl())), HttpMethod.POST); req.setAdditionalHeader( j.jenkins.getCrumbIssuer().getCrumbRequestField(), j.jenkins.getCrumbIssuer().getCrumb((jakarta.servlet.ServletRequest) null)); diff --git a/src/test/java/org/jenkinsci/plugins/authorizeproject/strategy/SystemAuthorizationStrategyTest.java b/src/test/java/org/jenkinsci/plugins/authorizeproject/strategy/SystemAuthorizationStrategyTest.java index 98eee0b..3635cfa 100644 --- a/src/test/java/org/jenkinsci/plugins/authorizeproject/strategy/SystemAuthorizationStrategyTest.java +++ b/src/test/java/org/jenkinsci/plugins/authorizeproject/strategy/SystemAuthorizationStrategyTest.java @@ -173,7 +173,7 @@ public void testRestInterfaceSuccess() throws Exception { wc.login("admin"); // GET config.xml of srcProject - String configXml = getConfigXml(wc.goToXml(String.format("%s/config.xml", srcProject.getUrl()))); + String configXml = getConfigXml(wc.goToXml("%s/config.xml".formatted(srcProject.getUrl()))); // POST config.xml of srcProject to a new project. // This should success. @@ -182,7 +182,7 @@ public void testRestInterfaceSuccess() throws Exception { String projectName = destProject.getFullName(); WebRequest req = new WebRequest( - new URL(wc.getContextPath() + String.format("%s/config.xml", destProject.getUrl())), HttpMethod.POST); + new URL(wc.getContextPath() + "%s/config.xml".formatted(destProject.getUrl())), HttpMethod.POST); req.setAdditionalHeader( j.jenkins.getCrumbIssuer().getCrumbRequestField(), j.jenkins.getCrumbIssuer().getCrumb((jakarta.servlet.ServletRequest) null)); @@ -223,7 +223,7 @@ public void testRestInterfaceFailure() throws Exception { .setPermitReconfiguration(true); // GET config.xml of srcProject - String configXml = getConfigXml(wc.goToXml(String.format("%s/config.xml", srcProject.getUrl()))); + String configXml = getConfigXml(wc.goToXml("%s/config.xml".formatted(srcProject.getUrl()))); // POST config.xml of srcProject (userid is set to admin) to a new project. // This should fail. @@ -232,7 +232,7 @@ public void testRestInterfaceFailure() throws Exception { String projectName = destProject.getFullName(); WebRequest req = new WebRequest( - new URL(wc.getContextPath() + String.format("%s/config.xml", destProject.getUrl())), HttpMethod.POST); + new URL(wc.getContextPath() + "%s/config.xml".formatted(destProject.getUrl())), HttpMethod.POST); req.setAdditionalHeader( j.jenkins.getCrumbIssuer().getCrumbRequestField(), j.jenkins.getCrumbIssuer().getCrumb((jakarta.servlet.ServletRequest) null)); diff --git a/src/test/java/org/jenkinsci/plugins/authorizeproject/testutil/SecurityRealmWithUserFilter.java b/src/test/java/org/jenkinsci/plugins/authorizeproject/testutil/SecurityRealmWithUserFilter.java index add1e8d..891bd4d 100644 --- a/src/test/java/org/jenkinsci/plugins/authorizeproject/testutil/SecurityRealmWithUserFilter.java +++ b/src/test/java/org/jenkinsci/plugins/authorizeproject/testutil/SecurityRealmWithUserFilter.java @@ -51,8 +51,7 @@ public SecurityComponents createSecurityComponents() { baseComponent.manager, username -> { if (!validUserList.contains(username)) { - throw new UsernameNotFoundException( - String.format("%s is not listed as valid username.", username)); + throw new UsernameNotFoundException("%s is not listed as valid username.".formatted(username)); } return baseComponent.userDetails.loadUserByUsername(username); },