Skip to content

Commit

Permalink
[FIXED JENKINS-17087] getSortedDescriptorsForGlobalConfigUnclassified…
Browse files Browse the repository at this point in the history
… needed to avoid clobbering GlobalCrumbIssuerConfiguration in Jenkins.doConfigSubmit.
  • Loading branch information
jglick committed Mar 5, 2013
1 parent 8bfeaf7 commit ebd8ff1
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
3 changes: 3 additions & 0 deletions changelog.html
Expand Up @@ -55,6 +55,9 @@
<!-- Record your changes in the trunk here. -->
<div id="trunk" style="display:none"><!--=TRUNK-BEGIN=-->
<ul class=image>
<li class='major bug'>
Saving Global Jenkins Global Config wipes out the crumb issuer settings in the Global Security Config.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-17087">issue 17087</a>)
<li class=bug>
Preview function for textareas using Jenkins markup did not work when CSRF protection was enabled.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-17085">issue 17085</a>)
Expand Down
20 changes: 20 additions & 0 deletions core/src/main/java/hudson/Functions.java
Expand Up @@ -782,6 +782,7 @@ public static List<NodePropertyDescriptor> getNodePropertyDescriptors(Class<? ex
*
* @param predicate
* Filter the descriptors based on {@link GlobalConfigurationCategory}
* @since 1.494
*/
public static Collection<Descriptor> getSortedDescriptorsForGlobalConfig(Predicate<GlobalConfigurationCategory> predicate) {
ExtensionList<Descriptor> exts = Jenkins.getInstance().getExtensionList(Descriptor.class);
Expand All @@ -807,13 +808,32 @@ public static Collection<Descriptor> getSortedDescriptorsForGlobalConfig(Predica
return DescriptorVisibilityFilter.apply(Jenkins.getInstance(),answer);
}

/**
* Like {@link #getSortedDescriptorsForGlobalConfig(Predicate)} but with a constant truth predicate, to include all descriptors.
*/
public static Collection<Descriptor> getSortedDescriptorsForGlobalConfig() {
return getSortedDescriptorsForGlobalConfig(Predicates.<GlobalConfigurationCategory>alwaysTrue());
}

/**
* @deprecated This is rather meaningless.
*/
@Deprecated
public static Collection<Descriptor> getSortedDescriptorsForGlobalConfigNoSecurity() {
return getSortedDescriptorsForGlobalConfig(Predicates.not(GlobalSecurityConfiguration.FILTER));
}

/**
* Like {@link #getSortedDescriptorsForGlobalConfig(Predicate)} but for unclassified descriptors only.
* @since 1.506
*/
public static Collection<Descriptor> getSortedDescriptorsForGlobalConfigUnclassified() {
return getSortedDescriptorsForGlobalConfig(new Predicate<GlobalConfigurationCategory>() {
public boolean apply(GlobalConfigurationCategory cat) {
return cat instanceof GlobalConfigurationCategory.Unclassified;
}
});
}

private static class Tag implements Comparable<Tag> {
double ordinal;
Expand Down
9 changes: 6 additions & 3 deletions core/src/main/java/jenkins/model/Jenkins.java
Expand Up @@ -94,6 +94,7 @@
import hudson.DescriptorExtensionList;
import hudson.Extension;
import hudson.ExtensionList;
import hudson.ExtensionPoint;
import hudson.FilePath;
import hudson.Functions;
import hudson.Launcher;
Expand All @@ -110,6 +111,7 @@
import hudson.Util;
import static hudson.Util.fixEmpty;
import static hudson.Util.fixNull;
import hudson.WebAppMain;
import hudson.XmlFile;
import hudson.cli.CLICommand;
import hudson.cli.CliEntryPoint;
Expand Down Expand Up @@ -247,6 +249,7 @@
import javax.servlet.http.HttpServletResponse;

import static hudson.init.InitMilestone.*;
import hudson.security.BasicAuthenticationFilter;
import static javax.servlet.http.HttpServletResponse.SC_BAD_REQUEST;
import static javax.servlet.http.HttpServletResponse.SC_NOT_FOUND;
import java.io.File;
Expand Down Expand Up @@ -2702,7 +2705,7 @@ public synchronized void doConfigSubmit( StaplerRequest req, StaplerResponse rsp
jdks.addAll(req.bindJSONToList(JDK.class,json.get("jdks")));

boolean result = true;
for( Descriptor<?> d : Functions.getSortedDescriptorsForGlobalConfig() )
for (Descriptor<?> d : Functions.getSortedDescriptorsForGlobalConfigUnclassified())
result &= configureDescriptor(req,json,d);

version = VERSION;
Expand Down Expand Up @@ -2886,7 +2889,7 @@ public synchronized void doCreateView( StaplerRequest req, StaplerResponse rsp )
* Check if the given name is suitable as a name
* for job, view, etc.
*
* @throws ParseException
* @throws Failure
* if the given name is not good
*/
public static void checkGoodName(String name) throws Failure {
Expand All @@ -2907,7 +2910,7 @@ public static void checkGoodName(String name) throws Failure {

/**
* Makes sure that the given name is good as a job name.
* @return trimmed name if valid; throws ParseException if not
* @return trimmed name if valid; throws Failure if not
*/
private String checkJobName(String name) throws Failure {
checkGoodName(name);
Expand Down
Expand Up @@ -53,7 +53,7 @@ THE SOFTWARE.
</f:entry>

<!-- global configuration from everyone -->
<j:forEach var="descriptor" items="${h.getSortedDescriptorsForGlobalConfigNoSecurity()}">
<j:forEach var="descriptor" items="${h.getSortedDescriptorsForGlobalConfigUnclassified()}">
<j:set var="instance" value="${descriptor}" /><!-- this makes the <f:textbox field=.../> work -->
<f:rowSet name="${descriptor.jsonSafeClassName}">
<st:include page="${descriptor.globalConfigPage}" from="${descriptor}" />
Expand Down

0 comments on commit ebd8ff1

Please sign in to comment.