提交 20340e18 编写于 作者: J Jesse Glick

Restricting postBack access to users with ADMINISTER.

上级 c1adb4e6
...@@ -67,7 +67,7 @@ public class DownloadService extends PageDecorator { ...@@ -67,7 +67,7 @@ public class DownloadService extends PageDecorator {
* Builds up an HTML fragment that starts all the download jobs. * Builds up an HTML fragment that starts all the download jobs.
*/ */
public String generateFragment() { public String generateFragment() {
if (!DownloadSettings.get().isUseBrowser()) { if (!DownloadSettings.usePostBack()) {
return ""; return "";
} }
if (neverUpdate) return ""; if (neverUpdate) return "";
...@@ -308,9 +308,7 @@ public class DownloadService extends PageDecorator { ...@@ -308,9 +308,7 @@ public class DownloadService extends PageDecorator {
* This is where the browser sends us the data. * This is where the browser sends us the data.
*/ */
public void doPostBack(StaplerRequest req, StaplerResponse rsp) throws IOException { public void doPostBack(StaplerRequest req, StaplerResponse rsp) throws IOException {
if (!DownloadSettings.get().isUseBrowser()) { DownloadSettings.checkPostBackAccess();
throw new IOException("not allowed");
}
long dataTimestamp = System.currentTimeMillis(); long dataTimestamp = System.currentTimeMillis();
due = dataTimestamp+getInterval(); // success or fail, don't try too often due = dataTimestamp+getInterval(); // success or fail, don't try too often
......
...@@ -174,9 +174,7 @@ public class UpdateSite { ...@@ -174,9 +174,7 @@ public class UpdateSite {
* This is the endpoint that receives the update center data file from the browser. * This is the endpoint that receives the update center data file from the browser.
*/ */
public FormValidation doPostBack(StaplerRequest req) throws IOException, GeneralSecurityException { public FormValidation doPostBack(StaplerRequest req) throws IOException, GeneralSecurityException {
if (!DownloadSettings.get().isUseBrowser()) { DownloadSettings.checkPostBackAccess();
throw new IOException("not allowed");
}
return updateData(IOUtils.toString(req.getInputStream(),"UTF-8"), true); return updateData(IOUtils.toString(req.getInputStream(),"UTF-8"), true);
} }
......
...@@ -34,6 +34,7 @@ import hudson.model.UpdateSite; ...@@ -34,6 +34,7 @@ import hudson.model.UpdateSite;
import hudson.util.FormValidation; import hudson.util.FormValidation;
import java.io.IOException; import java.io.IOException;
import net.sf.json.JSONObject; import net.sf.json.JSONObject;
import org.acegisecurity.AccessDeniedException;
import org.kohsuke.accmod.Restricted; import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse; import org.kohsuke.accmod.restrictions.NoExternalUse;
import org.kohsuke.stapler.HttpResponse; import org.kohsuke.stapler.HttpResponse;
...@@ -75,6 +76,17 @@ import org.kohsuke.stapler.StaplerRequest; ...@@ -75,6 +76,17 @@ import org.kohsuke.stapler.StaplerRequest;
return GlobalConfigurationCategory.get(GlobalConfigurationCategory.Security.class); return GlobalConfigurationCategory.get(GlobalConfigurationCategory.Security.class);
} }
public static boolean usePostBack() {
return get().isUseBrowser() && Jenkins.getInstance().hasPermission(Jenkins.ADMINISTER);
}
public static void checkPostBackAccess() throws AccessDeniedException {
if (!get().isUseBrowser()) {
throw new AccessDeniedException("browser-based download disabled");
}
Jenkins.getInstance().checkPermission(Jenkins.ADMINISTER);
}
@Extension public static final class DailyCheck extends AsyncPeriodicWork { @Extension public static final class DailyCheck extends AsyncPeriodicWork {
public DailyCheck() { public DailyCheck() {
......
...@@ -31,8 +31,8 @@ THE SOFTWARE. ...@@ -31,8 +31,8 @@ THE SOFTWARE.
--> -->
<?jelly escape-by-default='true'?> <?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form"> <j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<j:invokeStatic var="ds" className="jenkins.model.DownloadSettings" method="get"/> <j:invokeStatic var="enabled" className="jenkins.model.DownloadSettings" method="usePostBack"/>
<j:if test="${ds.useBrowser}"> <j:if test="${enabled}">
<j:forEach var="site" items="${app.updateCenter.sites}"> <j:forEach var="site" items="${app.updateCenter.sites}">
<j:if test="${site.due or forcedUpdateCheck}"> <j:if test="${site.due or forcedUpdateCheck}">
<script> <script>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册