1
|
/**
|
2
|
* Copyright (C) 2012 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.persistence.hibernate.permission.voter;
|
10
|
|
11
|
import java.util.Collection;
|
12
|
import java.util.UUID;
|
13
|
|
14
|
import org.apache.log4j.Logger;
|
15
|
import org.springframework.security.access.ConfigAttribute;
|
16
|
|
17
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
18
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
19
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
20
|
import eu.etaxonomy.cdm.persistence.hibernate.permission.CdmAuthority;
|
21
|
|
22
|
/**
|
23
|
* @author andreas kohlbecker
|
24
|
\* @since Sep 4, 2012
|
25
|
*
|
26
|
*/
|
27
|
public class TaxonNodeVoter extends CdmPermissionVoter {
|
28
|
|
29
|
public static final Logger logger = Logger.getLogger(TaxonNodeVoter.class);
|
30
|
|
31
|
@Override
|
32
|
public Class<? extends CdmBase> getResponsibilityClass() {
|
33
|
return TaxonNode.class;
|
34
|
}
|
35
|
|
36
|
/* (non-Javadoc)
|
37
|
* @see eu.etaxonomy.cdm.persistence.hibernate.permission.voter.CdmPermissionVoter#furtherVotingDescisions(org.springframework.security.core.Authentication, java.lang.Object, java.util.Collection, eu.etaxonomy.cdm.persistence.hibernate.permission.voter.TaxonBaseVoter.ValidationResult)
|
38
|
*/
|
39
|
@Override
|
40
|
protected Integer furtherVotingDescisions(CdmAuthority CdmAuthority, Object object, Collection<ConfigAttribute> attributes,
|
41
|
ValidationResult validationResult) {
|
42
|
|
43
|
boolean isUuidMatchInParentNodes = CdmAuthority.hasTargetUuid() && findTargetUuidInParentNodes(CdmAuthority.getTargetUUID(), (TaxonNode)object);
|
44
|
if ( isUuidMatchInParentNodes && validationResult.isClassMatch && validationResult.isPermissionMatch){
|
45
|
logger.debug("permission, class and uuid in parent nodes are matching => ACCESS_GRANTED");
|
46
|
return ACCESS_GRANTED;
|
47
|
}
|
48
|
return null;
|
49
|
}
|
50
|
|
51
|
/**
|
52
|
* @param targetUuid
|
53
|
* @param node
|
54
|
* @return
|
55
|
*/
|
56
|
private boolean findTargetUuidInParentNodes(UUID targetUuid, TaxonNode node){
|
57
|
if (targetUuid.equals(node.getUuid())) {
|
58
|
return true;
|
59
|
} else {
|
60
|
TaxonNode parentNode = HibernateProxyHelper.deproxy(node, TaxonNode.class).getParent();
|
61
|
if (parentNode != null){
|
62
|
return findTargetUuidInParentNodes(targetUuid, parentNode);
|
63
|
}
|
64
|
}
|
65
|
return false;
|
66
|
}
|
67
|
|
68
|
/* (non-Javadoc)
|
69
|
* @see eu.etaxonomy.cdm.persistence.hibernate.permission.voter.CdmPermissionVoter#isOrpahn(eu.etaxonomy.cdm.model.common.CdmBase)
|
70
|
*/
|
71
|
@Override
|
72
|
public boolean isOrpahn(CdmBase object) {
|
73
|
if(object instanceof TaxonNode){
|
74
|
return ((TaxonNode)object).getParent() == null;
|
75
|
}
|
76
|
return false;
|
77
|
}
|
78
|
|
79
|
}
|