public Subject newSubject(final SAMLObject nameId,
                              final SAMLObject subjectConfNameId,
                              final SubjectConfirmation subjectConfirmation) {

        LOGGER.debug("Building subject for NameID [{}]", nameId);
        val subject = newSamlObject(Subject.class);
        subject.setNameID(null);
        subject.getSubjectConfirmations().forEach(confirmation -> confirmation.setNameID(null));

        if (nameId instanceof final NameID instance) {
            subject.setNameID(instance);
            subject.setEncryptedID(null);
        }
        if (nameId instanceof final EncryptedID instance) {
            subject.setNameID(null);
            subject.setEncryptedID(instance);
        }
        if (subjectConfNameId instanceof final NameID instance) {
            subjectConfirmation.setNameID(instance);
            subjectConfirmation.setEncryptedID(null);
        }
        if (subjectConfNameId instanceof final EncryptedID instance) {
            subjectConfirmation.setNameID(null);
            subjectConfirmation.setEncryptedID(instance);
        }
        subject.getSubjectConfirmations().add(subjectConfirmation);
        LOGGER.debug("Built subject [{}]", subject);
        return subject;
    }
New subject element.

@param nameId              the nameId
@param subjectConfNameId   the subject conf name id
@param subjectConfirmation the subject confirmation
@return the subject
support/cas-server-support-saml-core-api/src/main/java/org/apereo/cas/support/saml/util/AbstractSaml20ObjectBuilder.java