Skip to content

Commit 353cb48

Browse files
authored
Merge branch 'master' into JENKINS-70101
2 parents c2ca4f4 + 8ce5720 commit 353cb48

File tree

23 files changed

+381
-1264
lines changed

23 files changed

+381
-1264
lines changed

docs/consumer.adoc

Lines changed: 10 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -281,26 +281,6 @@ We leverage the https://plugins.jenkins.io/authentication-tokens[Authentication
281281
This means that we can use the `AuthenticationTokens.matcher(Class)` to restrict the list of credentials to the subset that can be converted.
282282
Alternatively, more complex conversion contexts can be handled with `AuthenticationTokens.matcher(AuthenticationTokenContext)`
283283

284-
* We want to let the user select the credentials to toggle the deployment state of a blue/green deployment for a completed build.
285-
+
286-
[source,java]
287-
----
288-
CredentialsProvider.listCredentialsInItem(
289-
StandardCredentials.class, // <1>
290-
job,
291-
Jenkins.getAuthentication2(), // <2>
292-
URIRequirementBuilder.fromUri(loadBalancerUrl),
293-
CredentialsMatchers.allOf(
294-
AuthenticationTokens.matcher(LoadBalancerAuthentication.class),
295-
CredentialsMatchers.withProperty("permission", "lb.switch") // <3>
296-
)
297-
)
298-
----
299-
<1> There are different credential types that can be used to authenticate with the load balancer, this is the common base class.
300-
<2> This is an immediate action performed by the user.
301-
<3> In this case there may be multiple credentials available to the user, we only want the ones with `"lb.switch".equals(credential.getPermission())`.
302-
Any credentials that do not have a `getPermission()` method will be excluded as well as any that do not have the corresponding return value.
303-
304284
* We want to let the user specify the credentials used to update the post commit receive hooks of a source control system for any corresponding jobs configured in Jenkins.
305285
+
306286
[NOTE]
@@ -379,24 +359,21 @@ If we have a job, "foobar", and we configure a credentials parameter on that job
379359

380360
If you are working outside the context of a `Run` then you will not have to deal with the complexities of credentials expressions.
381361

382-
In most cases the retrieval will just be a call to one of the `CredentialsProvider.lookupCredentialsInItem(...)`/`CredentialsProvider.lookupCredentialsInItemGroup(...)` wrapped within `CredentialsMatchers.firstOrNull(..., CredentialsMatchers.withId(...))`, for example:
362+
In most cases the retrieval will just be a call to `CredentialsProvider.findCredentialByIdInItemGroup` or `CredentialsProvider.findCredentialByIdInItem`:
383363

384364
[source,java]
385365
----
386-
StandardCredentials c = CredentialsMatchers.firstOrNull(
387-
CredentialsProvider.lookupCredentialsInItem(
366+
StandardCredentials c = CredentialsProvider.findCredentialByIdInItem(
367+
credentialsId,
388368
StandardCredentials.class, // <1>
389369
job, // <1>
390370
job instanceof Queue.Task // <1>
391371
? Tasks.getAuthenticationOf((Queue.Task)job))
392372
: ACL.SYSTEM2,
393373
URIRequirementBuilder.fromUri(...) // <1>
394-
),
395-
CredentialsMatchers.withId(credentialsId) // <2>
396-
);
374+
);
397375
----
398376
<1> These should be the same as your call to `CredentialsProvider.listCredentialsInItem(...)`/`CredentialsProvider.listCredentialsInItemGroup(...)`/`StandardListBoxModel.includeMatchingAs(...)` in order to ensure that we get the same credential instance back.
399-
<2> If you had additional `CredentialsMatcher` expressions in your call to `CredentialsProvider.listCredentialsInItem(...)`/`CredentialsProvider.listCredentialsInItemGroup(...)`/`StandardListBoxModel.includeMatchingAs(...)` then you should merge them here with a `CredentialsMatchers.allOf(...)`
400377

401378
Once you have retrieved a non-null credentials instance, all non-secret properties can be assumed as eager-fetch immutable.
402379

@@ -412,20 +389,18 @@ The recommended way to use a credential is through the https://plugins.jenkins.i
412389

