Skip to content

Commit fdf1915

Browse files
committed
Removing requesterAuthentication
1 parent 3435ec4 commit fdf1915

File tree

5 files changed

+46
-81
lines changed

5 files changed

+46
-81
lines changed

src/main/java/com/cloudbees/jenkins/support/SupportAction.java

+3-13
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333
import hudson.model.Api;
3434
import hudson.model.Failure;
3535
import hudson.model.RootAction;
36-
import hudson.security.ACL;
37-
import hudson.security.ACLContext;
3836
import hudson.security.Permission;
3937
import jakarta.servlet.ServletException;
4038
import jakarta.servlet.ServletOutputStream;
@@ -397,18 +395,10 @@ private void prepareBundle(StaplerResponse2 rsp, List<Component> components) thr
397395
rsp.addHeader("Content-Disposition", "inline; filename=" + BundleFileName.generate() + ";");
398396
final ServletOutputStream servletOutputStream = rsp.getOutputStream();
399397
try {
400-
SupportPlugin.setRequesterAuthentication(Jenkins.getAuthentication2());
401-
try {
402-
try (ACLContext ignored = ACL.as2(ACL.SYSTEM2)) {
403-
SupportPlugin.writeBundle(servletOutputStream, components);
404-
} catch (IOException e) {
405-
logger.log(Level.FINE, e.getMessage(), e);
406-
}
407-
} finally {
408-
SupportPlugin.clearRequesterAuthentication();
409-
}
410-
} finally {
398+
SupportPlugin.writeBundle(servletOutputStream, components);
411399
logger.fine("Response completed");
400+
} catch (IOException e) {
401+
logger.log(Level.FINE, e.getMessage(), e);
412402
}
413403
}
414404

src/main/java/com/cloudbees/jenkins/support/SupportCommand.java

+6-15
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@
3131
import hudson.Extension;
3232
import hudson.cli.CLICommand;
3333
import hudson.remoting.RemoteOutputStream;
34-
import hudson.security.ACL;
35-
import hudson.security.ACLContext;
3634
import java.io.FileOutputStream;
3735
import java.io.IOException;
3836
import java.io.OutputStream;
@@ -93,20 +91,13 @@ protected int run() throws Exception {
9391
selected.add(c);
9492
}
9593
}
96-
SupportPlugin.setRequesterAuthentication(Jenkins.getAuthentication2());
97-
try {
98-
try (ACLContext ignored = ACL.as2(ACL.SYSTEM2)) {
99-
OutputStream os;
100-
if (channel != null) { // Remoting mode
101-
os = channel.call(new SaveBundle(BundleFileName.generate()));
102-
} else { // redirect output to a ZIP file yourself
103-
os = new CloseProofOutputStream(stdout);
104-
}
105-
SupportPlugin.writeBundle(os, new ArrayList<>(selected));
106-
}
107-
} finally {
108-
SupportPlugin.clearRequesterAuthentication();
94+
OutputStream os;
95+
if (channel != null) { // Remoting mode
96+
os = channel.call(new SaveBundle(BundleFileName.generate()));
97+
} else { // redirect output to a ZIP file yourself
98+
os = new CloseProofOutputStream(stdout);
10999
}
100+
SupportPlugin.writeBundle(os, new ArrayList<>(selected));
110101
return 0;
111102
}
112103

src/main/java/com/cloudbees/jenkins/support/SupportPlugin.java

+5-11
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@ public class SupportPlugin extends Plugin {
158158
Jenkins.ADMINISTER,
159159
PermissionScope.JENKINS);
160160

161-
private static final ThreadLocal<Authentication> requesterAuthentication = new InheritableThreadLocal<>();
162161
private static final AtomicLong nextBundleWrite = new AtomicLong(Long.MIN_VALUE);
163162
private static final Logger logger = Logger.getLogger(SupportPlugin.class.getName());
164163
public static final String SUPPORT_DIRECTORY_NAME = "support";
@@ -234,16 +233,12 @@ public static File getLogsDirectory() {
234233
return new File(SafeTimerTask.getLogsRoot(), SUPPORT_DIRECTORY_NAME);
235234
}
236235

236+
/**
237+
* @deprecated Check permissions directly.
238+
*/
239+
@Deprecated
237240
public static Authentication getRequesterAuthentication() {
238-
return requesterAuthentication.get();
239-
}
240-
241-
public static void setRequesterAuthentication(Authentication authentication) {
242-
requesterAuthentication.set(authentication);
243-
}
244-
245-
public static void clearRequesterAuthentication() {
246-
requesterAuthentication.remove();
241+
return Jenkins.getAuthentication2();
247242
}
248243

