@Override
    public HttpResponse loginSucceeded(ServiceRequestContext ctx, AggregatedHttpRequest req,
                                       MessageContext<Response> message, @Nullable String sessionIndex,
                                       @Nullable String relayState) {
        final NameID nameId = getNameId(message.getMessage(), SamlNameIdFormat.EMAIL);
        final String username = nameId != null ? nameId.getValue() : null;
        if (username == null) {
            return HttpResponse.of(HttpStatus.UNAUTHORIZED, MediaType.HTML_UTF_8,
                                   "<html><body>Username is not found.</body></html>");
        }

        logger.info("{} user '{}' has been logged in.", ctx, username);

        final Cookie cookie = Cookie.secureBuilder("username", username)
                                    .domain("localhost")
                                    .maxAge(60)
                                    .path("/")
                                    .build();
        return HttpResponse.of(ResponseHeaders.builder(HttpStatus.OK)
                                              .contentType(MediaType.HTML_UTF_8)
                                              .cookies(cookie).build(),
                               HttpData.ofUtf8(
                                       "<html><body onLoad=\"window.location.href='/welcome'\"></body></html>"));
    }
Invoked when the SAML authentication process is finished and a user is authenticated. You can get
information about the authenticated user from the {@link Response}, especially his or her login name.
In this example, an email address is used as a login name. The login name is transferred to a web
browser via {@code Set-Cookie} header.
examples/saml-service-provider/src/main/java/example/armeria/server/saml/sp/MyAuthHandler.java