private String buildAuthnContextClassRefValue(final SamlProfileBuilderContext context) {
        val assignedContextClass = context.getRegisteredService().getRequiredAuthenticationContextClass();
        if (StringUtils.isNotBlank(assignedContextClass)) {
            LOGGER.debug("Using [{}] as indicated by SAML registered service [{}]",
                assignedContextClass, context.getRegisteredService().getName());
            val scriptFactory = ExecutableCompiledScriptFactory.findExecutableCompiledScriptFactory();
            if (scriptFactory.isPresent() && scriptFactory.get().isScript(assignedContextClass)) {
                val requiredClass = scriptFactory.get().isExternalScript(assignedContextClass)
                    ? SpringExpressionLanguageValueResolver.getInstance().resolve(assignedContextClass)
                    : assignedContextClass;
                return buildScriptedAuthnContextClassRef(context, requiredClass);
            }
            return SpringExpressionLanguageValueResolver.getInstance().resolve(assignedContextClass);
        }

        val defClass = getDefaultAuthenticationContextClass();
        val requestedAuthnContext = context.getSamlRequest() instanceof final AuthnRequest authnRequest
            ? authnRequest.getRequestedAuthnContext() : null;
        if (requestedAuthnContext == null) {
            LOGGER.debug("No specific authN context is requested. Returning [{}]", defClass);
            return buildDefaultAuthenticationContextClass(defClass, context);
        }
        val authnContextClassRefs = requestedAuthnContext.getAuthnContextClassRefs();
        if (authnContextClassRefs == null || authnContextClassRefs.isEmpty()) {
            LOGGER.debug("Requested authN context class ref is unspecified. Returning [{}]", defClass);
            return buildDefaultAuthenticationContextClass(defClass, context);
        }

        val contextInAssertion = getAuthenticationContextByAssertion(context,
            requestedAuthnContext, authnContextClassRefs);
        val finalCtx = StringUtils.defaultIfBlank(contextInAssertion, defClass);
        LOGGER.debug("Returning authentication context [{}]", finalCtx);
        return finalCtx;
    }
This is {@link SamlProfileAuthnContextClassRefBuilder}.

@author Misagh Moayyed
@since 5.0.0
support/cas-server-support-saml-idp-web/src/main/java/org/apereo/cas/support/saml/web/idp/profile/builders/authn/SamlProfileAuthnContextClassRefBuilder.java