Project

General

Profile

CdmAuthorisationAndAccessControl » History » Version 49

Andreas Kohlbecker, 01/17/2017 11:27 AM

1 1 Andreas Kohlbecker
2 3 Andreas Kohlbecker
# Cdm authorisation and access control
3 2 Andreas Kohlbecker
4 25 Andreas Kohlbecker
----
5
6 49 Andreas Kohlbecker
*Another page on this topic is found in the BDI wiki: http://wiki.bgbm.org/bdinotes/index.php/EDIT_Security*
7 25 Andreas Kohlbecker
8
9
----
10
11
12 2 Andreas Kohlbecker
It is evident that the cdm library needs authorisation and access control. There are library methods which need to protected from unauthorised execution and there is also the data which is exposed by the library. Not all data should be visible to every user so a [[HibernateSpringAndRowlevelSecurity|row level access control]] is needed.
13
14
15 4 Andreas Kohlbecker
## Questions
16 2 Andreas Kohlbecker
17 7 Andreas Kohlbecker
1. Do we need a access control in the web service (cdmlib-remote) or is it sufficient to protect the service layer. As long web service controllers are not using DAO (cdmlib-persistence) methods directly it should not be necessary.
18 4 Andreas Kohlbecker
19
20 3 Andreas Kohlbecker
## Use cases
21 4 Andreas Kohlbecker
22 12 Andreas Kohlbecker
 A. a specific **classification sub tree** is **publicly visible** that is it is _published_
23
 B. a specific **classification sub tree** must not be **publicly visible** in the data portal and thus must be also hidden in the web service responses
24
 C. a specific **classification sub tree** is only visible for users which have a specific **role** but the user is not granted to **edit** anything in/below it
25 19 Andreas Kohlbecker
 D. A user is only granted to **edit Descriptions** 
26
 E. A user is only granted to **edit DescriptionElements** of a specific _Feature_ 
27
 F. A user is only granted to **edit structured Descriptions** 
28
 G. Combinations of B, C and D, E must be possible
29
 H. Only users with the **roles** *Admin* or **Usermanager** or the user in question it self (if currently authenticated) are allowed to execute **change password** 
30
 I. Only users with the **roles** *Admin* or **Usermanager** are allowed to create or **edit** new users
31 12 Andreas Kohlbecker
32 1 Andreas Kohlbecker
~~~
33
<code class="rst">
34
Tabular summary of above use cases translated into roles:
35
36 19 Andreas Kohlbecker
===========  =========================  ======================================  ===============  =============================
37
\                                                                               what to protect
38
-----------  -------------------------  --------------------------------------  ----------------------------------------------
39
Usecase      Role                       authority string                        Entity            ServiceMethod
40
===========  =========================  ======================================  ===============  =============================
41 41 Andreas Kohlbecker
A.           Anonymous                  TaxonNode.[READ]{uuid}                     ...
42
B.           TaxGroupX_User             TaxonNode.[READ]{uuid}                     ...
43
C.           TaxGroupX_Editor           TaxonNode.[UPDATE]{uuid}                   ...
44
D.           DescriptionEditor		Description.[UPDATE]			 ...					
45
E.           DescriptionEditor		DescriptioElement(Ecology).[UPDATE]        ...					
46 19 Andreas Kohlbecker
H.           Admin, Usermanager                                                                  UserService.changePassword()
47
===========  =========================  ======================================  ===============  =============================
48 1 Andreas Kohlbecker
49
*Anonymous* means not authenticated  
50
51
~~~
52 17 Andreas Kohlbecker
53
 **Special cases:** 
