public void prepareSuccessfulResponse(final Map<String, Object> model,
                                          final Response response,
                                          final Service service,
                                          final Authentication authentication,
                                          final Principal principal,
                                          final Map<String, List<Object>> authnAttributes,
                                          final Map<String, List<Object>> principalAttributes) {

        val issuedAt = DateTimeUtils.zonedDateTimeOf(response.getIssueInstant());
        LOGGER.debug("Preparing SAML response for service [{}] issued at [{}]", service, issuedAt);

        val authnMethods = CollectionUtils.toCollection(authentication.getAttributes()
            .get(SamlAuthenticationMetaDataPopulator.ATTRIBUTE_AUTHENTICATION_METHOD));
        LOGGER.debug("Authentication methods found are [{}]", authnMethods);

        val authnStatement = samlObjectBuilder.newAuthenticationStatement(
            authentication.getAuthenticationDate(), authnMethods, principal.getId());
        LOGGER.debug("Built authentication statement for [{}] dated at [{}]", principal, authentication.getAuthenticationDate());

        val assertion = samlObjectBuilder.newAssertion(authnStatement, issuer, issuedAt,
            Saml20HexRandomIdGenerator.INSTANCE.getNewString());
        LOGGER.debug("Built assertion for issuer [{}] dated at [{}]", issuer, issuedAt);

        val skewIssueInSeconds = Beans.newDuration(issueLength).toSeconds();
        val conditions = samlObjectBuilder.newConditions(issuedAt, service.getId(), skewIssueInSeconds);
        assertion.setConditions(conditions);
        LOGGER.debug("Built assertion conditions for issuer [{}] and service [{}] ", issuer, service.getId());

        val subject = samlObjectBuilder.newSubject(principal.getId());
        LOGGER.debug("Built subject for principal [{}]", subject);

        val attributesToSend = prepareSamlAttributes(model, service, authnAttributes, principalAttributes);
        LOGGER.debug("Authentication statement shall include these attributes [{}]", attributesToSend);

        if (!attributesToSend.isEmpty()) {
            assertion.getAttributeStatements().add(samlObjectBuilder.newAttributeStatement(
                subject, attributesToSend, defaultAttributeNamespace));
        }

        response.setStatus(samlObjectBuilder.newStatus(StatusCode.SUCCESS, null));
        LOGGER.debug("Set response status code to [{}]", response.getStatus());

        response.getAssertions().add(assertion);
    }
Prepare successful response.

@param response            the response
@param service             the service
@param authentication      the authentication
@param principal           the principal
@param authnAttributes     the authn attributes
@param principalAttributes the principal attributes
support/cas-server-support-saml/src/main/java/org/apereo/cas/support/saml/authentication/SamlResponseBuilder.java