Sha256: 92eab7a09bfe9e2dee69b5cb2125917e9b0433ea1f49a9f2713bb0f4d39491fe

Contents?: true

Size: 858 Bytes

Versions: 9

Compression:

Stored size: 858 Bytes

Contents

require 'certmeister/policy'

module Certmeister

  module Policy

    class ChainAll

      def initialize(policys)
        validate_policys(policys)
        @policys = policys
      end

      def authenticate(request)
        success = Certmeister::Policy::Response.new(true, nil)
        @policys.inject(success) do |continue, policy|
          response = policy.authenticate(request)
          break response unless response.authenticated?
          continue
        end
      end

      private

      def validate_policys(policys)
        unless policys.is_a?(Enumerable) and policys.respond_to?(:size) and policys.size > 0 and
               policys.all? { |policy| Certmeister::Policy.validate_authenticate_signature(policy) }
          raise ArgumentError.new("enumerable collection of policys required")
        end
      end

    end

  end

end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
certmeister-0.3.2 lib/certmeister/policy/chain_all.rb
certmeister-0.3.1 lib/certmeister/policy/chain_all.rb
certmeister-0.3.0 lib/certmeister/policy/chain_all.rb
certmeister-0.2.3 lib/certmeister/policy/chain_all.rb
certmeister-0.2.1 lib/certmeister/policy/chain_all.rb
certmeister-0.2.0 lib/certmeister/policy/chain_all.rb
certmeister-0.1.0 lib/certmeister/policy/chain_all.rb
certmeister-0.0.2 lib/certmeister/policy/chain_all.rb
certmeister-0.0.1 lib/certmeister/policy/chain_all.rb