Project

General

Profile

Download (2.48 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2014 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

    
13
import org.springframework.security.access.ConfigAttribute;
14

    
15
import eu.etaxonomy.cdm.model.common.CdmBase;
16
import eu.etaxonomy.cdm.model.name.Registration;
17
import eu.etaxonomy.cdm.model.name.RegistrationStatus;
18
import eu.etaxonomy.cdm.persistence.hibernate.permission.CdmAuthority;
19

    
20
/**
21
 * @author a.kohlbecker
22
 * @date Feb 24, 2014
23
 *
24
 */
25
public class RegistrationVoter extends CdmPermissionVoter {
26

    
27
    /* (non-Javadoc)
28
     * @see eu.etaxonomy.cdm.persistence.hibernate.permission.voter.CdmPermissionVoter#getResponsibilityClass()
29
     */
30
    @Override
31
    public Class<? extends CdmBase> getResponsibilityClass() {
32
        return Registration.class;
33
    }
34

    
35
    /* (non-Javadoc)
36
     * @see eu.etaxonomy.cdm.persistence.hibernate.permission.voter.CdmPermissionVoter#isOrpahn(eu.etaxonomy.cdm.model.common.CdmBase)
37
     */
38
    @Override
39
    public boolean isOrpahn(CdmBase object) {
40
        return ((Registration)object).getTypeDesignations().size() > 0 && ((Registration)object).getName() == null;
41
    }
42

    
43
    /**
44
     * {@inheritDoc}
45
     */
46
    @Override
47
    protected Integer furtherVotingDescisions(CdmAuthority cdmAuthority, Object object, Collection<ConfigAttribute> attributes, ValidationResult vr) {
48

    
49
        // we only need to implement the case where a property is contained in the authority
50
        // the other case is covered by the CdmPermissionVoter
51
        if(cdmAuthority.hasProperty() && object instanceof Registration){
52

    
53
            RegistrationStatus status = ((Registration)object).getStatus();
54
            vr.isPropertyMatch = cdmAuthority.getProperty().contains(status.name());
55
            logger.debug("property is matching");
56

    
57
            if(vr.isPropertyMatch){
58
                if(vr.isIgnoreUuidMatch){
59
                    logger.debug("ignoring the uuid match result");
60
                    return ACCESS_GRANTED;
61
                }
62
                if(vr.isUuidMatch){
63
                    return ACCESS_GRANTED;
64
                } else {
65
                    return ACCESS_DENIED;
66
                }
67
            } else {
68
                return ACCESS_DENIED;
69
            }
70

    
71
        }
72

    
73
        return ACCESS_ABSTAIN; // ignore my further vote
74
    }
75

    
76

    
77

    
78
}
(7-7/12)