Project

General

Profile

Download (2.38 KB) Statistics
| Branch: | Tag: | Revision:
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.permission.voter;
10

    
11
import java.util.Collection;
12
import java.util.UUID;
13

    
14
import org.apache.logging.log4j.LogManager;import org.apache.logging.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.permission.CdmAuthority;
21
import eu.etaxonomy.cdm.persistence.permission.TargetEntityStates;
22

    
23
/**
24
 * @author andreas kohlbecker
25
 * @since Sep 4, 2012
26
 */
27
public class TaxonNodeVoter extends CdmPermissionVoter {
28

    
29
    public static final Logger logger = LogManager.getLogger(TaxonNodeVoter.class);
30

    
31
    @Override
32
    public Class<? extends CdmBase> getResponsibilityClass() {
33
        return TaxonNode.class;
34
    }
35

    
36
    @Override
37
    protected Integer furtherVotingDescisions(CdmAuthority CdmAuthority, TargetEntityStates targetEntityStates, Collection<ConfigAttribute> attributes,
38
            ValidationResult validationResult) {
39

    
40
        boolean isUuidMatchInParentNodes = CdmAuthority.hasTargetUuid() && findTargetUuidInParentNodes(CdmAuthority.getTargetUUID(), (TaxonNode)targetEntityStates.getEntity());
41
        if ( isUuidMatchInParentNodes  && validationResult.isClassMatch && validationResult.isPermissionMatch){
42
            logger.debug("permission, class and uuid in parent nodes are matching => ACCESS_GRANTED");
43
            return ACCESS_GRANTED;
44
        }
45
        return null;
46
    }
47

    
48
    private boolean findTargetUuidInParentNodes(UUID targetUuid, TaxonNode node){
49
        if (targetUuid.equals(node.getUuid())) {
50
            return true;
51
        } else {
52
            TaxonNode parentNode = HibernateProxyHelper.deproxy(node, TaxonNode.class).getParent();
53
            if (parentNode != null){
54
                 return findTargetUuidInParentNodes(targetUuid, parentNode);
55
            }
56
        }
57
        return false;
58
    }
59

    
60
    @Override
61
    public boolean isOrpahn(CdmBase object) {
62
        if(object instanceof TaxonNode){
63
            return ((TaxonNode)object).getParent() == null;
64
        }
65
        return false;
66
    }
67

    
68
}
(11-11/12)