54
55 18 Andreas Kohlbecker
* **@TaxonNames@** can potentially be shared between different taxa, thus a situation may occur where a user has grants to edit taxon A but not for taxon B, but both taxa are sharing the same name. How will we handle this situation, should the name be cloned when the user starts editing taxon A, so that taxon A has another name entity than taxon B after the user saved the latest changes?
56 12 Andreas Kohlbecker
* The same problem as described above for TaxonNames also accounts for *@References@*, but in this case the problem is more severe since references are very often part of multiple taxon names. 
57 19 Andreas Kohlbecker
58
59
## Implementation details
60
61 20 Andreas Kohlbecker
_only a brief note for now, compiled by a lot of copy paste from the java doc:_
62 19 Andreas Kohlbecker
63
64 20 Andreas Kohlbecker
### Roles and CdmAuthorities
65
66
67
#### Roles
68
69
only one hard coded role: `ROLE_ADMIN` 
70
71
72
#### CdmAuthority
73
74 21 Andreas Kohlbecker
A `CdmAuthority` consists basically of two parts which are separated by a dot character '.'.
75 20 Andreas Kohlbecker
76 21 Andreas Kohlbecker
* permissionClass: an `CdmPermissionClass` instance with represents a cdm type or a part of the cdm type hierarchy. The className is always represented as an upper case string.
77
* property: The `CdmAuthority` only applies to instances which satisfy the specified property. Interpretation is up to type specific voters.
78
* operation: a string which specifies a `Operation` on that set of cdm types
79 1 Andreas Kohlbecker
* targetUuid: The operation may be restricted to a specific cdm entity by adding the entity uuid to the operation. The uuid string is enclosed in curly brackets '{' , '}' and appended to the end of the operation.
80 20 Andreas Kohlbecker
81
Examples for permissionStrings:
82
83
~~~
84 41 Andreas Kohlbecker
 TAXONBASE.[CREATE]
85
 TAXONBASE.[READ]
86
 TAXONBASE.[UPDATE]
87
 TAXONBASE.[DELETE]
88
 TAXONBASE.[DELETE,CREATE,UPDATE,READ]
89
 DESCRIPTIONBASE.UPDATE]
90
 DESCRIPTIONELEMENTBASE(Ecology).UPDATE]
91 1 Andreas Kohlbecker
 TAXONNODE.UPDATE{20c8f083-5870-4cbd-bf56-c5b2b98ab6a7}
92
~~~
93 21 Andreas Kohlbecker
94 24 Andreas Kohlbecker
in contrast to CdmAuthorities there are more general role like the following listed below, all these roles are having the  role prefix `'ROLE_'` which is defined in the String Security RoleVoter class:
95
96
~~~
97
 ROLE_ADMIN
98
 ROLE_USER_MANAGER
