private void storeAttributeQueryTicketInRegistry(final Optional<Assertion> assertion, final SamlProfileBuilderContext context)
        throws Exception {
        val existingQuery = context.getHttpRequest().getAttribute(AttributeQuery.class.getSimpleName());
        if (existingQuery == null && assertion.isPresent()) {
            val nameId = (String) context.getHttpRequest().getAttribute(NameID.class.getName());
            val ticketGrantingTicket = CookieUtils.getTicketGrantingTicketFromRequest(
                getConfigurationContext().getTicketGrantingTicketCookieGenerator(),
                getConfigurationContext().getTicketRegistry(), context.getHttpRequest());

            if (ticketGrantingTicket != null) {
                val samlAttributeQueryTicketFactory = (SamlAttributeQueryTicketFactory) getConfigurationContext().getTicketFactory().get(SamlAttributeQueryTicket.class);
                val ticket = samlAttributeQueryTicketFactory.create(nameId, assertion.get(), context.getAdaptor().getEntityId(), ticketGrantingTicket);
                getConfigurationContext().getTicketRegistry().addTicket(ticket);
                context.getHttpRequest().setAttribute(SamlAttributeQueryTicket.class.getName(), ticket);
            }
        }
    }
This is {@link SamlProfileSaml2ResponseBuilder}.

@author Misagh Moayyed
@since 5.1.0
support/cas-server-support-saml-idp-web/src/main/java/org/apereo/cas/support/saml/web/idp/profile/builders/response/SamlProfileSaml2ResponseBuilder.java