Project

General

Profile

Download (2.45 KB) Statistics
| Branch: | Tag: | Revision:
1

    
2
package eu.etaxonomy.cdm.database;
3

    
4
import java.util.EnumSet;
5

    
6
import org.apache.log4j.Logger;
7
import org.hibernate.HibernateException;
8
import org.springframework.security.core.Authentication;
9

    
10
import eu.etaxonomy.cdm.model.common.CdmBase;
11
import eu.etaxonomy.cdm.persistence.hibernate.permission.CRUD;
12
import eu.etaxonomy.cdm.persistence.hibernate.permission.Operation;
13
import eu.etaxonomy.cdm.persistence.hibernate.permission.Role;
14

    
15
/**
16
 * @author andreas
17
 * @since Sep 4, 2012
18
 */
19
public class PermissionDeniedException extends HibernateException {
20
    private static final long serialVersionUID = 6993452039967589921L;
21
    @SuppressWarnings("unused")
22
    private static final Logger logger = Logger.getLogger(PermissionDeniedException.class);
23

    
24
    /**
25
     * @param message
26
     */
27
    public PermissionDeniedException(String message) {
28
        super(message);
29
    }
30

    
31
    public PermissionDeniedException(Authentication authentication, CdmBase entity, Operation requiredOperation) {
32
        super(requiredOperation + " not permitted for '" + authentication.getName()
33
                + "' on " + entity.getClass().getSimpleName() + "[uuid:" + entity.getUuid() + "', toString:'" + entity.toString() + "']");
34
    }
35

    
36
    public PermissionDeniedException(Authentication authentication, CdmBase entity, EnumSet<CRUD> requiredOperation) {
37
        super(requiredOperation + " not permitted for '" + authentication.getName()
38
                + "' on " + entity.getClass().getSimpleName() + "[uuid:" + entity.getUuid() + "', toString:'" + entity.toString() + "']");
39
    }
40

    
41
    public PermissionDeniedException(Authentication authentication, CdmBase entity, String requiredOperation) {
42
        super(requiredOperation + " not permitted for '" + authentication.getName()
43
                + "' on " + entity.getClass().getSimpleName() + "[uuid:" + entity.getUuid() + "', toString:'" + entity.toString() + "']");
44
    }
45

    
46
    /**
47
     * @param authentication
48
     * @param roles
49
     */
50
    public PermissionDeniedException(Authentication authentication, Role[] roles) {
51

    
52
        super("Permission denied for '" + authentication.getName()
53
                + "' none of the roles '" + roles + "' found in authentication.");
54
    }
55

    
56
    /**
57
     * @param cause
58
     */
59
    public PermissionDeniedException(Throwable cause) {
60
        super(cause);
61
    }
62

    
63
    /**
64
     * @param message
65
     * @param cause
66
     */
67
    public PermissionDeniedException(String message, Throwable cause) {
68
        super(message, cause);
69
    }
70

    
71
}
(17-17/20)