public void ValidateSubjectConfirmation(SubjectConfirmation subjectConfirmation)
        {
            if (subjectConfirmation == null) throw new ArgumentNullException("subjectConfirmation");

            if (!Saml2Utils.ValidateRequiredString(subjectConfirmation.Method))
                throw new Saml2FormatException("Method attribute of SubjectConfirmation MUST contain at least one non-whitespace character");

            if (!Uri.IsWellFormedUriString(subjectConfirmation.Method, UriKind.Absolute))
                throw new Saml2FormatException("SubjectConfirmation element has Method attribute which is not a wellformed absolute uri.");

            if (subjectConfirmation.Method == Saml2Constants.SubjectConfirmationMethods.HolderOfKey)
                _keyInfoValidator.ValidateKeyInfo(subjectConfirmation.SubjectConfirmationData);

            if (subjectConfirmation.Item != null)
            {
                if (subjectConfirmation.Item is NameID)
                    NameIdValidator.ValidateNameID((NameID)subjectConfirmation.Item);
                else if (subjectConfirmation.Item is EncryptedElement)
                    NameIdValidator.ValidateEncryptedID((EncryptedElement)subjectConfirmation.Item);
                else
                    throw new Saml2FormatException(string.Format("Identifier of type {0} is not supported for SubjectConfirmation", subjectConfirmation.Item.GetType()));
            }
            else if (subjectConfirmation.SubjectConfirmationData != null)
                SubjectConfirmationDataValidator.ValidateSubjectConfirmationData(subjectConfirmation.SubjectConfirmationData);
        }
        public virtual void ValidateSubject(Subject subject)
        {
            if (subject == null)
            {
                throw new ArgumentNullException("subject");
            }

            bool validContentFound = false;

            if (subject.Items == null || subject.Items.Length == 0)
            {
                throw new Saml20FormatException("Subject MUST contain either an identifier or a subject confirmation");
            }

            foreach (object o in subject.Items)
            {
                if (o is NameID)
                {
                    validContentFound = true;
                    NameIdValidator.ValidateNameID((NameID)o);
                }
                else if (o is EncryptedElement)
                {
                    validContentFound = true;
                    NameIdValidator.ValidateEncryptedID((EncryptedElement)o);
                }
                else if (o is SubjectConfirmation)
                {
                    validContentFound = true;
                    SubjectConfirmationValidator.ValidateSubjectConfirmation((SubjectConfirmation)o);
                }
            }

            if (!validContentFound)
            {
                throw new Saml20FormatException("Subject must have either NameID, EncryptedID or SubjectConfirmation subelement.");
            }
        }