private ResponseEntity<Object> produce(final HttpServletRequest request,
                                           final HttpServletResponse response,
                                           final SamlRequest samlRequest) {
        try {
            val selectedService = serviceFactory.createService(samlRequest.getEntityId());
            val registeredService = servicesManager.findServiceBy(selectedService, SamlRegisteredService.class);
            RegisteredServiceAccessStrategyUtils.ensureServiceAccessIsAllowed(selectedService, registeredService);

            val loadedService = new SamlRegisteredService();
            BeanUtils.copyProperties(registeredService, loadedService);
            loadedService.setEncryptAssertions(samlRequest.isEncrypt());
            loadedService.setEncryptAttributes(samlRequest.isEncrypt());

            val authnRequest = new AuthnRequestBuilder().buildObject();
            authnRequest.setIssuer(saml20ObjectBuilder.newIssuer(samlRequest.getEntityId()));

            val result = SamlRegisteredServiceMetadataAdaptor.get(defaultSamlRegisteredServiceCachingMetadataResolver, loadedService, samlRequest.getEntityId());
            return result
                .map(Unchecked.function(adaptor -> {
                    val messageContext = new MessageContext();
                    val scratch = messageContext.ensureSubcontext(ScratchContext.class);
                    val map = (Map) Objects.requireNonNull(scratch).getMap();
                    map.put(SamlProtocolConstants.PARAMETER_ENCODE_RESPONSE, Boolean.FALSE);
                    val assertion = getAssertion(samlRequest);
                    val buildContext = SamlProfileBuilderContext.builder()
                        .samlRequest(authnRequest)
                        .httpRequest(request)
                        .httpResponse(response)
                        .authenticatedAssertion(Optional.of(assertion))
                        .registeredService(loadedService)
                        .adaptor(adaptor)
                        .binding(SAMLConstants.SAML2_POST_BINDING_URI)
                        .messageContext(messageContext)
                        .build();
                    val object = responseBuilder.build(buildContext);
                    val encoded = SamlUtils.transformSamlObject(saml20ObjectBuilder.getOpenSamlConfigBean(), object, true).toString();
                    return new ResponseEntity<Object>(encoded, HttpStatus.OK);
                }))
                .orElseThrow(() -> new SamlException("Unable to locate " + samlRequest.getEntityId()));
        } catch (final Throwable e) {
            LoggingUtils.error(LOGGER, e);
            return new ResponseEntity<>(StringEscapeUtils.escapeHtml4(e.getMessage()), HttpStatus.BAD_REQUEST);
        }
    }
Produce logout request post.

@param entityId the entity id
@param response the response
@return the response entity
@throws Exception the exception
support/cas-server-support-saml-idp-web/src/main/java/org/apereo/cas/support/saml/web/idp/profile/sso/SSOSamlIdPPostProfileHandlerEndpoint.java