Optional<JsonWebKeySet> buildJsonWebKeySet(final OidcJsonWebKeyCacheKey cacheKey) {
        try {
            val resource = generateJwksResource();
            if (resource == null) {
                LOGGER.warn("Unable to load or generate a JWKS resource");
                return Optional.empty();
            }
            LOGGER.trace("Retrieving default JSON web key from [{}]", resource);
            val jsonWebKeySet = buildJsonWebKeySet(resource, cacheKey);

            if (jsonWebKeySet == null || jsonWebKeySet.getJsonWebKeys().isEmpty()) {
                LOGGER.warn("No JSON web keys could be found");
                return Optional.empty();
            }
            val badKeysCount = jsonWebKeySet.getJsonWebKeys()
                .stream()
                .filter(key ->
                    StringUtils.isBlank(key.getAlgorithm())
                    && StringUtils.isBlank(key.getKeyId())
                    && StringUtils.isBlank(key.getKeyType())).count();

            if (badKeysCount == jsonWebKeySet.getJsonWebKeys().size()) {
                LOGGER.warn("No valid JSON web keys could be found. The keys that are found in the keystore "
                            + "do not define an algorithm, key id or key type and cannot be used for JWKS operations.");
                return Optional.empty();
            }
            return Optional.of(jsonWebKeySet);
        } catch (final Throwable e) {
            LoggingUtils.warn(LOGGER, e);
        }
        return Optional.empty();
    }
Build json web key set.

@param cacheKey the cache key
@return the json web key set
support/cas-server-support-oidc-core-api/src/main/java/org/apereo/cas/oidc/jwks/OidcDefaultJsonWebKeystoreCacheLoader.java