Revision fb6e3c26
Added by Katja Luther over 12 years ago
cdmlib-model/src/main/java/eu/etaxonomy/cdm/permission/CdmPermissionEvaluator.java | ||
---|---|---|
96 | 96 |
if (targetDomainObject instanceof DescriptionElementBase){ |
97 | 97 |
return DescriptionPermissionEvaluator.hasPermission(authorities, (DescriptionElementBase)targetDomainObject, evalPermission); |
98 | 98 |
} |
99 |
if (targetDomainObject instanceof DescriptionBase){ |
|
100 |
return DescriptionPermissionEvaluator.hasPermission(authorities, (DescriptionBase)targetDomainObject, evalPermission); |
|
101 |
} |
|
99 | 102 |
for (GrantedAuthority authority: authorities){ |
100 | 103 |
AuthorityPermission authorityPermission= new AuthorityPermission(authority.getAuthority()); |
101 | 104 |
//evaluate authorities |
cdmlib-model/src/main/java/eu/etaxonomy/cdm/permission/DescriptionPermissionEvaluator.java | ||
---|---|---|
15 | 15 |
import org.springframework.security.core.GrantedAuthority; |
16 | 16 |
|
17 | 17 |
import eu.etaxonomy.cdm.model.common.User; |
18 |
import eu.etaxonomy.cdm.model.description.DescriptionBase; |
|
18 | 19 |
import eu.etaxonomy.cdm.model.description.DescriptionElementBase; |
19 | 20 |
import eu.etaxonomy.cdm.model.description.Feature; |
20 | 21 |
|
... | ... | |
41 | 42 |
|
42 | 43 |
return false; |
43 | 44 |
} |
45 |
|
|
46 |
|
|
47 |
public static boolean hasPermission (Collection<GrantedAuthority> authorities, |
|
48 |
DescriptionBase targetDomainObject, AuthorityPermission evalPermission){ |
|
49 |
Set<DescriptionElementBase> elements = targetDomainObject.getElements(); |
|
50 |
for (DescriptionElementBase element: elements){ |
|
51 |
for (GrantedAuthority authority :authorities){ |
|
52 |
if (authority.getAuthority().contains(CdmPermissionClass.DESCRIPTIONBASE.toString())){ |
|
53 |
if (authority.getAuthority().lastIndexOf(".") == authority.getAuthority().indexOf(".") && authority.getAuthority().contains(evalPermission.permission.toString())){ |
|
54 |
return true; |
|
55 |
}else{ |
|
56 |
if (authority.getAuthority().contains(element.getFeature().getLabel()) && authority.getAuthority().contains(evalPermission.permission.toString())){ |
|
57 |
return true; |
|
58 |
} |
|
59 |
} |
|
60 |
} |
|
61 |
} |
|
62 |
} |
|
63 |
|
|
64 |
return false; |
|
65 |
|
|
66 |
} |
|
44 | 67 |
} |
cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/service/SecurityTest.java | ||
---|---|---|
193 | 193 |
|
194 | 194 |
TaxonDescription description = iterator.next(); |
195 | 195 |
description = (TaxonDescription) descriptionService.find(description.getUuid()); |
196 |
Iterator<DescriptionElementBase> elements = description.getElements().iterator(); |
|
196 |
|
|
197 | 197 |
TextData textData = new TextData(); |
198 | 198 |
textData.setFeature(Feature.ECOLOGY()); |
199 | 199 |
Media media = Media.NewInstance(); |
... | ... | |
201 | 201 |
|
202 | 202 |
|
203 | 203 |
|
204 |
descriptionService.saveDescriptionElement(textData); |
|
204 |
//descriptionService.saveDescriptionElement(textData);
|
|
205 | 205 |
description.addElement(textData); |
206 | 206 |
|
207 | 207 |
descriptionService.saveOrUpdate(description); |
... | ... | |
212 | 212 |
iterator = descriptions.iterator(); |
213 | 213 |
|
214 | 214 |
description = iterator.next(); |
215 |
assertEquals(1,description.getElements().iterator().next().getMedia().size()); |
|
215 |
assertEquals(1, descriptions.size()); |
|
216 |
assertEquals(2,description.getElements().size()); |
|
217 |
|
|
218 |
|
|
216 | 219 |
|
217 | 220 |
} |
218 | 221 |
|
cdmlib-services/src/test/resources/eu/etaxonomy/cdm/api/service/SecurityTest.xml | ||
---|---|---|
21 | 21 |
<GRANTEDAUTHORITYIMPL ID="10" UUID="2fbcbdd4-97f0-4561-b635-1e479dd00375" CREATED="2009-02-03 17:52:26.0" AUTHORITY="TAXONBASE.ADMIN"/> |
22 | 22 |
<GRANTEDAUTHORITYIMPL ID="5" UUID="9eabd2c6-0590-4a1e-95f5-99cc58b63aa7" CREATED="2009-02-03 17:52:26.0" AUTHORITY="ALL.ADMIN"/> |
23 | 23 |
<GRANTEDAUTHORITYIMPL ID="7" UUID="2fc19d6c-a227-41d8-94e4-7c31accebc26" CREATED="2009-02-03 17:52:26.0" AUTHORITY="DESCRIPTIONBASE.UPDATE"/> |
24 |
<GRANTEDAUTHORITYIMPL ID="11" UUID="fc8088cf-cf96-42b6-9aa5-7c1ec5ccf145" CREATED="2009-02-03 17:52:26.0" AUTHORITY="DESCRIPTIONBASE.Ecology.UPDATE"/>
|
|
24 |
<GRANTEDAUTHORITYIMPL ID="11" UUID="fc8088cf-cf96-42b6-9aa5-7c1ec5ccf145" CREATED="2009-02-03 17:52:26.0" AUTHORITY="DESCRIPTIONBASE.Ecology.UPDATE"/> |
|
25 | 25 |
<GRANTEDAUTHORITYIMPL ID="12" UUID="8d131171-d281-4911-a960-16992de384c7" CREATED="2009-02-03 17:52:26.0" AUTHORITY="DESCRIPTIONBASE.Ecology.CREATE"/> |
26 | 26 |
<GRANTEDAUTHORITYIMPL ID="8" UUID="45b40e93-88b0-40eb-92a4-ffdd8f1d7bc3" CREATED="2009-02-03 17:52:26.0" AUTHORITY="TAXONNODE.UPDATE{20c8f083-5870-4cbd-bf56-c5b2b98ab6a7}"/> |
27 | 27 |
<GRANTEDAUTHORITYIMPL ID="9" UUID="8696ef0f-e98c-4842-b9d2-456b82584c25" CREATED="2009-02-03 17:52:26.0" AUTHORITY="TAXONNODE.CREATE{20c8f083-5870-4cbd-bf56-c5b2b98ab6a7}"/> |
... | ... | |
33 | 33 |
<USERACCOUNT USERNAME="partEditor" ID="5" CREATED="2009-06-18 13:47:59.0" UUID="38a251bd-0ba4-426f-8fcb-5c09560749a7" PASSWORD="41af8a6dac9f86b1081aa5840df75a53" ENABLED="true" ACCOUNTNONEXPIRED="true" CREDENTIALSNONEXPIRED="true" ACCOUNTNONLOCKED="true"/> |
34 | 34 |
<USERACCOUNT_GRANTEDAUTHORITYIMPL USERACCOUNT_ID="1" GRANTEDAUTHORITIES_ID="5"/> |
35 | 35 |
<USERACCOUNT_GRANTEDAUTHORITYIMPL USERACCOUNT_ID="2" GRANTEDAUTHORITIES_ID="7"/> |
36 |
<USERACCOUNT_GRANTEDAUTHORITYIMPL USERACCOUNT_ID="2" GRANTEDAUTHORITIES_ID="11"/>
|
|
36 |
<USERACCOUNT_GRANTEDAUTHORITYIMPL USERACCOUNT_ID="2" GRANTEDAUTHORITIES_ID="11"/>
|
|
37 | 37 |
<USERACCOUNT_GRANTEDAUTHORITYIMPL USERACCOUNT_ID="2" GRANTEDAUTHORITIES_ID="12"/> |
38 | 38 |
<USERACCOUNT_PERMISSIONGROUP GROUPS_ID="1" MEMBERS_ID="1"/> |
39 | 39 |
<USERACCOUNT_PERMISSIONGROUP GROUPS_ID="2" MEMBERS_ID="1"/> |
Also available in: Unified diff