Class: Zas::Authenticators::FilteredAuthenticator
- Inherits:
-
Object
- Object
- Zas::Authenticators::FilteredAuthenticator
- Defined in:
- lib/zas/authenticators/filtered_authenticator.rb
Overview
Public: An authenticator that filters the credentials through 1 or more filters that can transform the credentials before passing them to another authenticator.
Example:
authenticator = FilteredAuthenticator.new(MyRealAuthenticator.new, [SomeFilter, SomeOtherFilter])
authenticator.authenticate(credentials)
Instance Attribute Summary collapse
-
#logger ⇒ Object
Returns the value of attribute logger.
Instance Method Summary collapse
-
#authenticate(credentials) ⇒ Object
Public: Authenticate the given credentials.
-
#initialize(delegate, *filters) ⇒ FilteredAuthenticator
constructor
Public: Initialize the filtered authenticator with the given delegate and filters.
Constructor Details
#initialize(delegate, *filters) ⇒ FilteredAuthenticator
Public: Initialize the filtered authenticator with the given delegate and filters. Filters will be applied when the authentication occurs.
delegate - The implementation to delegate to after filtering is complete filters - The filters to apply
19 20 21 22 |
# File 'lib/zas/authenticators/filtered_authenticator.rb', line 19 def initialize(delegate, *filters) self.delegate = delegate self.filters = [filters].compact.flatten end |
Instance Attribute Details
#logger ⇒ Object
Returns the value of attribute logger.
11 12 13 |
# File 'lib/zas/authenticators/filtered_authenticator.rb', line 11 def logger @logger end |
Instance Method Details
#authenticate(credentials) ⇒ Object
Public: Authenticate the given credentials.
credentials - The credentials
Returns true if the credentials are authenticated
29 30 31 32 33 34 35 |
# File 'lib/zas/authenticators/filtered_authenticator.rb', line 29 def authenticate(credentials) logger.info "Applying filters to credentials: #{filters.join(', ')}" if logger credentials = filters.reduce(credentials) { |credentials, filter| filter.authenticate(credentials) } logger.info "Delegating to #{delegate.class.name}" if logger delegate.logger ||= logger delegate.authenticate(*credentials) end |