protected Optional<OIDCClientMetadata> fetchRelyingPartyMetadata(final TrustChainResolver trustChainResolver,
                                                                     final EntityID entityId) {
        return FunctionUtils.doAndHandle(() -> {
            val resolvedChains = trustChainResolver.resolveTrustChains(entityId);
            val chain = resolvedChains.getShortest();
            val metadataPolicy = chain.resolveCombinedMetadataPolicy(EntityType.OPENID_RELYING_PARTY);

            val claims = chain.getLeafConfiguration().getSignedStatement().getJWTClaimsSet();
            val rawRp = (JSONObject) claims.getClaim(EntityType.OPENID_RELYING_PARTY.getValue());
            val clientMetadataJson = metadataPolicy.apply(rawRp);
            return Optional.of(OIDCClientMetadata.parse(clientMetadataJson));
        }, e -> Optional.<OIDCClientMetadata>empty()).get();
    }
This is {@link OidcFederationDefaultTrustChainResolver}.

@author Misagh Moayyed
@since 7.3.0
support/cas-server-support-oidc-core-api/src/main/java/org/apereo/cas/oidc/federation/OidcFederationDefaultTrustChainResolver.java