public static <T> T executeGroovyShellScript(final Script script,
                                                 final Map<String, Object> variables,
                                                 final Class<T> clazz) {
        try {
            val binding = script.getBinding();
            if (!binding.hasVariable("logger")) {
                binding.setVariable("logger", LOGGER);
            }
            if (variables != null && !variables.isEmpty()) {
                variables.forEach(binding::setVariable);
            }
            script.setBinding(binding);
            LOGGER.debug("Executing groovy script [{}] with variables [{}]", script, binding.getVariables());

            val result = script.run();
            return getGroovyScriptExecutionResultOrThrow(clazz, result);
        } catch (final Exception e) {
            LoggingUtils.error(LOGGER, e);
        }
        return null;
    }
Execute groovy shell script t.

@param <T>       the type parameter
@param script    the script
@param variables the variables
@param clazz     the clazz
@return the t
core/cas-server-core-scripting/src/main/java/org/apereo/cas/util/scripting/ScriptingUtils.java