protected MessageContext getEncoderMessageContext(final RequestAbstractType request, final T samlObject,
                                                      final String relayState, final MessageContext messageContext) {
        val ctx = new MessageContext();
        ctx.setMessage(samlObject);
        ctx.addSubcontext(messageContext.ensureSubcontext(SAMLBindingContext.class));
        SAMLBindingSupport.setRelayState(ctx, relayState);
        SamlIdPUtils.preparePeerEntitySamlEndpointContext(Pair.of(request, messageContext), ctx, adaptor, getBinding());
        val self = ctx.ensureSubcontext(SAMLSelfEntityContext.class);
        self.setEntityId(SamlIdPUtils.getIssuerFromSamlObject(samlObject));
        return ctx;
    }
Build encoder message context.

@param request        the authn request
@param samlObject     the saml response
@param relayState     the relay state
@param messageContext the message context
@return the message context
support/cas-server-support-saml-idp-web/src/main/java/org/apereo/cas/support/saml/web/idp/profile/builders/enc/encoder/BaseHttpServletAwareSamlObjectEncoder.java