413390
[source,java]
414391
----
415-
StandardCredentials c = CredentialsMatchers.firstOrNull( // <1>
416-
CredentialsProvider.listCredentialsInItem(
392+
StandardCredentials c = CredentialsProvider.findCredentialByIdInItem( // <1>
393+
credentialsId,
417394
StandardCredentials.class,
418395
job,
419396
job instanceof Queue.Task
420397
? Tasks.getAuthenticationOf2((Queue.Task)job))
421398
: ACL.SYSTEM2,
422399
URIRequirementBuilder.fromUri(issueTrackerUrl)
423-
),
424-
CredentialsMatchers.allOf(
425-
CredentialsMatchers.withId(credentialsId),
426-
AuthenticationTokens.matcher(IssueTrackerAuthentication.class) // <2>
427-
)
428-
);
400+
);
401+
if (c != null && !AuthenticationTokens.matcher(IssueTrackerAuthentication.class).matches(c)) {
402+
c = null;
403+
}
429404
IssueTrackerAuthentication auth = AuthenticationTokens.convert(
430405
IssueTrackerAuthentication.class, // <2>
431406
c // <3>
@@ -449,32 +424,6 @@ StandardCredentials c = ...;
449424
CredentialsProvider.track(job, c);
450425
----
451426

452-
In most cases we can avoid holding object references longer than necessary by combining all these methods together:
453-
454-
[source,java]
455-
----
456-
IssueTrackerAuthentication auth = AuthenticationTokens.convert(
457-
IssueTrackerAuthentication.class,
458-
CredentialsProvider.track(
459-
job,
460-
CredentialsMatchers.firstOrNull(
461-
CredentialsProvider.listCredentialsInItem(
462-
StandardCredentials.class,
463-
job,
464-
job instanceof Queue.Task
465-
? Tasks.getAuthenticationOf2((Queue.Task)job))
466-
: ACL.SYSTEM2,
467-
URIRequirementBuilder.fromUri(issueTrackerUrl)
468-
),
469-
CredentialsMatchers.allOf(
470-
CredentialsMatchers.withId(credentialsId),
471-
AuthenticationTokens.matcher(IssueTrackerAuthentication.class)
472-
)
473-
)
474-
)
475-
);
476-
----
477-
478427
=== Binding user supplied credentials parameters to builds
479428

480429
A running build can be supplied with credentials parameter values.

docs/implementation.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,6 @@ The `CredentialsProvider` extension point is perhaps one of the more complicated
576576
* Where the backing store is remote from Jenkins then:
577577

578578
** potentially has to be able to either instantiate `java.lang.reflect.Proxy` implementations for credentials, or create on-demand implementation classes using http://asm.ow2.org/[ASM] (or similar).
579-
** potentially has to deal with parsing the `CredentialsMatcher` query language in order to minimize transfer of information over the network.
580579
** may need to store Jenkins specific state in Jenkins in order to provide credentials domain support.
581580

582581
* Where the backing store is local to Jenkins but contextual to a specific Jenkins model object and not covered by the three existing credentials providers: System, User and Folder, then replication of that code will likely be required.
@@ -597,7 +596,6 @@ These existing examples are probably not good as reference examples as they have
597596
+
598597
A good reference implementation would be clean of such distractions.
599598
* [ ] Provide links to some other implementations of credentials providers for other use cases.
600-
* [ ] Provide some details on how the Credentials Query Language can be used to limit querying credentials from the remote service
601599
602600
====
603601

@@ -698,6 +696,8 @@ Listing credentials operations are normally restricted to the population of cred
698696
Such requests are AJAX requests, so we have the option to block without affecting the rest of the Jenkins UI.
699697
700698
Blocking for more than between 5 and 10 seconds, however, will cause user frustration, thus for this type of request we try to serve the response live and fall-back to the cache if the live response takes too long.
699+
700+
Runtime lookups of credentials is normally limited to loading a specific credential by id, so consider overriding the methods which take an id argument.
701701
====
702702

703703
These different caching concerns are addresses at different points in the credentials API:

pom.xml

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
<parent>
3030
<groupId>org.jenkins-ci.plugins</groupId>
3131
<artifactId>plugin</artifactId>
32-
<version>5.2102.v5f5fe09fccf1</version>
32+
<version>6.2122.v70b_7b_f659d72</version>
3333
<relativePath />
3434
</parent>
3535

@@ -212,23 +212,6 @@
212212
<compatibleSinceVersion>1354</compatibleSinceVersion>
213213
</configuration>
214214
</plugin>
215-
<plugin>
216-
<groupId>org.antlr</groupId>
217-
<artifactId>antlr4-maven-plugin</artifactId>
218-
<!-- This must be compatible with the ANTLR runtime provided by Jenkins core. -->
219-
<version>4.13.2</version>
220-
<configuration>
221-
<listener>true</listener>
222-
<visitor>true</visitor>
223-
</configuration>
224-
<executions>
225-
<execution>
226-
<goals>
227-
<goal>antlr4</goal>
228-
</goals>
229-
</execution>
230-
</executions>
231-
</plugin>
232215
</plugins>
233216
</build>
234217
</project>

0 commit comments

Comments
 (0)