private static String fetchAttributeValue(final RegisteredServiceUsernameProviderContext context,
                                              final String groovyScript) throws Throwable {
        val cacheMgr = ApplicationContextProvider.getScriptResourceCacheManager()
            .orElseThrow(() -> new RuntimeException("No groovy script cache manager is available to execute username provider"));
        val script = cacheMgr.resolveScriptableResource(groovyScript,
            context.getRegisteredService().getServiceId(), context.getRegisteredService().getName());
        return Optional.ofNullable(fetchAttributeValueFromScript(script, context.getPrincipal(), context.getService()))
            .map(Object::toString)
            .orElse(null);
    }
Resolves the username for the service to be the default principal id.

@author Misagh Moayyed
@since 4.1.0
core/cas-server-core-services-api/src/main/java/org/apereo/cas/services/GroovyRegisteredServiceUsernameProvider.java