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
25 import java.util.Objects;
26
27 import javax.xml.bind.annotation.XmlAccessType;
28 import javax.xml.bind.annotation.XmlAccessorType;
29 import javax.xml.bind.annotation.XmlElement;
30 import javax.xml.bind.annotation.XmlRootElement;
31 import javax.xml.bind.annotation.XmlType;
32
33
34
35
36 @XmlAccessorType(XmlAccessType.FIELD)
37 @XmlType(name = "role", namespace = "http://org.opencastproject.security")
38 @XmlRootElement(name = "role", namespace = "http://org.opencastproject.security")
39 public final class JaxbRole implements Role {
40
41
42 @XmlElement(name = "name")
43 protected String name;
44
45
46 @XmlElement(name = "description")
47 protected String description;
48
49 @XmlElement(name = "organization")
50 protected JaxbOrganization organization;
51
52 @XmlElement(name = "organization-id")
53 protected String organizationId;
54
55 @XmlElement(name = "type")
56 protected Type type = Type.INTERNAL;
57
58
59
60
61 public JaxbRole() {
62 }
63
64
65
66
67
68
69
70
71
72 public JaxbRole(String name, JaxbOrganization organization) throws IllegalArgumentException {
73 super();
74 this.name = name;
75 this.organizationId = organization.getId();
76 }
77
78
79
80
81
82
83
84
85
86
87
88 public JaxbRole(String name, JaxbOrganization organization, String description) throws IllegalArgumentException {
89 this(name, organization);
90 this.description = description;
91 }
92
93
94
95
96
97
98
99
100
101
102
103
104
105 public JaxbRole(String name, JaxbOrganization organization, String description, Type type) throws IllegalArgumentException {
106 this(name, organization, description);
107 this.type = type;
108 }
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123 public JaxbRole(String name, String organizationId, String description, Type type) throws IllegalArgumentException {
124 super();
125 this.name = name;
126 this.organizationId = organizationId;
127 this.description = description;
128 this.type = type;
129 }
130
131 public static JaxbRole fromRole(Role role) {
132 if (role instanceof JaxbRole)
133 return (JaxbRole) role;
134 return new JaxbRole(role.getName(), role.getOrganizationId(), role.getDescription(), role.getType());
135 }
136
137
138
139
140
141
142 @Override
143 public String getName() {
144 return name;
145 }
146
147
148
149
150
151
152 @Override
153 public String getDescription() {
154 return description;
155 }
156
157
158
159
160 public String getOrganizationId() {
161 if (organizationId != null) {
162 return organizationId;
163 }
164 if (organization != null) {
165 return organization.getId();
166 }
167 return null;
168 }
169
170
171
172
173
174
175 public Type getType() {
176 return type;
177 }
178
179
180
181
182
183
184 @Override
185 public int hashCode() {
186 return Objects.hash(name, getOrganizationId());
187 }
188
189
190
191
192
193
194 @Override
195 public boolean equals(Object obj) {
196 if (!(obj instanceof Role))
197 return false;
198 Role other = (Role) obj;
199 return name.equals(other.getName())
200 && Objects.equals(getOrganizationId(), other.getOrganizationId());
201 }
202
203
204
205
206
207
208 @Override
209 public String toString() {
210 return name + ":" + getOrganizationId();
211 }
212 }