@PostMapping(produces = {
        MediaType.TEXT_XML_VALUE,
        MediaType.APPLICATION_XML_VALUE,
        MediaType.APPLICATION_JSON_VALUE
    }, consumes = {
        MediaType.TEXT_XML_VALUE,
        MediaType.APPLICATION_XML_VALUE,
        MediaType.APPLICATION_JSON_VALUE,
        MediaType.APPLICATION_FORM_URLENCODED_VALUE
    })
    @Operation(summary = "Handle validation request and produce saml1 payload.", parameters = {
        @Parameter(name = "username", required = true, description = "The username"),
        @Parameter(name = "password", required = false, description = "The password"),
        @Parameter(name = "service", required = true, description = "The service")
    })
    public ResponseEntity handle(
        final HttpServletRequest request,
        final String username,
        @RequestParam(required = false) final String password,
        final String service) throws Throwable {
        val selectedService = serviceFactory.getObject().createService(service);
        val authentication = buildAuthentication(username, password, selectedService);

        val registeredService = servicesManager.getObject().findServiceBy(selectedService);
        val audit = AuditableContext.builder()
            .service(selectedService)
            .authentication(authentication)
            .registeredService(registeredService)
            .build();
        val accessResult = registeredServiceAccessStrategyEnforcer.getObject().execute(audit);
        accessResult.throwExceptionIfNeeded();

        val principal = authentication.getPrincipal();

        val context = RegisteredServiceAttributeReleasePolicyContext
            .builder()
            .registeredService(registeredService)
            .service(selectedService)
            .principal(principal)
            .applicationContext(openSamlConfigBean.getObject().getApplicationContext())
            .build();
        val attributesToRelease = registeredService.getAttributeReleasePolicy().getAttributes(context);

        val usernameContext = RegisteredServiceUsernameProviderContext
            .builder()
            .registeredService(registeredService)
            .service(selectedService)
            .principal(principal)
            .applicationContext(openSamlConfigBean.getObject().getApplicationContext())
            .build();
        val principalId = registeredService.getUsernameAttributeProvider().resolveUsername(usernameContext);

        val modifiedPrincipal = principalFactory.getObject().createPrincipal(principalId, attributesToRelease);
        val builder = DefaultAuthenticationBuilder.newInstance(authentication);
        builder.setPrincipal(modifiedPrincipal);
        val finalAuthentication = builder.build();

        val samlResponse = samlResponseBuilder.getObject().createResponse(selectedService.getId(), selectedService);
        samlResponseBuilder.getObject().prepareSuccessfulResponse(Map.of(), samlResponse, selectedService, finalAuthentication, principal,
            finalAuthentication.getAttributes(), principal.getAttributes());

        val encoded = SamlUtils.transformSamlObject(openSamlConfigBean.getObject(), samlResponse).toString();

        val contentType = StringUtils.defaultIfBlank(request.getHeader(HttpHeaders.CONTENT_TYPE), MediaType.APPLICATION_JSON_VALUE);
        if (MediaType.APPLICATION_XML_VALUE.equals(contentType) || MediaType.TEXT_XML_VALUE.equals(contentType)) {
            val headers = new HttpHeaders();
            headers.put(HttpHeaders.CONTENT_TYPE, List.of(MediaType.TEXT_XML_VALUE));
            return new ResponseEntity<>(encoded, headers, HttpStatus.OK);
        }

        val resValidation = new LinkedHashMap<String, Object>();
        resValidation.put(CasViewConstants.MODEL_ATTRIBUTE_NAME_ASSERTION, encoded);
        resValidation.put(CasViewConstants.MODEL_ATTRIBUTE_NAME_SERVICE, selectedService);
        resValidation.put("registeredService", registeredService);
        val headers = new HttpHeaders();
        headers.put(HttpHeaders.CONTENT_TYPE, List.of(MediaType.APPLICATION_JSON_VALUE));
        return new ResponseEntity<>(resValidation, headers, HttpStatus.OK);
    }
Handle validation request and produce saml1 payload.

@param request  the request
@param username the username
@param password the password
@param service  the service
@return the map
@throws Throwable the throwable
support/cas-server-support-saml/src/main/java/org/apereo/cas/support/saml/web/SamlValidateEndpoint.java