public static String determineBucketNameFor(final Optional<SamlRegisteredService> result,
                                                final String bucketName,
                                                final S3Client s3Client) {
        if (result.isPresent()) {
            val bucket = getBucketForService(result.get());
            if (s3Client.listBuckets(ListBucketsRequest.builder().build())
                .buckets().stream().anyMatch(foundBucket -> foundBucket.name().equalsIgnoreCase(bucket))) {
                return bucket;
            }
        }
        return bucketName;
    }
Determine bucket name for service.

@param result     the result
@param bucketName the bucket name
@param s3Client   the s 3 client
@return the bucket name
support/cas-server-support-saml-idp-metadata-aws-s3/src/main/java/org/apereo/cas/support/saml/idp/metadata/AmazonS3SamlIdPMetadataUtils.java