From 14183ea88744f6c43cd9eca98b1a8418a35b865f Mon Sep 17 00:00:00 2001 From: Vincent Latombe Date: Wed, 8 Nov 2023 05:27:37 -0800 Subject: [PATCH] Fix a compatibility error in `CredentialsProvider` Prefer calling deprecated overrides of `getCredentials(..., Item, ...)` if implemented rather than resolving closest `ItemGroup`. --- .../plugins/credentials/CredentialsProvider.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/cloudbees/plugins/credentials/CredentialsProvider.java b/src/main/java/com/cloudbees/plugins/credentials/CredentialsProvider.java index 296e57154..8afe42deb 100644 --- a/src/main/java/com/cloudbees/plugins/credentials/CredentialsProvider.java +++ b/src/main/java/com/cloudbees/plugins/credentials/CredentialsProvider.java @@ -1255,7 +1255,7 @@ public List getCredentials(@NonNull Class type, @NonNull Item item, @Nullable org.acegisecurity.Authentication authentication) { Objects.requireNonNull(item); - return getCredentialsInItemGroup(type, item.getParent(), authentication == null ? null : authentication.toSpring(), List.of()); + return getCredentialsInItemFallback(type, item, authentication == null ? null : authentication.toSpring(), List.of()); } /** @@ -1267,7 +1267,7 @@ public List getCredentials(@NonNull Class type, @NonNull Item item, @Nullable org.acegisecurity.Authentication authentication, @NonNull List domainRequirements) { - return getCredentialsInItem(type, item, authentication == null ? null : authentication.toSpring(), domainRequirements); + return getCredentialsInItemFallback(type, item, authentication == null ? null : authentication.toSpring(), domainRequirements); } /** @@ -1287,6 +1287,17 @@ public List getCredentialsInItem(@NonNull Class ty @NonNull Item item, @Nullable Authentication authentication, @NonNull List domainRequirements) { + if (Util.isOverridden(CredentialsProvider.class, getClass(), "getCredentials", Class.class, Item.class, org.acegisecurity.Authentication.class, List.class)) { + return getCredentials(type, item, authentication == null ? null : org.acegisecurity.Authentication.fromSpring(authentication), domainRequirements); + } + if (Util.isOverridden(CredentialsProvider.class, getClass(), "getCredentials", Class.class, Item.class, org.acegisecurity.Authentication.class)) { + return getCredentials(type, item, authentication == null ? null : org.acegisecurity.Authentication.fromSpring(authentication)); + } + return getCredentialsInItemFallback(type, item, authentication, domainRequirements); + } + + @NonNull + private List getCredentialsInItemFallback(@NonNull Class type, @NonNull Item item, @Nullable Authentication authentication, @NonNull List domainRequirements) { return getCredentialsInItemGroup(type, item instanceof ItemGroup ? (ItemGroup) item : item.getParent(), authentication, domainRequirements); }