Skip to content

Commit 8d1c500

Browse files
committed
[JEP-227] Replace Acegi Security with Spring Security APIs
This is the implementation of jenkinsci/jenkins#4848 for Credentials API. This will allow consumers of the credentials API to remove references to deprecated acegi APIs.
1 parent ff276f7 commit 8d1c500

17 files changed

+604
-148
lines changed

src/main/java/com/cloudbees/plugins/credentials/CredentialsParameterDefinition.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717
import java.util.Set;
1818
import jenkins.model.Jenkins;
1919
import net.sf.json.JSONObject;
20-
import org.acegisecurity.Authentication;
2120
import org.apache.commons.lang.StringUtils;
2221
import org.jenkinsci.Symbol;
2322
import org.kohsuke.stapler.AncestorInPath;
2423
import org.kohsuke.stapler.DataBoundConstructor;
2524
import org.kohsuke.stapler.QueryParameter;
2625
import org.kohsuke.stapler.StaplerRequest;
26+
import org.springframework.security.core.Authentication;
2727

2828
/**
2929
* A {@link ParameterDefinition} for a parameter that supplies a {@link Credentials}.
@@ -173,7 +173,7 @@ public StandardListBoxModel doFillDefaultValueItems(@AncestorInPath Item context
173173
final StandardListBoxModel result = new StandardListBoxModel();
174174
result.includeEmptyValue();
175175
if (acl.hasPermission(CredentialsProvider.USE_ITEM)) {
176-
result.includeAs(CredentialsProvider.getDefaultAuthenticationOf(context), context, typeClass, domainRequirements);
176+
result.includeAs(CredentialsProvider.getDefaultAuthenticationOf2(context), context, typeClass, domainRequirements);
177177
}
178178
return result;
179179
}
@@ -185,9 +185,9 @@ public StandardListBoxModel doFillValueItems(@AncestorInPath Item context,
185185
@QueryParameter boolean includeUser) {
186186
Jenkins jenkins = Jenkins.get();
187187
final ACL acl = context == null ? jenkins.getACL() : context.getACL();
188-
final Authentication authentication = Jenkins.getAuthentication();
189-
final Authentication itemAuthentication = CredentialsProvider.getDefaultAuthenticationOf(context);
190-
final boolean isSystem = ACL.SYSTEM.equals(authentication);
188+
final Authentication authentication = Jenkins.getAuthentication2();
189+
final Authentication itemAuthentication = CredentialsProvider.getDefaultAuthenticationOf2(context);
190+
final boolean isSystem = ACL.SYSTEM2.equals(authentication);
191191
final Class<? extends StandardCredentials> typeClass = decodeType(credentialType);
192192
final List<DomainRequirement> domainRequirements = Collections.emptyList();
193193
final StandardListBoxModel result = new StandardListBoxModel();

src/main/java/com/cloudbees/plugins/credentials/CredentialsParameterValue.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
import java.util.Collections;
2222
import java.util.List;
2323
import jenkins.model.Jenkins;
24-
import org.acegisecurity.Authentication;
2524
import org.apache.commons.lang.StringUtils;
2625
import org.kohsuke.stapler.DataBoundConstructor;
2726
import org.kohsuke.stapler.Stapler;
27+
import org.springframework.security.core.Authentication;
2828

2929
/**
3030
* A {@link ParameterValue} produced from a {@link CredentialsParameterDefinition}.
@@ -89,24 +89,24 @@ public <C extends IdCredentials> C lookupCredentials(@NonNull Class<C> type, @No
8989

9090
public <C extends IdCredentials> C lookupCredentials(@NonNull Class<C> type, @NonNull Run run,
9191
List<DomainRequirement> domainRequirements) {
92-
Authentication authentication = Jenkins.getAuthentication();
92+
Authentication authentication = Jenkins.getAuthentication2();
9393
final Executor executor = run.getExecutor();
9494
if (executor != null) {
9595
final WorkUnit workUnit = executor.getCurrentWorkUnit();
9696
if (workUnit != null) {
97-
authentication = workUnit.context.item.authenticate();
97+
authentication = workUnit.context.item.authenticate2();
9898
}
9999
}
100100
List<C> candidates = new ArrayList<>();
101-
final boolean isSystem = ACL.SYSTEM.equals(authentication);
101+
final boolean isSystem = ACL.SYSTEM2.equals(authentication);
102102
if (!isSystem && run.getParent().hasPermission(CredentialsProvider.USE_OWN)) {
103103
candidates.addAll(CredentialsProvider
104104
.lookupCredentials(type, run.getParent(), authentication, domainRequirements));
105105
}
106106
if (run.getParent().hasPermission(CredentialsProvider.USE_ITEM) || isSystem
107107
|| isDefaultValue) {
108108
candidates.addAll(
109-
CredentialsProvider.lookupCredentials(type, run.getParent(), ACL.SYSTEM, domainRequirements));
109+
CredentialsProvider.lookupCredentials(type, run.getParent(), ACL.SYSTEM2, domainRequirements));
110110
}
111111
return CredentialsMatchers.firstOrNull(candidates, CredentialsMatchers.withId(value));
112112
}
@@ -120,14 +120,14 @@ public String describe() {
120120
throw new IllegalStateException("Should only be called from value.jelly");
121121
}
122122
StandardCredentials c = CredentialsMatchers.firstOrNull(
123-
CredentialsProvider.lookupCredentials(StandardCredentials.class, run.getParent(), ACL.SYSTEM,
123+
CredentialsProvider.lookupCredentials(StandardCredentials.class, run.getParent(), ACL.SYSTEM2,
124124
Collections.emptyList()), CredentialsMatchers.withId(value));
125125
if (c != null) {
126126
return CredentialsNameProvider.name(c);
127127
}
128128
c = CredentialsMatchers.firstOrNull(
129129
CredentialsProvider.lookupCredentials(StandardCredentials.class, run.getParent(),
130-
Jenkins.getAuthentication(),
130+
Jenkins.getAuthentication2(),
131131
Collections.emptyList()), CredentialsMatchers.withId(value));
132132
if (c != null) {
133133
return CredentialsNameProvider.name(c);
@@ -144,14 +144,14 @@ public String iconClassName() {
144144
throw new IllegalStateException("Should only be called from value.jelly");
145145
}
146146
StandardCredentials c = CredentialsMatchers.firstOrNull(
147-
CredentialsProvider.lookupCredentials(StandardCredentials.class, run.getParent(), ACL.SYSTEM,
147+
CredentialsProvider.lookupCredentials(StandardCredentials.class, run.getParent(), ACL.SYSTEM2,
148148
Collections.emptyList()), CredentialsMatchers.withId(value));
149149
if (c != null) {
150150
return c.getDescriptor().getIconClassName();
151151
}
152152
c = CredentialsMatchers.firstOrNull(
153153
CredentialsProvider.lookupCredentials(StandardCredentials.class, run.getParent(),
154-
Jenkins.getAuthentication(),
154+
Jenkins.getAuthentication2(),
155155
Collections.emptyList()), CredentialsMatchers.withId(value));
156156
if (c != null) {
157157
return c.getDescriptor().getIconClassName();
@@ -167,7 +167,7 @@ public String url() {
167167
if (run == null) {
168168
throw new IllegalStateException("Should only be called from value.jelly");
169169
}
170-
try (ACLContext ctx = ACL.as(ACL.SYSTEM)) {
170+
try (ACLContext ignored = ACL.as2(ACL.SYSTEM2)) {
171171
for (CredentialsStore store : CredentialsProvider.lookupStores(run.getParent())) {
172172
String url = url(store);
173173
if (url != null) {

0 commit comments

Comments
 (0)