public AttributeStatement newAttributeStatement(final SamlProfileBuilderContext context,
                                                    final Map<String, Object> attributes,
                                                    final Saml20AttributeBuilder builder) throws Exception {
        val attrStatement = SamlUtils.newSamlObject(AttributeStatement.class);

        val resp = casProperties.getAuthn().getSamlIdp().getResponse();
        val nameFormats = new HashMap<>(resp.configureAttributeNameFormats());
        nameFormats.putAll(context.getRegisteredService().getAttributeNameFormats());

        val urns = new HashMap<String, String>();
        attributeDefinitionStore.getAttributeDefinitions()
            .stream()
            .filter(SamlIdPAttributeDefinition.class::isInstance)
            .map(SamlIdPAttributeDefinition.class::cast)
            .filter(defn -> StringUtils.isNotBlank(defn.getUrn()))
            .forEach(defn -> {
                urns.put(defn.getKey(), defn.getUrn());
                urns.put(defn.getName(), defn.getUrn());
            });
        LOGGER.debug("Attribute definitions tagged with URNs in the attribute definition store are [{}]", urns);
        LOGGER.debug("Attributes to process for SAML2 attribute statement are [{}]", attributes);
        for (val entry : attributes.entrySet()) {
            var attributeValue = entry.getValue();
            var attributeName = entry.getKey();
            
            if (attributeName.equalsIgnoreCase(casProperties.getAuthn().getMfa().getCore().getAuthenticationContextAttribute())) {
                attributeValue = buildAuthenticationContextClassAttribute(context).orElse(null);
            }
            if (attributeValue == null || (attributeValue instanceof final Collection col && col.isEmpty())) {
                LOGGER.info("Skipping attribute [{}] because it does not have any values.", attributeName);
                continue;
            }
            
            val friendlyName = getAttributeFriendlyName(context, attributeName);
            val attributeNames = urns.containsKey(attributeName)
                ? List.of(urns.get(attributeName))
                : getMappedAttributeNamesFromAttributeDefinitionStore(attributeName);

            for (val name : attributeNames) {
                LOGGER.trace("Processing SAML2 attribute [{}] with value [{}], friendlyName [{}]", name, attributeValue, friendlyName);
                val valueType = context.getRegisteredService().getAttributeValueTypes().get(name);

                if (NameIDType.class.getSimpleName().equalsIgnoreCase(valueType)) {
                    val nameIdObject = samlNameIdBuilder.build(context);
                    if (nameIdObject instanceof final NameID nameId) {
                        val nameID = newSamlObject(NameID.class);
                        nameID.setFormat(nameId.getFormat());
                        nameID.setNameQualifier(nameId.getNameQualifier());
                        nameID.setSPNameQualifier(nameId.getSPNameQualifier());
                        nameID.setValue(nameId.getValue());
                        attributeValue = nameID;
                    }
                }
                if (NameIDType.PERSISTENT.equalsIgnoreCase(valueType)) {
                    val nameID = newSamlObject(NameID.class);
                    nameID.setFormat(NameIDType.PERSISTENT);
                    nameID.setNameQualifier(SamlIdPUtils.determineNameIdNameQualifier(context.getRegisteredService(), samlIdPMetadataResolver));
                    FunctionUtils.doIf(StringUtils.isNotBlank(context.getRegisteredService().getServiceProviderNameIdQualifier()),
                            value -> nameID.setSPNameQualifier(context.getRegisteredService().getServiceProviderNameIdQualifier()),
                            value -> nameID.setSPNameQualifier(context.getAdaptor().getEntityId()))
                        .accept(context.getRegisteredService());
                    CollectionUtils.firstElement(attributeValue).ifPresent(value -> nameID.setValue(value.toString()));
                    attributeValue = nameID;
                }

                LOGGER.debug("Creating SAML2 attribute [{}] with value [{}], friendlyName [{}]", name, attributeValue, friendlyName);
                val attribute = newAttribute(friendlyName, name, attributeValue,
                    nameFormats,
                    resp.getDefaultAttributeNameFormat(),
                    context.getRegisteredService().getAttributeValueTypes());

                LOGGER.trace("Created SAML2 attribute [{}] with NameID format [{}]", attribute.getName(), attribute.getNameFormat());
                builder.build(attrStatement, attribute);
            }
        }
        return attrStatement;
    }
New attribute statement.

@param context    the context
@param attributes the attributes
@param builder    the builder
@return the attribute statement
@throws Exception the exception
support/cas-server-support-saml-idp-web/src/main/java/org/apereo/cas/support/saml/web/idp/profile/builders/attr/SamlProfileSamlAttributeStatementBuilder.java