package org.apereo.cas.services.resource;

import org.apereo.cas.services.RegisteredService;
import org.apereo.cas.util.RegexUtils;

import org.apache.commons.lang3.StringUtils;

import java.util.regex.Pattern;

/**
 * This is {@link RegisteredServiceResourceNamingStrategy}.  Interface to provide naming strategy
 * to resource based services.
 *
 * @author Travis Schmidt
 * @since 5.3.0
 */
@FunctionalInterface
public interface RegisteredServiceResourceNamingStrategy {

    /**
     * Method will be called to provide a name for a resource to store a service.
     *
     * @param service   - The Service to be saved.
     * @param extension - The extension to be used.
     * @return - String representing a resource name.
     */
    String build(RegisteredService service, String extension);

    /**
     * Gets naming pattern.
     *
     * @param extensions the extensions
     * @return the naming pattern
     */
    default Pattern buildNamingPattern(final String... extensions) {
        var pattern = StringUtils.EMPTY;
        if (extensions.length > 0) {
            pattern = String.join("|", extensions);
        }
        return RegexUtils.createPattern("(\\w+)-(\\d+)\\.".concat(pattern));
    }
}

@@ -1128,16 +1128,106 @@
       %7D%0A
+        if (extensions.length %3E 1) %7B%0A            pattern = %22(%22 + pattern + %22)%22;%0A        %7D%0A
         

Fix regex for service file names (#4245)