@Override
    public Assertion build(final SamlProfileBuilderContext context) throws Exception {

        val statements = new ArrayList<Statement>();
        val authnStatement = samlProfileSamlAuthNStatementBuilder.build(context);
        statements.add(authnStatement);
        val attrStatement = samlProfileSamlAttributeStatementBuilder.build(context);

        if (!attrStatement.getAttributes().isEmpty() || !attrStatement.getEncryptedAttributes().isEmpty()) {
            statements.add(attrStatement);
        }

        val issuerId = FunctionUtils.doIf(StringUtils.isNotBlank(context.getRegisteredService().getIssuerEntityId()),
                context.getRegisteredService()::getIssuerEntityId,
                Unchecked.supplier(() -> {
                    val criteriaSet = new CriteriaSet(
                        new EvaluableEntityRoleEntityDescriptorCriterion(IDPSSODescriptor.DEFAULT_ELEMENT_NAME),
                        new SamlIdPSamlRegisteredServiceCriterion(context.getRegisteredService()));
                    LOGGER.trace("Resolving entity id from SAML2 IdP metadata to determine issuer for [{}]", context.getRegisteredService().getName());
                    val entityDescriptor = Objects.requireNonNull(samlIdPMetadataResolver.resolveSingle(criteriaSet));
                    return entityDescriptor.getEntityID();
                }))
            .get();

        val id = '_' + String.valueOf(RandomUtils.nextLong());
        val assertion = newAssertion(statements, issuerId, ZonedDateTime.now(ZoneOffset.UTC), id);
        assertion.setSubject(samlProfileSamlSubjectBuilder.build(context));
        assertion.setConditions(samlProfileSamlConditionsBuilder.build(context));

        val customizers = openSamlConfigBean.getApplicationContext()
            .getBeansOfType(SamlIdPResponseCustomizer.class).values();
        customizers.stream()
            .sorted(AnnotationAwareOrderComparator.INSTANCE)
            .forEach(customizer -> customizer.customizeAssertion(context, this, assertion));
        signAssertion(assertion, context);
        return assertion;
    }
This is {@link SamlProfileSamlAssertionBuilder}.

@author Misagh Moayyed
@since 5.0.0
support/cas-server-support-saml-idp-web/src/main/java/org/apereo/cas/support/saml/web/idp/profile/builders/assertion/SamlProfileSamlAssertionBuilder.java