@SuppressWarnings("JdkObsolete")
    public static Resource prepareClasspathResourceIfNeeded(final Resource resource,
                                                            final boolean isDirectory,
                                                            final String containsName) {
        try {
            LOGGER.trace("Preparing possible classpath resource [{}]", resource);
            if (resource == null) {
                LOGGER.debug("No resource defined to prepare.");
                return null;
            }

            if (isFileURL(resource.getURL())) {
                return resource;
            }

            val destination = new File(FileUtils.getTempDirectory(), Objects.requireNonNull(resource.getFilename()));
            if (isDirectory) {
                LOGGER.trace("Creating resource directory [{}]", destination);
                FileUtils.forceMkdir(destination);
                FileUtils.cleanDirectory(destination);
            } else if (destination.exists()) {
                LOGGER.trace("Deleting resource directory [{}]", destination);
                FileUtils.forceDelete(destination);
            }

            val url = extractUrlFromResource(resource);
            val file = getFile(StringUtils.substringBefore(url.toExternalForm(), "/!"));
            LOGGER.trace("Processing file [{}]", file);
            try (val jFile = new JarFile(file)) {
                val e = jFile.entries();
                while (e.hasMoreElements()) {
                    val entry = e.nextElement();
                    val name = entry.getName();
                    LOGGER.trace("Comparing [{}] against [{}] and pattern [{}]", name, resource.getFilename(), containsName);
                    if (name.contains(resource.getFilename()) && RegexUtils.find(containsName, name)) {
                        try (val stream = jFile.getInputStream(entry)) {
                            var copyDestination = destination;
                            if (isDirectory) {
                                val entryFileName = new File(name);
                                copyDestination = new File(destination, entryFileName.getName());
                            }
                            LOGGER.trace("Copying resource entry [{}] to [{}]", name, copyDestination);
                            try (val writer = Files.newBufferedWriter(copyDestination.toPath(), StandardCharsets.UTF_8)) {
                                IOUtils.copy(stream, writer, StandardCharsets.UTF_8);
                            }
                        }
                    }
                }
            }
            return new FileSystemResource(destination);
        } catch (final Exception e) {
            throw new RuntimeException(e);
        }
    }
If the provided resource is a classpath resource, running inside an embedded container,
and if the container is running in a non-exploded form, classpath resources become non-accessible.
So, this method will attempt to move resources out of classpath and onto a physical location
outside the context, typically in the "cas" directory of the temp system folder.

@param resource     the resource
@param isDirectory  the if the resource is a directory, in which case entries will be copied over.
@param containsName the resource name pattern
@return the file
core/cas-server-core-util-api/src/main/java/org/apereo/cas/util/ResourceUtils.java