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.acl;
21
22 import com.fasterxml.jackson.annotation.JsonValue;
23 import com.google.common.collect.ImmutableMap;
24
25 import java.util.Map;
26
27 /**
28 * A pairing of an accessor and their non-inherited permissions.
29 */
30 class AccessorPermissions<T> {
31 final String accessorId;
32 final T permissionSet;
33
34 public AccessorPermissions(String accessorId, T permissionSet) {
35 this.accessorId = accessorId;
36 this.permissionSet = permissionSet;
37 }
38
39 @JsonValue
40 public Map<String, T> asMap() {
41 return ImmutableMap.of(accessorId, permissionSet);
42 }
43
44 @Override
45 public boolean equals(Object o) {
46 if (this == o) return true;
47 if (o == null || getClass() != o.getClass()) return false;
48
49 AccessorPermissions that = (AccessorPermissions) o;
50
51 return accessorId.equals(that.accessorId)
52 && permissionSet.equals(that.permissionSet);
53
54 }
55
56 @Override
57 public int hashCode() {
58 int result = accessorId.hashCode();
59 result = 31 * result + permissionSet.hashCode();
60 return result;
61 }
62
63 @Override
64 public String toString() {
65 return "<" + accessorId + " " + permissionSet + ">";
66 }
67 }