protected NameID finalizeNameId(final NameID nameid,
                                    final SamlProfileBuilderContext context) {
        if (nameid != null) {
            val registeredService = context.getRegisteredService();
            if (!StringUtils.equalsIgnoreCase(registeredService.getNameIdQualifier(), "none")
                && !registeredService.isSkipGeneratingNameIdQualifier()) {
                if (StringUtils.isNotBlank(registeredService.getNameIdQualifier())) {
                    nameid.setNameQualifier(registeredService.getNameIdQualifier());
                } else {
                    nameid.setNameQualifier(SamlIdPUtils.determineNameIdNameQualifier(registeredService, samlIdPMetadataResolver));
                }
            }

            if (!StringUtils.equalsIgnoreCase(registeredService.getServiceProviderNameIdQualifier(), "none")
                 && !registeredService.isSkipGeneratingServiceProviderNameIdQualifier()) {
                FunctionUtils.doIf(StringUtils.isNotBlank(registeredService.getServiceProviderNameIdQualifier()),
                        value -> nameid.setSPNameQualifier(registeredService.getServiceProviderNameIdQualifier()),
                        value -> nameid.setSPNameQualifier(context.getAdaptor().getEntityId()))
                    .accept(registeredService);
            }
        }
        return nameid;
    }
This is {@link SamlProfileSamlNameIdBuilder}.

@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/nameid/SamlProfileSamlNameIdBuilder.java