1
|
/**
|
2
|
* Copyright (C) 2009 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.cdm.permission;
|
10
|
|
11
|
import java.util.Collection;
|
12
|
import java.util.Set;
|
13
|
|
14
|
import org.springframework.security.core.Authentication;
|
15
|
import org.springframework.security.core.GrantedAuthority;
|
16
|
|
17
|
import eu.etaxonomy.cdm.model.common.User;
|
18
|
import eu.etaxonomy.cdm.model.description.DescriptionBase;
|
19
|
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
|
20
|
import eu.etaxonomy.cdm.model.description.Feature;
|
21
|
|
22
|
/**
|
23
|
* @author k.luther
|
24
|
* @date 06.07.2011
|
25
|
*
|
26
|
*/
|
27
|
public class DescriptionPermissionEvaluator {
|
28
|
|
29
|
public static boolean hasPermission(Collection<GrantedAuthority> authorities,
|
30
|
DescriptionElementBase targetDomainObject, AuthorityPermission evalPermission) {
|
31
|
|
32
|
Feature feature = targetDomainObject.getFeature();
|
33
|
String authorityString;
|
34
|
for (GrantedAuthority authority: authorities){
|
35
|
authorityString = authority.getAuthority();
|
36
|
AuthorityPermission authorityPermission = new AuthorityPermission(authorityString);
|
37
|
String label = feature.getLabel();
|
38
|
if (authorityString.contains(feature.getLabel()) && evalPermission.permission.equals(authorityPermission.permission)){
|
39
|
return true;
|
40
|
}
|
41
|
}
|
42
|
|
43
|
return false;
|
44
|
}
|
45
|
|
46
|
|
47
|
public static boolean hasPermission (Collection<GrantedAuthority> authorities,
|
48
|
DescriptionBase targetDomainObject, AuthorityPermission evalPermission){
|
49
|
Set<DescriptionElementBase> elements = targetDomainObject.getElements();
|
50
|
|
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
|
for (DescriptionElementBase element: elements){
|
57
|
if (authority.getAuthority().contains(element.getFeature().getLabel()) && authority.getAuthority().contains(evalPermission.permission.toString())){
|
58
|
return true;
|
59
|
}
|
60
|
}
|
61
|
}
|
62
|
}
|
63
|
}
|
64
|
|
65
|
|
66
|
return false;
|
67
|
|
68
|
}
|
69
|
}
|