protected void signAssertion(final Assertion assertion,
                                 final SamlProfileBuilderContext context) throws Exception {
        var signAssertions = (context.getRegisteredService().getSignAssertions() == TriStateBoolean.UNDEFINED && context.getAdaptor().isWantAssertionsSigned())
                             || context.getRegisteredService().getSignAssertions().isTrue();
        if (!signAssertions) {
            signAssertions = SamlIdPUtils.doesEntityDescriptorMatchEntityAttribute(context.getAdaptor().getEntityDescriptor(),
                List.of(MetadataEntityAttributeQuery.of(SamlIdPConstants.KnownEntityAttributes.SHIBBOLETH_SIGN_ASSERTIONS.getName(),
                    Attribute.URI_REFERENCE, List.of(Boolean.TRUE.toString()))));
        }
        
        if (signAssertions) {
            LOGGER.debug("SAML registered service [{}] requires assertions to be signed", context.getAdaptor().getEntityId());
            samlObjectSigner.encode(assertion, context.getRegisteredService(), context.getAdaptor(),
                context.getHttpResponse(), context.getHttpRequest(), context.getBinding(), context.getSamlRequest(),
                context.getMessageContext());
        } else {
            LOGGER.debug("SAML registered service [{}] does not require assertions to be signed", context.getAdaptor().getEntityId());
        }
    }
Sign assertion.

@param assertion the assertion
@param context   the context
@throws Exception the exception
support/cas-server-support-saml-idp-web/src/main/java/org/apereo/cas/support/saml/web/idp/profile/builders/assertion/SamlProfileSamlAssertionBuilder.java