# File lib/mcollective/security/base.rb, line 55
      def validate_filter?(filter)
        failed = 0
        passed = 0

        passed = 1 if Util.empty_filter?(filter)

        filter.keys.each do |key|
          case key
          when /puppet_class|cf_class/
            filter[key].each do |f|
              Log.debug("Checking for class #{f}")
              if Util.has_cf_class?(f) then
                Log.debug("Passing based on configuration management class #{f}")
                passed += 1
              else
                Log.debug("Failing based on configuration management class #{f}")
                failed += 1
              end
            end

          when "compound"
            filter[key].each do |compound|
              result = false
              truth_values = []

              begin
                compound.each do |expression|
                  case expression.keys.first
                    when "statement"
                      truth_values << Matcher.eval_compound_statement(expression).to_s
                    when "fstatement"
                      truth_values << Matcher.eval_compound_fstatement(expression.values.first)
                    when "and"
                      truth_values << "&&"
                    when "or"
                      truth_values << "||"
                    when "("
                      truth_values << "("
                    when ")"
                      truth_values << ")"
                    when "not"
                      truth_values << "!"
                  end
                end

                result = eval(truth_values.join(" "))
              rescue DDLValidationError
                result = false
              end

              if result
                Log.debug("Passing based on class and fact composition")
                passed +=1
              else
                Log.debug("Failing based on class and fact composition")
                failed +=1
              end
            end

          when "agent"
            filter[key].each do |f|
              if Util.has_agent?(f) || f == "mcollective"
                Log.debug("Passing based on agent #{f}")
                passed += 1
              else
                Log.debug("Failing based on agent #{f}")
                failed += 1
              end
            end

          when "fact"
            filter[key].each do |f|
              if Util.has_fact?(f[:fact], f[:value], f[:operator])
                Log.debug("Passing based on fact #{f[:fact]} #{f[:operator]} #{f[:value]}")
                passed += 1
              else
                Log.debug("Failing based on fact #{f[:fact]} #{f[:operator]} #{f[:value]}")
                failed += 1
              end
            end

          when "identity"
            unless filter[key].empty?
              # Identity filters should not be 'and' but 'or' as each node can only have one identity
              matched = filter[key].select{|f| Util.has_identity?(f)}.size

              if matched == 1
                Log.debug("Passing based on identity")
                passed += 1
              else
                Log.debug("Failed based on identity")
                failed += 1
              end
            end
          end
        end

        if failed == 0 && passed > 0
          Log.debug("Message passed the filter checks")

          @stats.passed

          return true
        else
          Log.debug("Message failed the filter checks")

          @stats.filtered

          return false
        end
      end