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 validationResult) {
|
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
|
if(cdmAuthority.getProperty().contains(status.name())){
|
55
|
return ACCESS_GRANTED;
|
56
|
} else {
|
57
|
return ACCESS_DENIED;
|
58
|
}
|
59
|
|
60
|
}
|
61
|
|
62
|
return ACCESS_ABSTAIN; // ignore my further vote
|
63
|
}
|
64
|
|
65
|
|
66
|
|
67
|
}
|