1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.opencastproject.security.api;
23
24 import org.apache.commons.lang3.StringUtils;
25
26 import javax.xml.bind.annotation.XmlAccessType;
27 import javax.xml.bind.annotation.XmlAccessorType;
28 import javax.xml.bind.annotation.XmlRootElement;
29 import javax.xml.bind.annotation.XmlType;
30
31
32
33
34 @XmlAccessorType(XmlAccessType.FIELD)
35 @XmlType(name = "ace", namespace = "http://org.opencastproject.security", propOrder = { "action", "allow", "role" })
36 @XmlRootElement(name = "ace", namespace = "http://org.opencastproject.security")
37 public final class AccessControlEntry {
38
39
40 private String role = null;
41
42
43 private String action = null;
44
45
46 private boolean allow = false;
47
48
49
50
51 public AccessControlEntry() {
52 }
53
54
55
56
57
58
59
60
61
62
63
64 public AccessControlEntry(String role, String action, boolean allow) {
65 this.role = role;
66 this.action = action;
67 this.allow = allow;
68 }
69
70
71
72
73 public String getRole() {
74 return role;
75 }
76
77
78
79
80 public String getAction() {
81 return action;
82 }
83
84
85
86
87 public boolean isAllow() {
88 return allow;
89 }
90
91 public boolean isValid() {
92 return StringUtils.isNotBlank(role) && StringUtils.isNotBlank(action);
93 }
94
95
96
97
98
99
100 @Override
101 public boolean equals(Object obj) {
102 if (obj instanceof AccessControlEntry) {
103 AccessControlEntry other = (AccessControlEntry) obj;
104 return this.allow == other.allow && this.role.equals(other.role) && this.action.equals(other.action);
105 } else {
106 return false;
107 }
108 }
109
110
111
112
113
114
115 @Override
116 public int hashCode() {
117 return (role + action + Boolean.toString(allow)).hashCode();
118 }
119
120
121
122
123
124
125 @Override
126 public String toString() {
127 StringBuilder sb = new StringBuilder(role).append(" is ");
128 if (!allow)
129 sb.append("not ");
130 sb.append("allowed to ");
131 sb.append(action);
132 return sb.toString();
133 }
134
135 }