1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.mycore.mcr.acl.accesskey.model;
20
21 import java.util.Date;
22
23 import org.mycore.backend.jpa.MCRObjectIDConverter;
24 import org.mycore.datamodel.metadata.MCRObjectID;
25
26 import com.fasterxml.jackson.annotation.JsonIgnore;
27 import com.fasterxml.jackson.annotation.JsonInclude;
28
29 import jakarta.persistence.Column;
30 import jakarta.persistence.Convert;
31 import jakarta.persistence.Entity;
32 import jakarta.persistence.GeneratedValue;
33 import jakarta.persistence.GenerationType;
34 import jakarta.persistence.Id;
35 import jakarta.persistence.NamedQueries;
36 import jakarta.persistence.NamedQuery;
37 import jakarta.persistence.Table;
38
39 @NamedQueries({
40 @NamedQuery(name = "MCRAccessKey.getWithObjectId",
41 query = "SELECT k"
42 + " FROM MCRAccessKey k"
43 + " WHERE k.objectId = :objectId"
44 + " ORDER BY k.lastModified ASC"),
45 @NamedQuery(name = "MCRAccessKey.getWithSecret",
46 query = "SELECT k"
47 + " FROM MCRAccessKey k"
48 + " WHERE k.secret = :secret AND k.objectId = :objectId"),
49 @NamedQuery(name = "MCRAccessKey.getWithType",
50 query = "SELECT k"
51 + " FROM MCRAccessKey k"
52 + " WHERE k.type = :type AND k.objectId = :objectId"),
53 @NamedQuery(name = "MCRAccessKey.clearWithObjectId",
54 query = "DELETE"
55 + " FROM MCRAccessKey k"
56 + " WHERE k.objectId = :objectId"),
57 @NamedQuery(name = "MCRAccessKey.clear",
58 query = "DELETE"
59 + " FROM MCRAccessKey k"),
60 })
61
62
63
64
65
66
67 @Entity
68 @Table(name = "MCRAccessKey")
69 @JsonInclude(JsonInclude.Include.NON_NULL)
70 public class MCRAccessKey {
71
72 private static final long serialVersionUID = 1L;
73
74
75 private int id;
76
77
78 private MCRObjectID objectId;
79
80
81 private String secret;
82
83
84 private String type;
85
86
87 private Boolean isActive;
88
89
90 private Date expiration;
91
92
93 private String comment;
94
95
96 private Date created;
97
98
99 private String createdBy;
100
101
102 private Date lastModified;
103
104
105 private String lastModifiedBy;
106
107 protected MCRAccessKey() {
108 }
109
110
111
112
113
114
115
116 public MCRAccessKey(final String secret, final String type) {
117 this();
118 setSecret(secret);
119 setType(type);
120 }
121
122
123
124
125 @JsonIgnore
126 @Column(name = "object_id",
127 length = MCRObjectID.MAX_LENGTH,
128 nullable = false)
129 @Convert(converter = MCRObjectIDConverter.class)
130 public MCRObjectID getObjectId() {
131 return objectId;
132 }
133
134
135
136
137 public void setObjectId(final MCRObjectID objectId) {
138 this.objectId = objectId;
139 }
140
141
142
143
144 @JsonIgnore
145 @Id
146 @GeneratedValue(strategy = GenerationType.IDENTITY)
147 @Column(name = "accesskey_id",
148 nullable = false)
149 public int getId() {
150 return id;
151 }
152
153
154
155
156 public void setId(int id) {
157 this.id = id;
158 }
159
160
161
162
163 @Column(name = "secret",
164 nullable = false)
165 public String getSecret() {
166 return secret;
167 }
168
169
170
171
172 public void setSecret(final String secret) {
173 this.secret = secret;
174 }
175
176
177
178
179 @Column(name = "type",
180 nullable = false)
181 public String getType() {
182 return type;
183 }
184
185
186
187
188 public void setType(String type) {
189 this.type = type;
190 }
191
192
193
194
195 @Column(name = "isActive",
196 nullable = false)
197 public Boolean getIsActive() {
198 return isActive;
199 }
200
201
202
203
204 public void setIsActive(final Boolean isActive) {
205 this.isActive = isActive;
206 }
207
208
209
210
211 @Column(name = "expiration")
212 public Date getExpiration() {
213 return expiration;
214 }
215
216
217
218
219 public void setExpiration(final Date expiration) {
220
221 this.expiration = expiration;
222 }
223
224
225
226
227 @Column(name = "comment")
228 public String getComment() {
229 return comment;
230 }
231
232
233
234
235 public void setComment(String comment) {
236 this.comment = comment;
237 }
238
239
240
241
242 @Column(name = "created")
243 public Date getCreated() {
244 return created;
245 }
246
247
248
249
250 public void setCreated(final Date created) {
251 this.created = created;
252 }
253
254
255
256
257 @Column(name = "createdBy")
258 public String getCreatedBy() {
259 return createdBy;
260 }
261
262
263
264
265 public void setCreatedBy(final String createdBy) {
266 this.createdBy = createdBy;
267 }
268
269
270
271
272 @Column(name = "lastModified")
273 public Date getLastModified() {
274 return lastModified;
275 }
276
277
278
279
280 @Column(name = "lastModified")
281 public void setLastModified(final Date lastModified) {
282 this.lastModified = lastModified;
283 }
284
285
286
287
288 @Column(name = "lastModifiedBy")
289 public String getLastModifiedBy() {
290 return lastModifiedBy;
291 }
292
293
294
295
296 public void setLastModifiedBy(final String lastModifiedBy) {
297 this.lastModifiedBy = lastModifiedBy;
298 }
299
300 @Override
301 public boolean equals(Object o) {
302 if (o == this) {
303 return true;
304 }
305 if (!(o instanceof MCRAccessKey)) {
306 return false;
307 }
308 MCRAccessKey other = (MCRAccessKey) o;
309 return this.id == other.getId() && this.type.equals(other.getType())
310 && this.secret.equals(other.getSecret());
311 }
312 }