@Override
    protected Response encode(final SamlProfileBuilderContext context,
                              final Response samlResponse,
                              final String relayState) {
        LOGGER.trace("Constructing encoder based on binding [{}] for [{}]", context.getBinding(), context.getAdaptor().getEntityId());
        if (context.getBinding().equalsIgnoreCase(SAMLConstants.SAML2_ARTIFACT_BINDING_URI)) {
            val encoder = new SamlResponseArtifactEncoder(
                getConfigurationContext().getVelocityEngineFactory(),
                context.getAdaptor(), context.getHttpRequest(), context.getHttpResponse(),
                getConfigurationContext().getSamlArtifactMap());
            return encoder.encode(context.getSamlRequest(), samlResponse, relayState, context.getMessageContext());
        }

        if (context.getBinding().equalsIgnoreCase(SAMLConstants.SAML2_POST_SIMPLE_SIGN_BINDING_URI)) {
            val encoder = new SamlResponsePostSimpleSignEncoder(getConfigurationContext().getVelocityEngineFactory(),
                context.getAdaptor(), context.getHttpResponse(), context.getHttpRequest());
            return encoder.encode(context.getSamlRequest(), samlResponse, relayState, context.getMessageContext());
        }

        val encoder = new SamlResponsePostEncoder(getConfigurationContext().getVelocityEngineFactory(), context.getAdaptor(), context.getHttpResponse(), context.getHttpRequest());
        return encoder.encode(context.getSamlRequest(), samlResponse, relayState, context.getMessageContext());
    }
This is {@link SamlProfileSaml2ResponseBuilder}.

@author Misagh Moayyed
@since 5.1.0
support/cas-server-support-saml-idp-web/src/main/java/org/apereo/cas/support/saml/web/idp/profile/builders/response/SamlProfileSaml2ResponseBuilder.java