zas-service 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,6 +8,8 @@ module Zas
8
8
  # authenticator = FilteredAuthenticator.new(MyRealAuthenticator.new, [SomeFilter, SomeOtherFilter])
9
9
  # authenticator.authenticate(credentials)
10
10
  class FilteredAuthenticator
11
+ attr_accessor :logger
12
+
11
13
  # Initialize the filtered authenticator with the given delegate
12
14
  # and filters. Filters will be applied when the authentication
13
15
  # occurs.
@@ -23,7 +25,9 @@ module Zas
23
25
  #
24
26
  # credentials - The credentials
25
27
  def authenticate(credentials)
28
+ logger.info "Applying filters to credentials: #{filters.join(', ')}"
26
29
  credentials = filters.reduce(credentials) { |credentials, filter| filter.authenticate(credentials) }
30
+ logger.info "Delegating to #{delegate.class.name}"
27
31
  delegate.authenticate(*credentials)
28
32
  end
29
33
 
@@ -29,6 +29,8 @@ module Zas
29
29
  self[:salt_field] || :password_salt
30
30
  end
31
31
  end
32
+
33
+ attr_accessor :logger
32
34
 
33
35
  # Initialize the autenticator with the given sequel DB. Optionally pass in additional
34
36
  # configuration for the authenticator.
@@ -45,7 +47,9 @@ module Zas
45
47
 
46
48
  # Authenticate the given username/password pair
47
49
  def authenticate(username, password)
50
+ logger.info "Authenticating #{username} (table: #{table_name}, username_field: #{username_field})"
48
51
  record = db[table_name].filter(username_field => username).first
52
+ logger.info "Record found for #{username}"
49
53
  tokens = [password, record[salt_field]].compact
50
54
  matches?(record[password_field], *tokens) if record
51
55
  end
@@ -0,0 +1,11 @@
1
+ module Zas
2
+ module Filters
3
+ module StandardAuth
4
+ module_function
5
+
6
+ def authenticate(credentials)
7
+ [credentials['username'], credentials['password']]
8
+ end
9
+ end
10
+ end
11
+ end
data/lib/zas/filters.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  module Zas
2
2
  module Filters
3
+ require 'zas/filters/standard_auth'
3
4
  require 'zas/filters/http_basic_auth'
4
5
  end
5
6
  end
data/lib/zas/service.rb CHANGED
@@ -12,6 +12,8 @@ module Zas
12
12
  require 'zas/authenticators'
13
13
  require 'zas/crypto_providers'
14
14
 
15
+ attr_accessor :logger
16
+
15
17
  # A collection authenticators mapped to keys.
16
18
  def authenticators
17
19
  @authenticators ||= {}
@@ -37,7 +39,7 @@ module Zas
37
39
 
38
40
  begin
39
41
  while req = socket.recv
40
- logger.debug req
42
+ logger.info req
41
43
  socket.send(encode(authenticate(req)))
42
44
  end
43
45
  rescue ZMQ::Error => e
@@ -50,7 +52,7 @@ module Zas
50
52
  attr_accessor :host
51
53
  attr_accessor :port
52
54
  attr_accessor :context
53
- attr_accessor :logger
55
+ attr_writer :logger
54
56
 
55
57
  # Handle the authentication.
56
58
  #
@@ -63,6 +65,7 @@ module Zas
63
65
  raise "No authenticator found for #{req.strategy}" unless authenticator
64
66
  {:authenticated? => authenticator.authenticate(req.credentials)}
65
67
  rescue => e
68
+ logger.info "Error authenticating: #{e.message}"
66
69
  {:error => e.message}
67
70
  end
68
71
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zas-service
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -41,6 +41,7 @@ files:
41
41
  - lib/zas/crypto_providers/sha512.rb
42
42
  - lib/zas/crypto_providers.rb
43
43
  - lib/zas/filters/http_basic_auth.rb
44
+ - lib/zas/filters/standard_auth.rb
44
45
  - lib/zas/filters.rb
45
46
  - lib/zas/service.rb
46
47
  - lib/zas/service_configuration.rb