1
|
|
2
|
package eu.etaxonomy.cdm.persistence.hibernate;
|
3
|
|
4
|
|
5
|
|
6
|
import java.io.Serializable;
|
7
|
|
8
|
import org.apache.log4j.Logger;
|
9
|
import org.hibernate.EmptyInterceptor;
|
10
|
import org.hibernate.type.Type;
|
11
|
import org.springframework.security.core.context.SecurityContextHolder;
|
12
|
import org.springframework.stereotype.Component;
|
13
|
|
14
|
|
15
|
import eu.etaxonomy.cdm.permission.CdmPermission;
|
16
|
import eu.etaxonomy.cdm.permission.CdmPermissionEvaluator;
|
17
|
@Component
|
18
|
public class CdmSecurityHibernateInterceptor extends EmptyInterceptor {
|
19
|
private static final Logger logger = Logger
|
20
|
.getLogger(CdmSecurityHibernateInterceptor.class);
|
21
|
|
22
|
|
23
|
public boolean onSave(Object entity,
|
24
|
Serializable id,
|
25
|
Object[] state,
|
26
|
String[] propertyNames,
|
27
|
Type[] type) {
|
28
|
|
29
|
CdmPermissionEvaluator permissionEvaluator = new CdmPermissionEvaluator();
|
30
|
if (SecurityContextHolder.getContext().getAuthentication() != null){
|
31
|
return permissionEvaluator.hasPermission(SecurityContextHolder.getContext().getAuthentication(), entity, CdmPermission.CREATE);}
|
32
|
else return true;
|
33
|
|
34
|
}
|
35
|
public boolean onFlushDirty(Object entity,
|
36
|
Serializable id,
|
37
|
Object[] currentState,
|
38
|
Object[] previousState,
|
39
|
String[] propertyNames,
|
40
|
Type[] types) {
|
41
|
|
42
|
CdmPermissionEvaluator permissionEvaluator = new CdmPermissionEvaluator();
|
43
|
if (SecurityContextHolder.getContext().getAuthentication() != null){
|
44
|
return permissionEvaluator.hasPermission(SecurityContextHolder.getContext().getAuthentication(), entity, CdmPermission.UPDATE);}
|
45
|
else return true;
|
46
|
|
47
|
}
|
48
|
|
49
|
}
|