ncs_navigator_authority 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/buildfile +1 -1
- data/lib/ncs_navigator/authorization/core/authority.rb +48 -13
- data/lib/ncs_navigator/authorization/psc/authority.rb +5 -3
- data/lib/ncs_navigator/authorization/version.rb +2 -2
- data/spec/fixtures/vcr_cassettes/staff_portal/psc/users_with_null_username.yml +34 -0
- data/spec/ncs_navigator/authorization/core/authority_spec.rb +29 -13
- metadata +6 -4
data/buildfile
CHANGED
@@ -3,5 +3,5 @@ require 'buildr-gemjar'
|
|
3
3
|
|
4
4
|
define 'ncs_navigator_authority_gems' do
|
5
5
|
project.version = '1.0.0'
|
6
|
-
package(:gemjar).with_gem(:file => _('ncs_navigator_authority-1.0.0.gem')).with_gem('jruby-
|
6
|
+
package(:gemjar).with_gem(:file => _('ncs_navigator_authority-1.0.0.gem')).with_gem('jruby-openssl', '0.7.5')
|
7
7
|
end
|
@@ -2,6 +2,7 @@ require 'ncs_navigator/configuration'
|
|
2
2
|
module NcsNavigator::Authorization::Core
|
3
3
|
class Authority
|
4
4
|
def initialize(ignored_config=nil)
|
5
|
+
@logger = Logger.new("ncs_navigator_authority_core.log")
|
5
6
|
@groups = {}
|
6
7
|
@portal = :NCSNavigator
|
7
8
|
end
|
@@ -11,7 +12,7 @@ module NcsNavigator::Authorization::Core
|
|
11
12
|
return user unless base
|
12
13
|
user.merge!(base)
|
13
14
|
end
|
14
|
-
|
15
|
+
|
15
16
|
def user(user)
|
16
17
|
staff = get_staff(user)
|
17
18
|
if staff
|
@@ -28,7 +29,7 @@ module NcsNavigator::Authorization::Core
|
|
28
29
|
groups = staff['roles'].collect do |role|
|
29
30
|
role['name']
|
30
31
|
end
|
31
|
-
|
32
|
+
|
32
33
|
if groups
|
33
34
|
u.group_memberships(@portal).concat(load_group_memberships(@portal, groups))
|
34
35
|
end
|
@@ -37,25 +38,44 @@ module NcsNavigator::Authorization::Core
|
|
37
38
|
nil
|
38
39
|
end
|
39
40
|
end
|
40
|
-
|
41
|
-
|
42
|
-
|
41
|
+
|
42
|
+
def find_users(*criteria)
|
43
|
+
return [] unless criteria.empty?
|
44
|
+
result = []
|
45
|
+
if users = get_users
|
46
|
+
users.each do |u|
|
47
|
+
au = Aker::User.new(u["username"])
|
48
|
+
au.identifiers[:staff_id] = u["staff_id"]
|
49
|
+
au.first_name = u["first_name"]
|
50
|
+
au.last_name = u["last_name"]
|
51
|
+
result << au
|
52
|
+
end
|
53
|
+
end
|
54
|
+
result
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
43
59
|
def staff_portal_uri
|
44
60
|
NcsNavigator.configuration.staff_portal_uri
|
45
61
|
end
|
46
|
-
|
62
|
+
|
47
63
|
def get_connection(user)
|
48
64
|
connection = staff_portal_client(user).connection
|
49
65
|
end
|
50
|
-
|
51
|
-
def staff_portal_client(user)
|
66
|
+
|
67
|
+
def staff_portal_client(user = nil)
|
52
68
|
NcsNavigator::Authorization::StaffPortal::Client.new(staff_portal_uri, :authenticator => create_authenticator(user))
|
53
69
|
end
|
54
|
-
|
55
|
-
def create_authenticator(user)
|
70
|
+
|
71
|
+
def create_authenticator(user = nil)
|
72
|
+
if user
|
56
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
|
57
77
|
end
|
58
|
-
|
78
|
+
|
59
79
|
def load_group_memberships(portal, group_data)
|
60
80
|
group_data.collect do |group|
|
61
81
|
Aker::GroupMembership.new(find_or_create_group(portal, group))
|
@@ -66,11 +86,11 @@ module NcsNavigator::Authorization::Core
|
|
66
86
|
existing = (@groups[portal] ||= []).collect { |top|
|
67
87
|
top.find { |g| g.name == group_name }
|
68
88
|
}.compact.first
|
69
|
-
return existing if existing
|
89
|
+
return existing if existing
|
70
90
|
@groups[portal] << Aker::Group.new(group_name)
|
71
91
|
@groups[portal].last
|
72
92
|
end
|
73
|
-
|
93
|
+
|
74
94
|
def get_staff(user)
|
75
95
|
connection = get_connection(user)
|
76
96
|
response = connection.get '/staff/' << user.username << '.json'
|
@@ -80,5 +100,20 @@ module NcsNavigator::Authorization::Core
|
|
80
100
|
nil
|
81
101
|
end
|
82
102
|
end
|
103
|
+
|
104
|
+
def get_users
|
105
|
+
users = nil
|
106
|
+
begin
|
107
|
+
response = staff_portal_client.connection.get('/users.json')
|
108
|
+
if response.status == 200
|
109
|
+
users = response.body
|
110
|
+
else
|
111
|
+
@logger.warn("#{Time.now}: Staff Portal Response: #{response.body}")
|
112
|
+
end
|
113
|
+
rescue => e
|
114
|
+
@logger.error("#{Time.now} : Staff Portal: #{e.class} #{e}")
|
115
|
+
end
|
116
|
+
users
|
117
|
+
end
|
83
118
|
end
|
84
119
|
end
|
@@ -3,8 +3,8 @@ require 'logger'
|
|
3
3
|
module NcsNavigator::Authorization::Psc
|
4
4
|
class Authority
|
5
5
|
def initialize(ignored_config=nil)
|
6
|
-
@staff_portal_connection ||= staff_portal_client.connection
|
7
6
|
@logger = Logger.new("#{Java::JavaLang::System.getProperty('catalina.base')}/logs/ncs_navigator_authority.log")
|
7
|
+
@staff_portal_connection ||= staff_portal_client.connection
|
8
8
|
end
|
9
9
|
|
10
10
|
def get_user_by_username(username, role_detail_level)
|
@@ -69,7 +69,8 @@ module NcsNavigator::Authorization::Psc
|
|
69
69
|
|
70
70
|
def staff_portal_client
|
71
71
|
NcsNavigator::Authorization::StaffPortal::Client.new(NcsNavigator.configuration.staff_portal_uri,
|
72
|
-
:authenticator => create_authenticator
|
72
|
+
:authenticator => create_authenticator,
|
73
|
+
:ssl => {:ca_file => NcsNavigator.configuration.psc['ssl_ca_file']}.tap{|a| @logger.info("#{a.inspect}")})
|
73
74
|
end
|
74
75
|
|
75
76
|
def create_authenticator
|
@@ -82,11 +83,12 @@ module NcsNavigator::Authorization::Psc
|
|
82
83
|
response = @staff_portal_connection.get url
|
83
84
|
if response.status == 200
|
84
85
|
staff = response.body
|
86
|
+
@logger.info("#{Time.now}: Staff Portal Response: Successful connection")
|
85
87
|
else
|
86
88
|
@logger.warn("#{Time.now}: Staff Portal Response: #{response.body}")
|
87
89
|
end
|
88
90
|
rescue => e
|
89
|
-
@logger.error("#{Time.now} : Staff Portal: #{e
|
91
|
+
@logger.error("#{Time.now} : Staff Portal: #{e} #{e.class}")
|
90
92
|
end
|
91
93
|
staff
|
92
94
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
---
|
2
|
+
- !ruby/struct:VCR::HTTPInteraction
|
3
|
+
request: !ruby/struct:VCR::Request
|
4
|
+
method: :get
|
5
|
+
uri: https://psc_application:psc_application@staffportal.local/users.json?role%5B%5D=Field%20Staff&role%5B%5D=Phone%20Staff
|
6
|
+
body:
|
7
|
+
headers:
|
8
|
+
authorization:
|
9
|
+
- Basic cHNjX2FwcGxpY2F0aW9uOnBzY19hcHBsaWNhdGlvbg==
|
10
|
+
response: !ruby/struct:VCR::Response
|
11
|
+
status: !ruby/struct:VCR::ResponseStatus
|
12
|
+
code: 200
|
13
|
+
message: OK
|
14
|
+
headers:
|
15
|
+
x-ua-compatible:
|
16
|
+
- IE=Edge
|
17
|
+
etag:
|
18
|
+
- "\"59c92e159922355929ebc5d1e6250f07\""
|
19
|
+
content-type:
|
20
|
+
- application/json; charset=utf-8
|
21
|
+
x-runtime:
|
22
|
+
- "0.163889"
|
23
|
+
server:
|
24
|
+
- WEBrick/1.3.1 (Ruby/1.8.7/2011-02-18)
|
25
|
+
date:
|
26
|
+
- Tue, 06 Mar 2012 19:28:46 GMT
|
27
|
+
content-length:
|
28
|
+
- "1005"
|
29
|
+
set-cookie:
|
30
|
+
- _OMA_session=BAh7ByIZYWtlci5sYXN0X3JlcXVlc3RfYXRsKwduZVZPIg9zZXNzaW9uX2lkIiU0YzBmZWYxMzU3NDljYmI0OTRhMTg1Nzg4ZTc1YzFkMg%3D%3D--74de3cd65976130dd9df4118f7ba156d94661db8; path=/; HttpOnly
|
31
|
+
cache-control:
|
32
|
+
- max-age=0, private, must-revalidate
|
33
|
+
body: "[{\"notify\":true,\"study_center\":20000029,\"ncs_inactive_date\":null,\"staff_type_other\":null,\"roles\":[{\"name\":\"Field Staff\"},{\"name\":\"Outreach Staff\"}],\"ethnicity\":null,\"staff_id\":\"5de404f5-9c37-4d92-8f2a-30041400ba06\",\"zipcode\":null,\"numeric_id\":1885042269,\"race_other\":null,\"username\":null,\"gender\":null,\"external\":false,\"staff_type\":null,\"languages\":[],\"last_name\":\"Palbo\",\"subcontractor\":null,\"race\":null,\"experience\":null,\"email\":\"nolan_palbo@test.com\",\"first_name\":\"Nolan\",\"ncs_active_date\":null},{\"notify\":true,\"study_center\":20000029,\"ncs_inactive_date\":null,\"staff_type_other\":null,\"roles\":[{\"name\":\"Field Staff\"},{\"name\":\"Phone Staff\"},{\"name\":\"System Administrator\"},{\"name\":\"User Administrator\"},{\"name\":\"Staff Supervisor\"},{\"name\":\"Biological Specimen Collector\"}],\"ethnicity\":null,\"staff_id\":\"16912345-ba05-481d-aa80-96e71e1ac9d9\",\"zipcode\":null,\"numeric_id\":960833693,\"race_other\":null,\"username\":\"testuser\",\"gender\":null,\"external\":false,\"staff_type\":null,\"languages\":[],\"last_name\":\"Grant\",\"subcontractor\":null,\"race\":null,\"experience\":null,\"email\":\"perry_grant@test.com\",\"first_name\":\"Perry\",\"ncs_active_date\":null}]"
|
34
|
+
http_version: "1.1"
|
@@ -4,47 +4,63 @@ require 'vcr'
|
|
4
4
|
require 'faraday'
|
5
5
|
require 'faraday_stack'
|
6
6
|
describe NcsNavigator::Authorization::Core::Authority do
|
7
|
-
|
7
|
+
|
8
8
|
before do
|
9
9
|
@ncs_navigator_authority = NcsNavigator::Authorization::Core::Authority.new
|
10
10
|
@user = mock(:username => "lee", :cas_proxy_ticket => "PT-cas-ticket")
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
describe "user" do
|
14
14
|
before do
|
15
15
|
VCR.use_cassette('staff_portal/core/user') do
|
16
16
|
@return_user = @ncs_navigator_authority.user(@user)
|
17
17
|
end
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
it "copies first name from staff portal user" do
|
21
21
|
@return_user.first_name.should == "Lee"
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
it "copies last name from staff portal user" do
|
25
25
|
@return_user.last_name.should == "Peterson"
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
it "copies email from staff portal user" do
|
29
29
|
@return_user.email.should == "lee@test.com"
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
it "copies staff_id as identifiers from staff portal staff_id" do
|
33
33
|
@return_user.identifiers[:staff_id].should == "test_staff_id"
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
it "generate group membership from staff role" do
|
37
37
|
@return_user.group_memberships(:NCSNavigator).include?("Staff Supervisor").should be_true
|
38
38
|
end
|
39
39
|
end
|
40
|
-
|
41
|
-
|
40
|
+
|
41
|
+
describe "find_users" do
|
42
|
+
it "returns all the users" do
|
43
|
+
VCR.use_cassette('staff_portal/psc/all_users') do
|
44
|
+
users = @ncs_navigator_authority.find_users
|
45
|
+
users.count.should == 6
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
it "returns and empty array if passed criteria" do
|
50
|
+
VCR.use_cassette('staff_portal/psc/all_users') do
|
51
|
+
users = @ncs_navigator_authority.find_users({"a" => "b"})
|
52
|
+
users.should be_empty
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
|
42
58
|
describe "#amplify!" do
|
43
59
|
before do
|
44
60
|
@lee = mock(Aker::User, :username => "lee", :cas_proxy_ticket => "PT-cas-ticket",:first_name => "Lee", :portals => [:NCSNavigator])
|
45
61
|
@before_lee = mock(Aker::User, :username => "lee", :cas_proxy_ticket => "PT-cas-ticket", :merge! => @lee)
|
46
62
|
end
|
47
|
-
|
63
|
+
|
48
64
|
def actual
|
49
65
|
VCR.use_cassette('staff_portal/core/user') do
|
50
66
|
@ncs_navigator_authority.amplify!(@before_lee)
|
@@ -54,16 +70,16 @@ describe NcsNavigator::Authorization::Core::Authority do
|
|
54
70
|
it "copies simple attributes" do
|
55
71
|
actual.first_name.should == "Lee"
|
56
72
|
end
|
57
|
-
|
73
|
+
|
58
74
|
it "copies portal" do
|
59
75
|
actual.portals.should == [:NCSNavigator]
|
60
76
|
end
|
61
|
-
|
77
|
+
|
62
78
|
it "does nothing for an unknown user" do
|
63
79
|
VCR.use_cassette('staff_portal/core/unknown_user') do
|
64
80
|
lambda { @ncs_navigator_authority.amplify!(mock(Aker::User, :username => "lees", :cas_proxy_ticket => "PT-cas-ticket"))}.should_not raise_error
|
65
81
|
end
|
66
82
|
end
|
67
83
|
end
|
68
|
-
|
84
|
+
|
69
85
|
end
|
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:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
+
- 1
|
8
9
|
- 0
|
9
|
-
|
10
|
-
version: 1.0.0
|
10
|
+
version: 1.1.0
|
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-
|
18
|
+
date: 2012-11-20 00:00:00 -06:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -185,6 +185,7 @@ files:
|
|
185
185
|
- spec/fixtures/vcr_cassettes/staff_portal/psc/users_by_last_or_user_name.yml
|
186
186
|
- spec/fixtures/vcr_cassettes/staff_portal/psc/users_by_role.yml
|
187
187
|
- spec/fixtures/vcr_cassettes/staff_portal/psc/users_by_username.yml
|
188
|
+
- spec/fixtures/vcr_cassettes/staff_portal/psc/users_with_null_username.yml
|
188
189
|
- spec/navigator.ini
|
189
190
|
- spec/ncs_navigator/.DS_Store
|
190
191
|
- spec/ncs_navigator/authorization/core/authority_spec.rb
|
@@ -246,6 +247,7 @@ test_files:
|
|
246
247
|
- spec/fixtures/vcr_cassettes/staff_portal/psc/users_by_last_or_user_name.yml
|
247
248
|
- spec/fixtures/vcr_cassettes/staff_portal/psc/users_by_role.yml
|
248
249
|
- spec/fixtures/vcr_cassettes/staff_portal/psc/users_by_username.yml
|
250
|
+
- spec/fixtures/vcr_cassettes/staff_portal/psc/users_with_null_username.yml
|
249
251
|
- spec/navigator.ini
|
250
252
|
- spec/ncs_navigator/.DS_Store
|
251
253
|
- spec/ncs_navigator/authorization/core/authority_spec.rb
|