Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require Jenkins 2.479.1 or newer #268

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>4.88</version>
<version>5.5</version>
<relativePath />
</parent>

Expand Down Expand Up @@ -33,8 +33,9 @@
<revision>1.8.2</revision>
<changelist>-SNAPSHOT</changelist>
<gitHubRepo>jenkinsci/authorize-project-plugin</gitHubRepo>
<jenkins.baseline>2.452</jenkins.baseline>
<jenkins.version>${jenkins.baseline}.4</jenkins.version>
<!-- https://www.jenkins.io/doc/developer/plugin-development/choosing-jenkins-baseline/ -->
<jenkins.baseline>2.479</jenkins.baseline>
<jenkins.version>${jenkins.baseline}.1</jenkins.version>
<spotbugs.effort>Max</spotbugs.effort>
<spotbugs.threshold>Low</spotbugs.threshold>
<spotless.check.skip>false</spotless.check.skip>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

/**
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -91,7 +91,7 @@
* 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 {}

Check warning on line 94 in src/main/java/org/jenkinsci/plugins/authorizeproject/AuthorizeProjectStrategyDescriptor.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 94 is not covered by tests

/**
* @return this strategy can be enabled by default.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
*
Expand All @@ -40,7 +40,7 @@ public class AuthorizeProjectUtil {
* Create a new {@link Describable} object from user inputs.
*/
public static <T extends Describable<?>> T bindJSONWithDescriptor(
StaplerRequest req, JSONObject formData, String fieldName, Class<T> clazz) throws FormException {
StaplerRequest2 req, JSONObject formData, String fieldName, Class<T> clazz) throws FormException {
formData = formData.getJSONObject(fieldName);
if (formData == null || formData.isNullObject()) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
Expand Down Expand Up @@ -179,10 +179,11 @@ public List<Descriptor<AuthorizeProjectStrategy>> 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<String> enabledStrategies = new HashSet<>();
Set<String> disabledStrategies = new HashSet<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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()));
}

Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -176,15 +176,15 @@ 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"));
}

/**
* {@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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.", "");
}
}
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -354,10 +354,10 @@ 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(null));
j.jenkins.getCrumbIssuer().getCrumb((jakarta.servlet.ServletRequest) null));
req.setRequestBody(configXml);
wc.getPage(req);

Expand Down Expand Up @@ -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.
Expand All @@ -407,10 +407,10 @@ 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(null));
j.jenkins.getCrumbIssuer().getCrumb((jakarta.servlet.ServletRequest) null));
req.setRequestBody(configXml);

assertThrows(FailingHttpStatusCodeException.class, () -> wc.getPage(req));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -182,10 +182,10 @@ 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(null));
j.jenkins.getCrumbIssuer().getCrumb((jakarta.servlet.ServletRequest) null));
req.setRequestBody(configXml);
wc.getPage(req);

Expand Down Expand Up @@ -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.
Expand All @@ -232,10 +232,10 @@ 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(null));
j.jenkins.getCrumbIssuer().getCrumb((jakarta.servlet.ServletRequest) null));
req.setRequestBody(configXml);

assertThrows(FailingHttpStatusCodeException.class, () -> wc.getPage(req));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},
Expand Down
Loading