Skip to content

Commit 0efbcb7

Browse files
authored
Updated to FlowExecution.getAuthentication2 (#1002)
1 parent 9e25a94 commit 0efbcb7

File tree

4 files changed

+17
-12
lines changed

4 files changed

+17
-12
lines changed

plugin/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@
6262
<artifactId>support-core</artifactId>
6363
<version>1575.v49b_01a_460e3b_</version>
6464
</dependency>
65+
<dependency>
66+
<groupId>org.jenkins-ci.plugins.workflow</groupId>
67+
<artifactId>workflow-api</artifactId>
68+
<version>1366.vf1fb_e1a_f6b_22</version>
69+
</dependency>
6570
</dependencies>
6671
</dependencyManagement>
6772
<dependencies>

plugin/src/main/java/org/jenkinsci/plugins/workflow/cps/CpsFlowExecution.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,6 @@
141141
import edu.umd.cs.findbugs.annotations.NonNull;
142142
import net.jcip.annotations.GuardedBy;
143143

144-
import org.acegisecurity.Authentication;
145-
import org.acegisecurity.userdetails.UsernameNotFoundException;
146144
import java.nio.charset.StandardCharsets;
147145
import jenkins.util.SystemProperties;
148146
import org.codehaus.groovy.GroovyBugError;
@@ -154,6 +152,8 @@
154152
import org.jenkinsci.plugins.workflow.flow.FlowExecutionList;
155153
import org.jenkinsci.plugins.workflow.graph.FlowGraphWalker;
156154
import org.kohsuke.accmod.restrictions.DoNotUse;
155+
import org.springframework.security.core.Authentication;
156+
import org.springframework.security.core.userdetails.UsernameNotFoundException;
157157

158158
/**
159159
* {@link FlowExecution} implemented with Groovy CPS.
@@ -421,8 +421,8 @@ public CpsFlowExecution(@NonNull String script, boolean sandbox, @NonNull FlowE
421421
this.script = script;
422422
this.sandbox = sandbox;
423423
this.durabilityHint = durabilityHint;
424-
Authentication auth = Jenkins.getAuthentication();
425-
this.user = auth.equals(ACL.SYSTEM) ? null : auth.getName();
424+
Authentication auth = Jenkins.getAuthentication2();
425+
this.user = auth.equals(ACL.SYSTEM2) ? null : auth.getName();
426426
this.storage = createStorage();
427427
this.storage.setAvoidAtomicWrite(!this.getDurabilityHint().isAtomicWrite());
428428
}
@@ -1563,21 +1563,21 @@ void notifyListeners(List<FlowNode> nodes, boolean synchronous) {
15631563
}
15641564
}
15651565

1566-
@Override public Authentication getAuthentication() {
1566+
@Override public Authentication getAuthentication2() {
15671567
if (user == null) {
1568-
return ACL.SYSTEM;
1568+
return ACL.SYSTEM2;
15691569
}
15701570
try {
15711571
User u = User.getById(user, true);
15721572
if (u == null) {
1573-
return Jenkins.ANONYMOUS;
1573+
return Jenkins.ANONYMOUS2;
15741574
} else {
1575-
return u.impersonate();
1575+
return u.impersonate2();
15761576
}
15771577
} catch (UsernameNotFoundException x) {
15781578
LOGGER.log(Level.WARNING, "could not restore authentication", x);
15791579
// Should not expose this to callers.
1580-
return Jenkins.ANONYMOUS;
1580+
return Jenkins.ANONYMOUS2;
15811581
}
15821582
}
15831583

plugin/src/main/java/org/jenkinsci/plugins/workflow/cps/CpsVmExecutorService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ void restore() {
169169

170170
private ThreadContext setUp() {
171171
CpsFlowExecution execution = cpsThreadGroup.getExecution();
172-
ACL.impersonate(execution.getAuthentication());
172+
ACL.impersonate2(execution.getAuthentication2());
173173
CURRENT.set(cpsThreadGroup);
174174
cpsThreadGroup.busy = true;
175175
Thread t = Thread.currentThread();

plugin/src/test/java/org/jenkinsci/plugins/workflow/WorkflowTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ public static final class Execution extends AbstractStepExecutionImpl {
205205
@Override public void onResume() {
206206
super.onResume();
207207
try {
208-
listener.getLogger().println("again running as " + flow.getAuthentication().getName() + " from " + Thread.currentThread().getName());
208+
listener.getLogger().println("again running as " + flow.getAuthentication2().getName() + " from " + Thread.currentThread().getName());
209209
} catch (Exception x) {
210210
getContext().onFailure(x);
211211
}
@@ -214,7 +214,7 @@ public static final class Execution extends AbstractStepExecutionImpl {
214214
public static void finish(final boolean terminate) {
215215
StepExecution.acceptAll(Execution.class, input -> {
216216
try {
217-
input.listener.getLogger().println((terminate ? "finally" : "still") + " running as " + input.flow.getAuthentication().getName() + " from " + Thread.currentThread().getName());
217+
input.listener.getLogger().println((terminate ? "finally" : "still") + " running as " + input.flow.getAuthentication2().getName() + " from " + Thread.currentThread().getName());
218218
if (terminate) {
219219
input.getContext().onSuccess(null);
220220
}

0 commit comments

Comments
 (0)