99
~~~
100
101 43 Andreas Kohlbecker
### Permission Groups
102
103
Permission groups can usually created as needed. The group name should reflect semantics the nature of the permission group.
104
105
The cdm provides default permission groups which are created by the `FirstDataInserter` in case they do not yet exist. See #4082 (implement default permission groups) for implementation details. Currently the following default permission groups exist: 
106
107 45 Andreas Kohlbecker
1. *Editor*: Contains all Authorities which are required to be granted for general editing, except the Authority for a specific taxonomical group. In order to actually enable an Editor to edit something it must be associated with a TAXONNODE Authority, e.g: @TAXONNODE.[CREATE,UPDATE,DELETE,READ]{...@}. Users which belong to this permission group are prohibited from toggling the publish-flag and from changing or deleting references and authors, but are able to create new ones. Once a 'Editor' has created a new Reference or Author the new entity is considered being still in the process of being created for some time even if the entity has already been saved to the database. See #4305 (newly created entities must stay editable even if a user only has the permission to create them) for implementation details on this feature.
108 43 Andreas Kohlbecker
109
~~~
110
REFERENCE.[CREATE,READ]
111
TAXONNAMEBASE.[CREATE,READ,UPDATE]
112
TEAMORPERSONBASE.[CREATE,READ]
113
TAXONBASE.[CREATE,UPDATE,DELETE,READ]
114
DESCRIPTIONBASE.[CREATE,UPDATE,DELETE,READ]
115
DESCRIPTIONELEMENTBASE.[CREATE,UPDATE,DELETE,READ]
116
~~~
117 44 Andreas Kohlbecker
1. *ProjectManager*: A permission group which enables a User to edit and delete entities which are of central importance for a whole project. Users which belong to this permission group are granted to edit and delete taxa, names, references, authors, terms and can toggle the publish-flag on taxa, speciemens and occurrences.
118 43 Andreas Kohlbecker
119
~~~
120
REFERENCE.[UPDATE,DELETE]
121
TAXONNAMEBASE.[DELETE]
122
TEAMORPERSONBASE.[UPDATE,DELETE]
123
ROLE_PROJECT_MANAGER
124
~~~
125
126 21 Andreas Kohlbecker
### Authorisation control
127
128
Different approaches of authorisation control need to be used in order to implement all kinds of CRUD permissions:
129
130
* service layer: method `@PreAuthorize` annotations with Spring EL, e.g. UserService:
131
132
~~~
133
@PreAuthorize("#username == authentication.name or hasRole('ROLE_ADMIN')")
134
public void changePasswordForUser(String username, String newPassword) {
135 1 Andreas Kohlbecker
...
136 21 Andreas Kohlbecker
~~~
137 1 Andreas Kohlbecker
* UPDATE and CREATE of cdm instances is protected by a Hibernate interceptor, the `CdmSecurityHibernateInterceptor@. This interceptor implements the  @onSave()` and `onFlushDirty` methods and thus can control creation and updating of cdm objects. Hibernate calls these methods for any entity which needs to be persisted even if a save or update operations causes a cascading save of objects connected to the object graph which is being saved. **TODO** implement DELETE (#3079)
138 21 Andreas Kohlbecker
* READ permissions can not be implemented using the `CdmSecurityHibernateInterceptor@. Reasons: @onLoad()` is called just before an object is initialized, so the object has no uuid or anything else with would be needed to decide on principals authorisation. A row based access control mechanism is required, see [[HibernateSpringAndRowlevelSecurity]]
139
140
141 4 Andreas Kohlbecker
142
143 22 Andreas Kohlbecker
### Authorisation evaluation
144
145
146 41 Andreas Kohlbecker
One of the central classes for the evaluation of Roles and CdmAuthorities is the `CdmPermissionEvluator` with implements the `org.springframework.security.access.PermissionEvaluator@. The method @public boolean hasPermission(Authentication authentication, Object targetDomainObject, Object permission)` will always return true if the authentication has the role `ROLE_ADMIN` otherwise decission making is delegated to a `AccessDecisionManager` which should be `UnanimousBasedUnrevocable@. This @AccessDecisionManager` polls all configured AccessDecisionVoters grants access if only grant (or abstain) votes were received. The `AccessDecisionManager` then asks the set of plugged in **@AccessDecisionVoter@s*. The cdm specific voters are found in the package eu.etaxonomy.cdm.persistence.hibernate.permission.voter. For actual configuration details please see the *persistence_security.xml** , here is an example: 
147 22 Andreas Kohlbecker
148 1 Andreas Kohlbecker
~~~
149 41 Andreas Kohlbecker
<bean id="accessDecisionManager" class="org.springframework.security.access.vote.UnanimousBasedUnrevocable">
150 22 Andreas Kohlbecker
        <property name="decisionVoters">
151
            <list>
152
                <bean class="eu.etaxonomy.cdm.persistence.hibernate.permission.voter.GrantAlwaysVoter" />
153
                <bean class="eu.etaxonomy.cdm.persistence.hibernate.permission.voter.TaxonNodeVoter" />
154
                <bean class="eu.etaxonomy.cdm.persistence.hibernate.permission.voter.TaxonBaseVoter" />
155
                <bean class="eu.etaxonomy.cdm.persistence.hibernate.permission.voter.DescriptionBaseVoter" />
156
                <bean class="eu.etaxonomy.cdm.persistence.hibernate.permission.voter.DescriptionElementVoter" />
157
            </list>
158
        </property>
159
</bean>
160
161
<!--
162 41 Andreas Kohlbecker
    CdmPermissionEvaluator.hasPermissions() evaluates the CdmPermissions like TAXONNODE.[UPDATE]{20c8f083-5870-4cbd-bf56-c5b2b98ab6a7}
163 22 Andreas Kohlbecker
-->
164
<bean id="cdmPermissionEvaluator" class="eu.etaxonomy.cdm.persistence.hibernate.permission.CdmPermissionEvaluator">
165
    <property name="accessDecisionManager" ref="accessDecisionManager" />
166
</bean>
167
~~~
168
169 26 Andreas Kohlbecker
170
#### AccessDecisionVoters
171
172
173 34 Andreas Kohlbecker
As briefly described above, the AccessDecisionVoters are crucial for finding a decision on whether a user is allowed to perform an operation on a specific cdm object or class of cdm objects. The operations are the so called CRUD operations. This acronym refers to Create, Read, Update, Delete. 
174 26 Andreas Kohlbecker
175 35 Andreas Kohlbecker
176
A user can have one or multiple granted authorities, for more information on granted authorities please refer to the paragraph [[CdmAuthorisationAndAccessControl#CdmAuthority|CdmAuthority]] above. All voters will cast votes on all granted authorities a user has.
177
178
179 1 Andreas Kohlbecker
In the following we will just use the term voter as a short form for AccessDecisionVoter. 
180 33 Andreas Kohlbecker
181 1 Andreas Kohlbecker
182 35 Andreas Kohlbecker
Voters can cast three different vote:
183 27 Andreas Kohlbecker
184
185
* Allow
186
* Deny 
187
* Abstain
188
189
190 38 Andreas Kohlbecker
In order to make a access decision the AccessDecisionVoters are asked sequentially to cast their vote. If at least one voter casts _Deny_ the the whole operation will be denied. This behaviour is guaranteed by the `GrantAlwaysVoter` which will always cast an _Allow_.
191 1 Andreas Kohlbecker
192 27 Andreas Kohlbecker
193 40 Andreas Kohlbecker
All AccessDecisionVoters are responsible for a specific class of data entities and thus it will only cast an _Allow_ or _Deny_ vote when an operation on an object of this class is to be performed. If a voter is not responsible it will _Abstain_. If a voter "feels" not responsible it casts an _Abstain_. As a consequence of this concept everything is allowed unless a voter is responsible for a specific object class. Only in this case there is the potential that an operation will be denied.
194
195
196
Generally each of the voters will check if the user has a granted authority which matches the the operation and object. Voters can also perform additional checks (see TaxonNodeVoter, DescriptionElementVoter) which can take related objects into account (parent taxon nodes) or specific properties of of Objects (feature of description element).
197 27 Andreas Kohlbecker
198
199
List of existing AccessDecisionVoters in the order of their execution:
200 30 Andreas Kohlbecker
201 28 Andreas Kohlbecker
  
202 1 Andreas Kohlbecker
1. TaxonNodeVoter: 
203 36 Andreas Kohlbecker
  * responsible for TaxonNode
204 37 Andreas Kohlbecker
  * allows if voter is responsible for the object class in question and
205
    1. if the user has a granted authority for that specific object or for all objects of this class which matches the operation to be performed
206 39 Andreas Kohlbecker
    1. or if the user has a matching granted authority for any of the parent taxon nodes in the classification (e.g.: @TAXONNODE.UPDATE{20c8f083-5870-4cbd-bf56-c5b2b98ab6a7@})
207 37 Andreas Kohlbecker
  * denies otherwise
208
1. TaxonBaseVoter:  
209
  * responsible for Taxon, Synonym
210 38 Andreas Kohlbecker
  * allows if voter is responsible for the object class in question and
211 39 Andreas Kohlbecker
    1. if the user has a granted authority for that specific object or for all objects of this class which matches the operation to be performed (e.g.: @TAXONBASE.UPDATE@)
212 38 Andreas Kohlbecker
  * denies otherwise
213
1. DescriptionBaseVoter:  
214
  * responsible for TaxonDescription, SpecimenDescription
215 37 Andreas Kohlbecker
  * allows if voter is responsible for the object class in question and
216 39 Andreas Kohlbecker
    1. if the user has a granted authority for that specific object or for all objects of this class which matches the operation to be performed (e.g.: @DESCRIPTIONBASE.UPDATE@)
217 38 Andreas Kohlbecker
  * denies otherwise
218
1. DescriptionElementVoter:  
219
  * responsible for all types of DescriptionElements
220 37 Andreas Kohlbecker
  * allows if voter is responsible for the object class in question and
221 38 Andreas Kohlbecker
    1. if the user has a granted authority for that specific object or for all objects of this class which matches the operation to be performed
222 42 Andreas Kohlbecker
    1. if the the operation to be preformed is specific to the Feature of the Description Element and if the _Property_ of one of the users granted authorities matches this Feature. (e.g.: @DESCRIPTIONELEMENTBASE(Ecology).[UPDATE]@)
223 38 Andreas Kohlbecker
  * denies otherwise
224 26 Andreas Kohlbecker
225
226
227 1 Andreas Kohlbecker