249244
public void setSupportProvider(SupportProvider supportProvider) throws IOException {
@@ -969,7 +964,6 @@ protected synchronized void doRun() throws Exception {
969964
thread.setName(String.format(
970965
"%s periodic bundle generator: since %s",
971966
SupportPlugin.class.getSimpleName(), new Date()));
972-
clearRequesterAuthentication();
973967
try (ACLContext ignored = ACL.as2(ACL.SYSTEM2)) {
974968
File bundleDir = getRootDirectory();
975969
if (!bundleDir.exists()) {

src/main/java/com/cloudbees/jenkins/support/actions/SupportObjectAction.java

+8-16
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
import hudson.model.Action;
1414
import hudson.model.Descriptor;
1515
import hudson.model.Saveable;
16-
import hudson.security.ACL;
17-
import hudson.security.ACLContext;
1816
import hudson.util.DescribableList;
1917
import jakarta.servlet.ServletException;
2018
import jakarta.servlet.http.HttpServletResponse;
@@ -139,21 +137,15 @@ public final void doGenerateAndDownload(StaplerRequest2 req, StaplerResponse2 rs
139137
"Content-Disposition", "inline; filename=" + BundleFileName.generate(getBundleNameQualifier()) + ";");
140138

141139
try {
142-
SupportPlugin.setRequesterAuthentication(Jenkins.getAuthentication2());
143-
try (ACLContext old = ACL.as2(ACL.SYSTEM2)) {
144-
SupportPlugin.writeBundle(rsp.getOutputStream(), components, new ComponentVisitor() {
145-
@Override
146-
public <C extends Component> void visit(Container container, C component) {
147-
((ObjectComponent<T>) component).addContents(container, object);
148-
}
149-
});
150-
} catch (IOException e) {
151-
LOGGER.log(Level.WARNING, e.getMessage(), e);
152-
} finally {
153-
SupportPlugin.clearRequesterAuthentication();
154-
}
155-
} finally {
140+
SupportPlugin.writeBundle(rsp.getOutputStream(), components, new ComponentVisitor() {
141+
@Override
142+
public <C extends Component> void visit(Container container, C component) {
143+
((ObjectComponent<T>) component).addContents(container, object);
144+
}
145+
});
156146
LOGGER.fine("Response completed");
147+
} catch (IOException e) {
148+
LOGGER.log(Level.WARNING, e.getMessage(), e);
157149
}
158150
}
159151

src/main/java/com/cloudbees/jenkins/support/impl/AboutUser.java

+24-26
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.cloudbees.jenkins.support.impl;
22

3-
import com.cloudbees.jenkins.support.SupportPlugin;
43
import com.cloudbees.jenkins.support.api.Component;
54
import com.cloudbees.jenkins.support.api.Container;
65
import com.cloudbees.jenkins.support.api.PrefilteredPrintedContent;
@@ -13,6 +12,7 @@
1312
import java.util.Collection;
1413
import java.util.Collections;
1514
import java.util.Set;
15+
import jenkins.model.Jenkins;
1616
import org.springframework.security.core.Authentication;
1717
import org.springframework.security.core.GrantedAuthority;
1818

@@ -36,33 +36,31 @@ public Set<Permission> getRequiredPermissions() {
3636

3737
@Override
3838
public void addContents(@NonNull Container result) {
39-
final Authentication authentication = SupportPlugin.getRequesterAuthentication();
40-
if (authentication != null) {
41-
result.add(new PrefilteredPrintedContent("user.md") {
42-
@Override
43-
protected void printTo(PrintWriter out, ContentFilter filter) throws IOException {
44-
out.println("User");
45-
out.println("====");
46-
out.println();
47-
out.println("Authentication");
48-
out.println("--------------");
49-
out.println();
50-
out.println(" * Authenticated: " + authentication.isAuthenticated());
51-
out.println(" * Name: " + ContentFilter.filter(filter, authentication.getName()));
52-
Collection<? extends GrantedAuthority> authorities = authentication.getAuthorities();
53-
if (authorities != null) {
54-
out.println(" * Authorities ");
55-
for (GrantedAuthority authority : authorities) {
56-
out.println(" - "
57-
+ (authority == null
58-
? "null"
59-
: "`" + authority.toString().replaceAll("`", "&#96;") + "`"));
60-
}
39+
final Authentication authentication = Jenkins.getAuthentication2();
40+
result.add(new PrefilteredPrintedContent("user.md") {
41+
@Override
42+
protected void printTo(PrintWriter out, ContentFilter filter) throws IOException {
43+
out.println("User");
44+
out.println("====");
45+
out.println();
46+
out.println("Authentication");
47+
out.println("--------------");
48+
out.println();
49+
out.println(" * Authenticated: " + authentication.isAuthenticated());
50+
out.println(" * Name: " + ContentFilter.filter(filter, authentication.getName()));
51+
Collection<? extends GrantedAuthority> authorities = authentication.getAuthorities();
52+
if (authorities != null) {
53+
out.println(" * Authorities ");
54+
for (GrantedAuthority authority : authorities) {
55+
out.println(" - "
56+
+ (authority == null
57+
? "null"
58+
: "`" + authority.toString().replaceAll("`", "&#96;") + "`"));
6159
}
62-
out.println();
6360
}
64-
});
65-
}
61+
out.println();
62+
}
63+
});
6664
}
6765

6866
@NonNull

0 commit comments

Comments
 (0)