Skip to content

Commit

Permalink
Fix a compatibility error in CredentialsProvider
Browse files Browse the repository at this point in the history
Prefer calling deprecated overrides of `getCredentials(..., Item, ...)` if implemented rather than resolving closest `ItemGroup`.
  • Loading branch information
Vlatombe committed Nov 8, 2023
1 parent 3757c78 commit 14183ea
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1255,7 +1255,7 @@ public <C extends Credentials> List<C> getCredentials(@NonNull Class<C> 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());
}

/**
Expand All @@ -1267,7 +1267,7 @@ public <C extends Credentials> List<C> getCredentials(@NonNull Class<C> type,
@NonNull Item item,
@Nullable org.acegisecurity.Authentication authentication,
@NonNull List<DomainRequirement> domainRequirements) {
return getCredentialsInItem(type, item, authentication == null ? null : authentication.toSpring(), domainRequirements);
return getCredentialsInItemFallback(type, item, authentication == null ? null : authentication.toSpring(), domainRequirements);
}

/**
Expand All @@ -1287,6 +1287,17 @@ public <C extends Credentials> List<C> getCredentialsInItem(@NonNull Class<C> ty
@NonNull Item item,
@Nullable Authentication authentication,
@NonNull List<DomainRequirement> 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 <C extends Credentials> List<C> getCredentialsInItemFallback(@NonNull Class<C> type, @NonNull Item item, @Nullable Authentication authentication, @NonNull List<DomainRequirement> domainRequirements) {
return getCredentialsInItemGroup(type, item instanceof ItemGroup ? (ItemGroup) item : item.getParent(),
authentication, domainRequirements);
}
Expand Down

0 comments on commit 14183ea

Please sign in to comment.