ncs_navigator_authority 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,12 +1,16 @@
1
1
  require 'ncs_navigator/configuration'
2
2
  module NcsNavigator::Authorization::Core
3
3
  class Authority
4
- def initialize(ignored_config=nil)
5
- @logger = Logger.new("ncs_navigator_authority_core.log")
4
+ def initialize(config=nil)
5
+ @logger = config.try(:logger) || Logger.new(STDERR)
6
6
  @groups = {}
7
7
  @portal = :NCSNavigator
8
8
  end
9
9
 
10
+ def logger
11
+ @logger
12
+ end
13
+
10
14
  def amplify!(user)
11
15
  base = user(user)
12
16
  return user unless base
@@ -44,6 +48,7 @@ module NcsNavigator::Authorization::Core
44
48
  result = []
45
49
  if users = get_users
46
50
  users.each do |u|
51
+ next if u["username"].blank?
47
52
  au = Aker::User.new(u["username"])
48
53
  au.identifiers[:staff_id] = u["staff_id"]
49
54
  au.first_name = u["first_name"]
@@ -61,19 +66,19 @@ module NcsNavigator::Authorization::Core
61
66
  end
62
67
 
63
68
  def get_connection(user)
64
- connection = staff_portal_client(user).connection
69
+ connection = staff_portal_client(create_authenticator(user)).connection
65
70
  end
66
71
 
67
- def staff_portal_client(user = nil)
68
- NcsNavigator::Authorization::StaffPortal::Client.new(staff_portal_uri, :authenticator => create_authenticator(user))
72
+ def staff_portal_client(authenticator)
73
+ NcsNavigator::Authorization::StaffPortal::Client.new(staff_portal_uri, :authenticator => authenticator)
69
74
  end
70
75
 
71
- def create_authenticator(user = nil)
72
- if user
73
- { :token => lambda { user.cas_proxy_ticket(staff_portal_uri) } }
74
- else
75
- { :basic => ["psc_application", NcsNavigator.configuration.staff_portal['psc_user_password']] }
76
- end
76
+ def create_authenticator(user)
77
+ { :token => lambda { user.cas_proxy_ticket(staff_portal_uri) } }
78
+ end
79
+
80
+ def machine_authenticator
81
+ { :basic => ["psc_application", NcsNavigator.configuration.staff_portal['psc_user_password']] }
77
82
  end
78
83
 
79
84
  def load_group_memberships(portal, group_data)
@@ -93,7 +98,7 @@ module NcsNavigator::Authorization::Core
93
98
 
94
99
  def get_staff(user)
95
100
  connection = get_connection(user)
96
- response = connection.get '/staff/' << user.username << '.json'
101
+ response = make_request(connection, '/staff/' << user.username << '.json')
97
102
  if response.status == 200
98
103
  response.body
99
104
  else
@@ -101,17 +106,22 @@ module NcsNavigator::Authorization::Core
101
106
  end
102
107
  end
103
108
 
109
+ def make_request(connection, url)
110
+ connection.get(url)
111
+ end
112
+
104
113
  def get_users
105
114
  users = nil
106
115
  begin
107
- response = staff_portal_client.connection.get('/users.json')
116
+ connection = staff_portal_client(machine_authenticator).connection
117
+ response = make_request(connection, '/users.json')
108
118
  if response.status == 200
109
119
  users = response.body
110
120
  else
111
- @logger.warn("#{Time.now}: Staff Portal Response: #{response.body}")
121
+ logger.warn("#{Time.now}: Staff Portal Response: #{response.body}")
112
122
  end
113
123
  rescue => e
114
- @logger.error("#{Time.now} : Staff Portal: #{e.class} #{e}")
124
+ logger.error("#{Time.now} : Staff Portal: #{e.class} #{e}")
115
125
  end
116
126
  users
117
127
  end
@@ -1,5 +1,5 @@
1
1
  module NcsNavigator
2
2
  module Authorization
3
- VERSION = '1.1.0'
3
+ VERSION = '1.1.1'
4
4
  end
5
5
  end
@@ -52,8 +52,23 @@ describe NcsNavigator::Authorization::Core::Authority do
52
52
  users.should be_empty
53
53
  end
54
54
  end
55
+
55
56
  end
56
57
 
58
+ describe "logger" do
59
+
60
+ it "should use the default logger" do
61
+ @ncs_navigator_authority.logger.should_not be_nil
62
+ end
63
+
64
+ it "should use the configured logger if given" do
65
+ logger = Logger.new("dummyfile.log")
66
+ auth = NcsNavigator::Authorization::Core::Authority.new(
67
+ mock(Aker::Configuration, :logger => logger))
68
+ auth.logger.should == logger
69
+ end
70
+
71
+ end
57
72
 
58
73
  describe "#amplify!" do
59
74
  before do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ncs_navigator_authority
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 1
9
- - 0
10
- version: 1.1.0
9
+ - 1
10
+ version: 1.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jalpa Patel
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-11-20 00:00:00 -06:00
18
+ date: 2012-11-26 00:00:00 -06:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency