@Override
    public HttpResponse serve(ServiceRequestContext ctx, HttpRequest req) throws Exception {
        final SamlServiceFunction func = serviceMap.get(req.path());
        if (func == null) {
            return HttpResponse.of(HttpStatus.BAD_REQUEST, MediaType.PLAIN_TEXT_UTF_8,
                                   DATA_INCORRECT_PATH);
        }

        final CompletionStage<AggregatedHttpRequest> f;
        if (portConfigHolder.isDone()) {
            f = req.aggregate();
        } else {
            f = portConfigHolder.future().thenCompose(unused -> req.aggregate());
        }
        return HttpResponse.of(f.handleAsync((aggregatedReq, cause) -> {
            if (cause != null) {
                cause = Exceptions.peel(cause);
                if (cause instanceof HttpStatusException || cause instanceof HttpResponseException) {
                    return HttpResponse.ofFailure(cause);
                }
                logger.warn("{} Failed to aggregate a SAML request.", ctx, cause);
                return HttpResponse.of(HttpStatus.BAD_REQUEST, MediaType.PLAIN_TEXT_UTF_8,
                                       DATA_AGGREGATION_FAILURE);
            }

            final SamlPortConfig portConfig = portConfigHolder.config();
            assert portConfig != null;

            final boolean isTls = ctx.sessionProtocol().isTls();
            if (portConfig.scheme().isTls() != isTls) {
                if (isTls) {
                    logger.warn("{} Received a SAML request via a TLS connection.", ctx);
                    return HttpResponse.of(HttpStatus.BAD_REQUEST, MediaType.PLAIN_TEXT_UTF_8,
                                           DATA_NOT_CLEARTEXT);
                } else {
                    logger.warn("{} Received a SAML request via a cleartext connection.", ctx);
                    return HttpResponse.of(HttpStatus.BAD_REQUEST, MediaType.PLAIN_TEXT_UTF_8,
                                           DATA_NOT_TLS);
                }
            }

            // Use user-specified hostname if it exists.
            // If there's no hostname set by a user, the default virtual hostname will be used.
            final String defaultHostname =
                    firstNonNull(sp.hostname(), ctx.config().virtualHost().defaultHostname());
            // assertion, logout requests incur blocking calls
            return func.serve(ctx, aggregatedReq, defaultHostname, portConfig);
        }, ctx.blockingTaskExecutor()));
    }
An {@link HttpService} which handles SAML APIs, such as consuming an assertion, retrieving a metadata
or handling a logout request from an identity provider.
saml/src/main/java/com/linecorp/armeria/server/saml/SamlService.java