View Javadoc

1   /*
2    * Copyright 2015 Data Archiving and Networked Services (an institute of
3    * Koninklijke Nederlandse Akademie van Wetenschappen), King's College London,
4    * Georg-August-Universitaet Goettingen Stiftung Oeffentlichen Rechts
5    *
6    * Licensed under the EUPL, Version 1.1 or – as soon they will be approved by
7    * the European Commission - subsequent versions of the EUPL (the "Licence");
8    * You may not use this work except in compliance with the Licence.
9    * You may obtain a copy of the Licence at:
10   *
11   * https://joinup.ec.europa.eu/software/page/eupl
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the Licence is distributed on an "AS IS" basis,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the Licence for the specific language governing
17   * permissions and limitations under the Licence.
18   */
19  
20  package eu.ehri.project.exceptions;
21  
22  /**
23   * Represents a violation of the permission system constraints
24   * on the modification of data.
25   */
26  public class PermissionDenied extends Exception {
27  
28      private static final long serialVersionUID = -3948097018322416889L;
29  
30      private String accessor;
31      private String entity;
32      private String scope;
33      private String permission;
34  
35      public PermissionDenied(String accessor, String message) {
36          super(String.format("Permission denied accessing resource as '%s': %s",
37                  accessor, message));
38          this.accessor = accessor;
39      }
40  
41      public PermissionDenied(String message) {
42          super(message);
43      }
44  
45      public PermissionDenied(String accessor, String entity, String message) {
46          super(String.format(
47                  "Permission denied accessing resource '%s' as '%s': %s",
48                  entity, accessor, message));
49          this.accessor = accessor;
50          this.entity = entity;
51      }
52  
53      public PermissionDenied(String accessor, String entity,
54              String permission, String scope) {
55          super(
56                  String.format(
57                          "Permission '%s' denied for resource '%s' as '%s' with scope '%s'",
58                          permission, entity,
59                          accessor, scope));
60          this.accessor = accessor;
61          this.entity = entity;
62          this.scope = scope;
63          this.permission = permission;
64      }
65  
66      public String getAccessor() {
67          return accessor;
68      }
69  
70      public String getEntity() {
71          return entity;
72      }
73  
74      public String getScope() {
75          return scope;
76      }
77  
78      public String getPermission() {
79          return permission;
80      }
81  }