Skip to content

Commit

Permalink
Merge branch 'master' into JENKINS-71578
Browse files Browse the repository at this point in the history
  • Loading branch information
mawinter69 authored Aug 23, 2023
2 parents 901be04 + ae74db6 commit d4c42ff
Show file tree
Hide file tree
Showing 110 changed files with 792 additions and 508 deletions.
4 changes: 2 additions & 2 deletions bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ THE SOFTWARE.
<!-- https://docs.spring.io/spring-security/site/docs/5.5.4/reference/html5/#getting-maven-no-boot -->
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-bom</artifactId>
<version>5.8.5</version>
<version>5.8.6</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down Expand Up @@ -189,7 +189,7 @@ THE SOFTWARE.
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant</artifactId>
<version>1.10.13</version>
<version>1.10.14</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
import java.io.DataInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.Charset;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.commons.lang.StringEscapeUtils;

/**
* Filters out console notes.
Expand All @@ -36,6 +40,8 @@
*/
public class PlainTextConsoleOutputStream extends LineTransformationOutputStream.Delegating {

private static final Logger LOGGER = Logger.getLogger(PlainTextConsoleOutputStream.class.getName());

/**
*
*/
Expand Down Expand Up @@ -64,7 +70,11 @@ protected void eol(byte[] in, int sz) throws IOException {
int rest = sz - next;
ByteArrayInputStream b = new ByteArrayInputStream(in, next, rest);

ConsoleNote.skip(new DataInputStream(b));
try {
ConsoleNote.skip(new DataInputStream(b));
} catch (IOException x) {
LOGGER.log(Level.FINE, "Failed to skip annotation from \"" + StringEscapeUtils.escapeJava(new String(in, next, rest, Charset.defaultCharset())) + "\"", x);
}

int bytesUsed = rest - b.available(); // bytes consumed by annotations
written += bytesUsed;
Expand Down
12 changes: 9 additions & 3 deletions core/src/main/java/hudson/model/Label.java
Original file line number Diff line number Diff line change
Expand Up @@ -592,10 +592,16 @@ public static Set<LabelAtom> parse(@CheckForNull String labels) {
final Set<LabelAtom> r = new TreeSet<>();
labels = fixNull(labels);
if (labels.length() > 0) {
final QuotedStringTokenizer tokenizer = new QuotedStringTokenizer(labels);
while (tokenizer.hasMoreTokens())
r.add(Jenkins.get().getLabelAtom(tokenizer.nextToken()));
Jenkins j = Jenkins.get();
LabelAtom labelAtom = j.tryGetLabelAtom(labels);
if (labelAtom == null) {
final QuotedStringTokenizer tokenizer = new QuotedStringTokenizer(labels);
while (tokenizer.hasMoreTokens())
r.add(j.getLabelAtom(tokenizer.nextToken()));
} else {
r.add(labelAtom);
}
}
return r;
}

Expand Down
16 changes: 14 additions & 2 deletions core/src/main/java/hudson/model/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
import net.sf.json.JSONObject;
import org.jvnet.localizer.Localizable;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import org.kohsuke.accmod.restrictions.ProtectedExternally;
import org.kohsuke.stapler.BindInterceptor;
import org.kohsuke.stapler.Stapler;
Expand Down Expand Up @@ -298,20 +299,31 @@ public OfflineCause getTemporaryOfflineCause() {
public TagCloud<LabelAtom> getLabelCloud() {
return new TagCloud<>(getAssignedLabels(), Label::getTiedJobCount);
}

/**
* @return An immutable set of LabelAtom associated with the current node label.
*/
@NonNull
@Restricted(NoExternalUse.class)
protected Set<LabelAtom> getLabelAtomSet() {
// Default implementation doesn't cache, since we can't hook on label updates.
return Collections.unmodifiableSet(Label.parse(getLabelString()));
}

/**
* Returns the possibly empty set of labels that are assigned to this node,
* including the automatic {@link #getSelfLabel() self label}, manually
* assigned labels and dynamically assigned labels via the
* {@link LabelFinder} extension point.
*
* This method has a side effect of updating the hudson-wide set of labels
* and should be called after events that will change that - e.g. a agent
* and should be called after events that will change that - e.g. an agent
* connecting.
*/

@Exported
public Set<LabelAtom> getAssignedLabels() {
Set<LabelAtom> r = Label.parse(getLabelString());
Set<LabelAtom> r = new HashSet<>(getLabelAtomSet());
r.add(getSelfLabel());
r.addAll(getDynamicLabels());
return Collections.unmodifiableSet(r);
Expand Down
21 changes: 19 additions & 2 deletions core/src/main/java/hudson/model/Slave.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import hudson.Util;
import hudson.cli.CLI;
import hudson.model.Descriptor.FormException;
import hudson.model.labels.LabelAtom;
import hudson.remoting.Callable;
import hudson.remoting.Channel;
import hudson.remoting.Which;
Expand All @@ -60,6 +61,7 @@
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.jar.JarFile;
Expand Down Expand Up @@ -179,6 +181,7 @@ protected Slave(@NonNull String name, String remoteFS, ComputerLauncher launcher
this.name = name;
this.remoteFS = remoteFS;
this.launcher = launcher;
this.labelAtomSet = Collections.unmodifiableSet(Label.parse(label));
}

/**
Expand All @@ -193,7 +196,7 @@ protected Slave(@NonNull String name, String nodeDescription, String remoteFS, i
this.numExecutors = numExecutors;
this.mode = mode;
this.remoteFS = Util.fixNull(remoteFS).trim();
this.label = Util.fixNull(labelString).trim();
this.labelAtomSet = Collections.unmodifiableSet(Label.parse(labelString));
this.launcher = launcher;
this.retentionStrategy = retentionStrategy;
getAssignedLabels(); // compute labels now
Expand Down Expand Up @@ -328,11 +331,24 @@ public String getLabelString() {
@Override
@DataBoundSetter
public void setLabelString(String labelString) throws IOException {
this.label = Util.fixNull(labelString).trim();
_setLabelString(labelString);
// Compute labels now.
getAssignedLabels();
}

private void _setLabelString(String labelString) {
this.label = Util.fixNull(labelString).trim();
this.labelAtomSet = Collections.unmodifiableSet(Label.parse(label));
}

@NonNull
private transient Set<LabelAtom> labelAtomSet;

@Override
protected Set<LabelAtom> getLabelAtomSet() {
return labelAtomSet;
}

@Override
public Callable<ClockDifference, IOException> getClockDifferenceCallable() {
return new GetClockDifference1();
Expand Down Expand Up @@ -574,6 +590,7 @@ public int hashCode() {
protected Object readResolve() {
if (nodeProperties == null)
nodeProperties = new DescribableList<>(this);
_setLabelString(label);
return this;
}

Expand Down
22 changes: 17 additions & 5 deletions core/src/main/java/hudson/security/SecurityRealm.java
Original file line number Diff line number Diff line change
Expand Up @@ -647,15 +647,27 @@ public static String getFrom() {
from = request.getParameter("from");
}

// On the 404 error page, use the session attribute it sets
if (request != null && request.getRequestURI().equals(request.getContextPath() + "/404")) {
final HttpSession session = request.getSession(false);
if (session != null) {
final Object attribute = session.getAttribute("from");
if (attribute != null) {
from = attribute.toString();
}
}
}

// If entry point was not found, try to deduce it from the request URI
// except pages related to login process
// except pages related to login process and the 404 error page
if (from == null
&& request != null
&& request.getRequestURI() != null
&& !request.getRequestURI().equals("/loginError")
&& !request.getRequestURI().equals("/login")) {

from = request.getRequestURI();
// The custom login page makes the next two lines obsolete, but safer to have them.
&& !request.getRequestURI().equals(request.getContextPath() + "/loginError")
&& !request.getRequestURI().equals(request.getContextPath() + "/login")
&& !request.getRequestURI().equals(request.getContextPath() + "/404")) {
from = request.getRequestURI();
}

// If deduced entry point isn't deduced yet or the content is a blank value
Expand Down
30 changes: 30 additions & 0 deletions core/src/main/java/jenkins/ErrorAttributeFilter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package jenkins;

import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import jenkins.model.Jenkins;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import org.springframework.security.core.Authentication;

/**
* Record the current user authentication for later impersonation if the response is 404 Not Found.
*
* @see Jenkins#generateNotFoundResponse(org.kohsuke.stapler.StaplerRequest, org.kohsuke.stapler.StaplerResponse)
*/
@Restricted(NoExternalUse.class)
public class ErrorAttributeFilter implements Filter {

public static final String USER_ATTRIBUTE = "jenkins.ErrorAttributeFilter.user";

@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
final Authentication authentication = Jenkins.getAuthentication2();
servletRequest.setAttribute(USER_ATTRIBUTE, authentication);
filterChain.doFilter(servletRequest, servletResponse);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import hudson.Extension;
import hudson.diagnosis.ReverseProxySetupMonitor;
import hudson.model.AdministrativeMonitor;
import hudson.model.ManageJenkinsAction;
import hudson.model.PageDecorator;
import hudson.util.HudsonIsLoading;
import hudson.util.HudsonIsRestarting;
Expand All @@ -53,9 +54,6 @@ public class AdministrativeMonitorsDecorator extends PageDecorator {
private final Collection<String> ignoredJenkinsRestOfUrls = new ArrayList<>();

public AdministrativeMonitorsDecorator() {
// redundant
ignoredJenkinsRestOfUrls.add("manage");

// otherwise this would be added to every internal context menu building request
ignoredJenkinsRestOfUrls.add("contextMenu");

Expand Down Expand Up @@ -165,6 +163,11 @@ public Collection<AdministrativeMonitor> getMonitorsToDisplay() {
return null;
}

// Don't show on Manage Jenkins
if (o instanceof ManageJenkinsAction) {
return null;
}

// don't show for some URLs served directly by Jenkins
if (o instanceof Jenkins) {
String url = a.getRestOfUrl();
Expand Down
Loading

0 comments on commit d4c42ff

Please sign in to comment.