def valid_credentials?(kind, *credentials)
      results = poll(:valid_credentials?, kind, *credentials)
      if results.empty?
        raise "No authentication-providing authority is configured.  " <<
          "At least one authority must implement #valid_credentials?."
      end
      user, authenticating_authority = results.detect { |r, authority| r && r != :unsupported }

      unless user
        msg =
          if results.collect { |r, auth| r }.uniq == [:unsupported]
            "no configured authorities support #{kind.inspect} credentials"
          else
            "invalid credentials"
          end
        on_authentication_failure(nil, kind, credentials, msg)
        return nil
      end

      vc_vetoers = results.select { |r, authority| r == false }.collect { |r, authority| authority }
      unless vc_vetoers.empty?
        msg = "credentials vetoed by #{vc_vetoers.collect(&:to_s).join(', ')}"
        on_authentication_failure(user, kind, credentials, msg)
        return false
      end

      veto_vetoers = poll(:veto?, user).
        select { |result, authority| result }.collect { |result, authority| authority }
      unless veto_vetoers.empty?
        msg = "user vetoed by #{veto_vetoers.collect(&:to_s).join(', ')}"
        on_authentication_failure(user, kind, credentials, msg)
        return false
      end

      amplify!(user)
      on_authentication_success(user, kind, credentials, authenticating_authority)
      user
    end
def valid_credentials?(kind, *credentials)
      results = poll(:valid_credentials?, kind, *credentials)
      if results.empty?
        raise "No authentication-providing authority is configured.  " <<
          "At least one authority must implement #valid_credentials?."
      end
      user, authenticating_authority = results.detect { |r, authority| r && r != :unsupported }

      unless user
        msg =
          if results.collect { |r, auth| r }.uniq == [:unsupported]
            "no configured authorities support #{kind.inspect} credentials"
          else
            "invalid credentials"
          end
        on_authentication_failure(nil, kind, credentials, msg)
        return nil
      end

      vc_vetoers = results.select { |r, authority| r == false }.collect { |r, authority| authority }
      unless vc_vetoers.empty?
        msg = "credentials vetoed by #{vc_vetoers.collect(&:to_s).join(', ')}"
        on_authentication_failure(user, kind, credentials, msg)
        return false
      end

      veto_vetoers = poll(:veto?, user).
        select { |result, authority| result }.collect { |result, authority| authority }
      unless veto_vetoers.empty?
        msg = "user vetoed by #{veto_vetoers.collect(&:to_s).join(', ')}"
        on_authentication_failure(user, kind, credentials, msg)
        return false
      end

      amplify!(user)
      on_authentication_success(user, kind, credentials, authenticating_authority)
      user
    end
The main authentication and authorization entry point for an
 authority.  A concrete authority can return one of four things
 from its implementation of this method:

 * A {Aker::User} instance if the credentials are valid.  The
   instance represents the user that corresponds to these
   credentials, with all the attributes and authorization
   information that the verifying authority knows about.
 * `nil` if the credentials aren't valid according to the
   authority.
 * `false` if the authority wants to prevent the presenter of
   these credentials from authenticating, even if another
   authority says they are valid.
 * `:unsupported` if the authority can never authenticate
   credentials of the provided kind.  Semantically this is the
   same as `nil`, but it allows `Composite` to provide a useful
   debugging message if none of the authorities are capable of
   validating a submitted kind.

 The composite implementation provided by this class does the
 following:

 * Executes `valid_credentials?` on all the configured authorities
   that implement it.
 * Returns `false` if any of the authorities return `false`.
 * Returns `nil` if none of the authorities returned a user.
 * Selects the first user returned by any of the authorities.
 * Returns `false` if any of the authorities {#veto? veto} the
   user.
 * Otherwise returns the user, {#amplify! amplified}.

 On failure, the {#on_authentication_failure} callback is called
 on any authority which provides it.  Similarly on success, the
 {#on_authentication_success} callback is called on all the
 authorities which support it.

 @param [Symbol] kind a symbol describing the semantics of the
   supplied credentials.  Different authorities may support
   different kinds (or multiple authorities may support the same
   kind).
 @param [Array] *credentials the actual credentials.  The form of
   these is dependent on the kind.

 @return [Aker::User,false,nil] the aggregated result of calling
   `valid_credentials?` on all the configured {#authorities}.
   If the credentials are valid, the returned user will already
   be {#amplify! amplified}.