hydra-access-controls 5.0.0 → 5.0.1
Sign up to get free protection for your applications and to get access to all the features.
data/README.textile
CHANGED
@@ -4,19 +4,51 @@ The hydra-access-controls gem provides access controls models and functionality
|
|
4
4
|
|
5
5
|
h2. Installation
|
6
6
|
|
7
|
-
|
7
|
+
The easiest way to make your code use this gem is to run the hydra generator that comes with the hydra-head gem. That will set up everything you need:
|
8
8
|
|
9
|
-
|
9
|
+
* adds _include Hydra::User_ to your User class
|
10
|
+
* modifies the filters in your CatalogController class to inject access controls into solr queries
|
11
|
+
* adds the YAML files that are used by the default RoleMapper class
|
12
|
+
* adds section to hydra_config initializer that sets names used to look up enforcement info in solr (see "Modifying solr field names for enforcement" below)
|
10
13
|
|
11
|
-
|
14
|
+
h2. Usage
|
12
15
|
|
13
|
-
|
16
|
+
h3. Enforcing Hydra-based Access Controls in your Controllers
|
14
17
|
|
15
|
-
|
18
|
+
They hydra generator handles part of this for you - it sets up the CatalogController (Blacklight's main controller for searches) to do gated discovery for you.
|
19
|
+
In your custom controllers, you need to tell them to enforce access controls.
|
16
20
|
|
17
|
-
|
21
|
+
*!!!This section is unfinished!!!*
|
22
|
+
_If you encounter this note, send an email to the hydra-tech mailing list asking "jcoyne":https://github.com/jcoyne to explain how to make a controller enforce Hydra-based access controls using CanCan._
|
18
23
|
|
19
|
-
|
24
|
+
|
25
|
+
h3. Modifying solr field names for enforcement
|
26
|
+
|
27
|
+
Hydra uses its own set of default solr field names to track rights-related metadata in solr. If you want to use your own field names, you can change them in your Hydra config. You will also have to modify the permissions response handler in your solrconfig.xml to return those fields.
|
28
|
+
|
29
|
+
Note: The hydra generator sets up the defaults for you in this file. You only need to edit it if you want to change the field names.
|
30
|
+
|
31
|
+
In config/initializers/hydra_config.rb
|
32
|
+
|
33
|
+
<pre>
|
34
|
+
Hydra.configure(:shared) do |config|
|
35
|
+
# ... other stuff ...
|
36
|
+
config[:permissions] = {
|
37
|
+
:discover => {:group =>"discover_access_group_t", :individual=>"discover_access_person_t"},
|
38
|
+
:read => {:group =>"read_access_group_t", :individual=>"read_access_person_t"},
|
39
|
+
:edit => {:group =>"edit_access_group_t", :individual=>"edit_access_person_t"},
|
40
|
+
:owner => "depositor_t",
|
41
|
+
:embargo_release_date => "embargo_release_date_dt"
|
42
|
+
}
|
43
|
+
config[:permissions][:inheritable] = {
|
44
|
+
:discover => {:group =>"inheritable_discover_access_group_t", :individual=>"inheritable_discover_access_person_t"},
|
45
|
+
:read => {:group =>"inheritable_read_access_group_t", :individual=>"inheritable_read_access_person_t"},
|
46
|
+
:edit => {:group =>"inheritable_edit_access_group_t", :individual=>"inheritable_edit_access_person_t"},
|
47
|
+
:owner => "inheritable_depositor_t",
|
48
|
+
:embargo_release_date => "inheritable_embargo_release_date_dt"
|
49
|
+
}
|
50
|
+
end
|
51
|
+
</pre>
|
20
52
|
|
21
53
|
h3. Policy-based Enforcement (or Collecton-level enforcement)
|
22
54
|
|
@@ -27,14 +59,15 @@ AdminPolicy objects store their inheritable rightsMetadata in a datastream calle
|
|
27
59
|
Object-level permissions and Policy-level permissions are combined to produce the list of Individuals & Groups who have access to the object. This means that if _either_ the object's rightsMetadata or the Policy's defaultRights grants access to an Individual or Group, that access will be allowed.
|
28
60
|
|
29
61
|
* Currently, an asset can have only one Policy associated with it -- you can't associate objects with multiple policies
|
30
|
-
*
|
31
62
|
|
32
63
|
To turn on Policy-based enforcement,
|
33
64
|
|
34
65
|
* include the Hydra::PolicyAwareAbility module in your Ability class (Make sure to include it _after_ Hydra::Ability because it overrides some of the methods provided by that module.)
|
35
66
|
* include the Hydra::PolicyAwareAccessControlsEnforcement module into any appropriate Controllers (or into ApplicationController)
|
36
67
|
|
37
|
-
|
68
|
+
|
69
|
+
Example app/models/ability.rb
|
70
|
+
|
38
71
|
<pre>
|
39
72
|
# Allows you to use CanCan to control access to Models
|
40
73
|
require 'cancan'
|
@@ -45,7 +78,8 @@ To turn on Policy-based enforcement,
|
|
45
78
|
end
|
46
79
|
</pre>
|
47
80
|
|
48
|
-
|
81
|
+
Example app/controllers/catalog_controller.rb
|
82
|
+
|
49
83
|
<pre>
|
50
84
|
class CatalogController < ApplicationController
|
51
85
|
|
@@ -57,30 +91,7 @@ To turn on Policy-based enforcement,
|
|
57
91
|
end
|
58
92
|
</pre>
|
59
93
|
|
60
|
-
h3. Modifying solr field names for enforcement
|
61
|
-
|
62
|
-
Hydra uses its own set of default solr field names to track rights-related metadata in solr. If you want to use your own field names, you can change them in your Hydra config. You will also have to modify the permissions response handler in your solrconfig.xml to return those fields.
|
63
94
|
|
64
|
-
# config/initializers/hydra_config.rb
|
65
|
-
<pre>
|
66
|
-
Hydra.configure(:shared) do |config|
|
67
|
-
# ... other stuff ...
|
68
|
-
config[:permissions] = {
|
69
|
-
:discover => {:group =>"discover_access_group_t", :individual=>"discover_access_person_t"},
|
70
|
-
:read => {:group =>"read_access_group_t", :individual=>"read_access_person_t"},
|
71
|
-
:edit => {:group =>"edit_access_group_t", :individual=>"edit_access_person_t"},
|
72
|
-
:owner => "depositor_t",
|
73
|
-
:embargo_release_date => "embargo_release_date_dt"
|
74
|
-
}
|
75
|
-
config[:permissions][:inheritable] = {
|
76
|
-
:discover => {:group =>"inheritable_discover_access_group_t", :individual=>"inheritable_discover_access_person_t"},
|
77
|
-
:read => {:group =>"inheritable_read_access_group_t", :individual=>"inheritable_read_access_person_t"},
|
78
|
-
:edit => {:group =>"inheritable_edit_access_group_t", :individual=>"inheritable_edit_access_person_t"},
|
79
|
-
:owner => "inheritable_depositor_t",
|
80
|
-
:embargo_release_date => "inheritable_embargo_release_date_dt"
|
81
|
-
}
|
82
|
-
end
|
83
|
-
</pre>
|
84
95
|
|
85
96
|
h2. Contributing
|
86
97
|
|
@@ -232,18 +232,22 @@ module Hydra::AccessControlsEnforcement
|
|
232
232
|
user_access_filters = []
|
233
233
|
current_ability.user_groups.each_with_index do |role, i|
|
234
234
|
permission_types.each do |type|
|
235
|
-
user_access_filters << "#{type}_access_group_t
|
235
|
+
user_access_filters << escape_filter("#{type}_access_group_t", role)
|
236
236
|
end
|
237
237
|
end
|
238
238
|
user_access_filters
|
239
239
|
end
|
240
240
|
|
241
|
+
def escape_filter(key, value)
|
242
|
+
[key, value.gsub('/', '\/')].join(':')
|
243
|
+
end
|
244
|
+
|
241
245
|
def apply_individual_permissions(permission_types)
|
242
246
|
# for individual person access
|
243
247
|
user_access_filters = []
|
244
248
|
if user_key.present?
|
245
249
|
permission_types.each do |type|
|
246
|
-
user_access_filters << "#{type}_access_person_t
|
250
|
+
user_access_filters << escape_filter("#{type}_access_person_t", user_key)
|
247
251
|
end
|
248
252
|
end
|
249
253
|
user_access_filters
|
@@ -133,6 +133,15 @@ describe Hydra::AccessControlsEnforcement do
|
|
133
133
|
@solr_parameters[:fq].first.should match(/#{type}_access_group_t\:researcher/)
|
134
134
|
end
|
135
135
|
end
|
136
|
+
|
137
|
+
it "should escape slashes in the group names" do
|
138
|
+
RoleMapper.stub(:roles).with(@stub_user.user_key).and_return(["abc/123","cde/567"])
|
139
|
+
subject.send(:apply_gated_discovery, @solr_parameters, @user_parameters)
|
140
|
+
["discover","edit","read"].each do |type|
|
141
|
+
@solr_parameters[:fq].first.should match(/#{type}_access_group_t\:abc\\\/123/)
|
142
|
+
@solr_parameters[:fq].first.should match(/#{type}_access_group_t\:cde\\\/567/)
|
143
|
+
end
|
144
|
+
end
|
136
145
|
end
|
137
146
|
|
138
147
|
describe "exclude_unwanted_models" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hydra-access-controls
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.0.
|
4
|
+
version: 5.0.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2012-12-
|
14
|
+
date: 2012-12-17 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: activesupport
|