/
IAdmin.java
635 lines (578 loc) · 22.2 KB
/
IAdmin.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
/*
* Copyright 2006-2014 University of Dundee. All rights reserved.
* Use is subject to license terms supplied in LICENSE.txt
*/
package ome.api;
import java.util.List;
import java.util.Map;
import ome.annotations.Hidden;
import ome.annotations.NotNull;
import ome.conditions.AuthenticationException;
import ome.model.IObject;
import ome.model.core.OriginalFile;
import ome.model.internal.Details;
import ome.model.internal.Permissions;
import ome.model.meta.Experimenter;
import ome.model.meta.ExperimenterGroup;
import ome.model.meta.GroupExperimenterMap;
import ome.system.EventContext;
import ome.system.Roles;
/**
* Administration interface providing access to admin-only functionality as well
* as JMX-based server access and selected user functions. Most methods require
* membership in privileged {@link ExperimenterGroup groups}.
*
* Methods which return {@link ome.model.meta.Experimenter} or
* {@link ome.model.meta.ExperimenterGroup} instances fetch and load all related
* instances of {@link ome.model.meta.ExperimenterGroup} or
* {@link ome.model.meta.Experimenter}, respectively.
*
* @author <br>
* Josh Moore <a
* href="mailto:josh.moore@gmx.de"> josh.moore@gmx.de</a>
* @since OME3.0
*/
public interface IAdmin extends ServiceInterface {
/**
* Returns true if the currently logged in user can modify the given
* {@link IObject}. This uses the same logic that would be applied during
* a Hibernate flush to the database.
*/
boolean canUpdate(IObject obj);
// ~ Getting users and groups
// =========================================================================
/**
* fetch an {@link Experimenter} and all related
* {@link ExperimenterGroup groups}.
*
* @param id
* id of the Experimenter
* @return an Experimenter. Never null.
* @throws ome.conditions.ApiUsageException
* if id does not exist.
*/
Experimenter getExperimenter(long id);
/**
* look up an {@link Experimenter} and all related
* {@link ExperimenterGroup groups} by name.
*
* @param omeName
* Name of the Experimenter
* @return an Experimenter. Never null.
* @throws ome.conditions.ApiUsageException
* if omeName does not exist.
*/
Experimenter lookupExperimenter(@NotNull
String omeName);
/**
* Looks up all {@link Experimenter experimenters} present and all related
* {@link ExperimenterGroup groups}.
*
* @return all Experimenters. Never null.
*/
List<Experimenter> lookupExperimenters();
/**
* Looks up all id of {@link Experimenter experimenters} who uses LDAP
* authentication (has set dn on password table).
*
* @return list of Experimenters. Never null.
*/
List<Map<String, Object>> lookupLdapAuthExperimenters();
/**
* Looks up {@link Experimenter experimenters} who uses LDAP authentication
* (has set dn on password table).
*
* @return Experimenter. Never null.
*/
String lookupLdapAuthExperimenter(long id);
/**
* fetch an {@link ExperimenterGroup} and all contained
* {@link Experimenter users}.
*
* @param id
* id of the ExperimenterGroup
* @return an ExperimenterGroup. Never null.
* @throws ome.conditions.ApiUsageException
* if id does not exist.
*/
ExperimenterGroup getGroup(long id);
/**
* look up an {@link ExperimenterGroup} and all contained
* {@link Experimenter users} by name.
*
* @param groupName
* Name of the ExperimenterGroup
* @return an ExperimenterGroup. Never null.
* @throws ome.conditions.ApiUsageException
* if groupName does not exist.
*/
ExperimenterGroup lookupGroup(@NotNull
String groupName);
/**
* Looks up all {@link ExperimenterGroup groups} present and all related
* {@link Experimenter experimenters}. The experimenters' groups are also
* loaded.
*
* @return all Groups. Never null.
*/
List<ExperimenterGroup> lookupGroups();
/**
* fetch all {@link Experimenter users} contained in this group. The
* returned users will have all fields filled in and all collections
* unloaded.
*
* @param groupId
* id of the ExperimenterGroup
* @return non-null array of all {@link Experimenter users} in this group.
*/
Experimenter[] containedExperimenters(long groupId);
/**
* fetch all {@link ExperimenterGroup groups} of which the given user is a
* member. The returned groups will have all fields filled in and all
* collections unloaded.
*
* @param experimenterId
* id of the Experimenter. Not null.
* @return non-null array of all {@link ExperimenterGroup groups} for this
* user.
*/
ExperimenterGroup[] containedGroups(long experimenterId);
/**
* retrieve the default {@link ExperimenterGroup group} for the given user
* id.
*
* @param experimenterId
* of the Experimenter. Not null.
* @return non-null {@link ExperimenterGroup}. If no default group is
* found, an exception will be thrown.
*/
ExperimenterGroup getDefaultGroup(long experimenterId);
/**
* Finds the ids for all groups for which the given {@link Experimenter} is
* owner/leader.
*
* @param e
* Non-null, managed (i.e. with id) {@link Experimenter}
* @see ExperimenterGroup#getDetails()
* @see Details#getOwner()
*/
List<Long> getLeaderOfGroupIds(Experimenter e);
/**
* Finds the ids for all groups for which the given {@link Experimenter} is
* a member.
*
* @param e
* Non-null, managed (i.e. with id) {@link Experimenter}
* @see ExperimenterGroup#getDetails()
* @see Details#getOwner()
*/
List<Long> getMemberOfGroupIds(Experimenter e);
// ~ Updating users and groups
// =========================================================================
/**
* Allows a user to update his/her own information. This is limited to the
* fields on Experimenter, all other fields (groups, etc.) are ignored. The
* experimenter argument need not have the proper id nor the proper omeName
* (which is immutable). To change the users default group (which is the
* only other customizable option), use
* {@link #setDefaultGroup(Experimenter, ExperimenterGroup)}
*
* @see #setDefaultGroup(Experimenter, ExperimenterGroup)
* @param experimenter
* A data transfer object. Only the fields: firstName,
* middleName, lastName, email, and institution are checked. Not
* null.
*/
void updateSelf(@NotNull
Experimenter experimenter);
/**
* Uploads a photo for the user which will be displayed on his/her profile.
* This photo will be saved as an {@link ome.model.core.OriginalFile} object
* with the given format, and attached to the user's {@link Experimenter}
* object via an {@link ome.model.annotations.FileAnnotation} with
* the namespace: "openmicroscopy.org/omero/experimenter/photo" (NSEXPERIMENTERPHOTO).
* If such an {@link ome.model.core.OriginalFile} instance already exists,
* it will be overwritten. If more than one photo is present, the oldest
* version will be modified (i.e. the highest updateEvent id).
*
* Note: as outlined in ticket:1794, this photo will be placed in the "user"
* group and therefore will be visible to everyone on the system.
*
* @param filename Not null. String name which will be used.
* @param format Not null. Format.value string. 'image/jpeg' and 'image/png' are common values.
* @param data Not null. Data from the image. This will be written to disk.
* @return the id of the overwritten or newly created user photo OriginalFile object.
*/
long uploadMyUserPhoto(String filename, String format, byte[] data);
/**
* Retrieve the {@link ome.model.core.OriginalFile} object attached to this
* user as specified by {@link #uploadMyUserPhoto(String, String, byte[])}.
* The return value is order by the most recently modified file first.
*
* @return file objects. Possibly empty.
*/
List<OriginalFile> getMyUserPhotos();
/**
* Updates an experimenter if admin or owner of group. Only string fields on
* the object are taken into account.
* The root and guest experimenters may not be renamed.
*
* Before a SecurityViolation would be thrown, however, this method will
* pass to {@link #updateSelf(Experimenter)} <em>if</em> the current user
* matches the given experimenter.
*
* @param experimenter
* the Experimenter to update.
*/
void updateExperimenter(@NotNull
Experimenter experimenter);
/**
* Updates an experimenter if admin or owner of group.
* Only string fields on the object are taken into account.
* The root and guest experimenters may not be renamed.
*
* @param experimenter
* the Experimenter to update.
* @param password
* Not-null. Must pass validation in the security sub-system.
*/
void updateExperimenterWithPassword(@NotNull
Experimenter experimenter, @Hidden
String password);
/**
* Updates an experimenter group if admin or owner of group.
* Only string fields on the object are taken into account.
* The root, system and guest groups may not be renamed,
* nor may the user's current group.
*
* @param group
* the ExperimenterGroup to update.
*/
void updateGroup(@NotNull
ExperimenterGroup group);
// ~ Creating users in groups
// =========================================================================
/**
* create and return a new user. This user will be created with the default
* group specified.
*
* @param newUser
* a new {@link Experimenter} instance
* @param group group name of the default group for this user
* @return id of the newly created {@link Experimenter}
*/
long createUser(@NotNull
Experimenter newUser, @NotNull
String group);
/**
* create and return a new system user. This user will be created with the
* "System" (administration) group as default and will also be in the "user"
* group.
*
* @param newSystemUser a new {@link Experimenter} instance
* @return id of the newly created {@link Experimenter}
*/
long createSystemUser(@NotNull
Experimenter newSystemUser);
/**
* create and return a new user in the given groups.
*
* @param experimenter
* A new {@link Experimenter} instance. Not null.
* @param defaultGroup
* Instance of {@link ExperimenterGroup}. Not null.
* @param otherGroups
* Array of {@link ExperimenterGroup} instances. Can be null.
* @return id of the newly created {@link Experimenter} Not null.
*/
long createExperimenter(@NotNull
Experimenter experimenter, @NotNull
ExperimenterGroup defaultGroup, ExperimenterGroup... otherGroups);
/**
* create and return a new user in the given groups with password.
*
* @param experimenter
* A new {@link Experimenter} instance. Not null.
* @param password
* Not-null. Must pass validation in the security sub-system.
* @param defaultGroup
* Instance of {@link ExperimenterGroup}. Not null.
* @param otherGroups
* Array of {@link ExperimenterGroup} instances. Can be null.
* @return id of the newly created {@link Experimenter} Not null.
* @throws ome.conditions.SecurityViolation
* if the new password is too weak.
*/
long createExperimenterWithPassword(@NotNull
Experimenter experimenter, @Hidden
String password, @NotNull
ExperimenterGroup defaultGroup, ExperimenterGroup... otherGroups);
/**
* create and return a new group. The {@link Details#setPermissions(Permissions)}
* method should be called on the instance which is passed. The given
* {@link Permissions} will become the default for all objects created while
* logged into this group, possibly modified by the user's umask settings.
* If no permissions is set, the default will be {@link Permissions#USER_PRIVATE},
* i.e. a group in which no user can see the other group member's data.
*
* @param group a new {@link ExperimenterGroup} instance. Not null.
* @return id of the newly created {@link ExperimenterGroup}
* @see <a href="http://trac.openmicroscopy.org.uk/ome/ticket/1434">ticket:1434"</a>
*/
long createGroup(ExperimenterGroup group);
/**
* adds a user to the given groups.
*
* @param user
* A currently managed entity. Not null.
* @param groups
* Groups to which the user will be added. Not null.
*/
void addGroups(@NotNull
Experimenter user, @NotNull
ExperimenterGroup... groups);
/**
* Removes an experimenter from the given groups.
* <ul>
* <li>The root experimenter is required to be in both the user and system groups.</li>
* <li>An experimenter may not remove themself from the user or system group.</li>
* <li>An experimenter may not be a member of only the user group,
* some other group is also required as the default group.</li>
* <li>An experimenter must remain a member of some group.</li>
* </ul>
*
* @param user
* A currently managed entity. Not null.
* @param groups
* Groups from which the user will be removed. Not null.
*/
void removeGroups(@NotNull
Experimenter user, @NotNull
ExperimenterGroup... groups);
/**
* sets the default group for a given user.
*
* @param user
* A currently managed {@link Experimenter}. Not null.
* @param group
* The group which should be set as default group for this user.
* Not null.
*/
void setDefaultGroup(@NotNull
Experimenter user, @NotNull
ExperimenterGroup group);
/**
* adds the user to the owner list for this group.
*
* Since Beta4.2 (ticket:1434) multiple users can be the "owner" of a group.
*
* @param group
* A currently managed {@link ExperimenterGroup}. Not null.
* @param owner
* A currently managed {@link Experimenter}. Not null.
*/
void setGroupOwner(@NotNull
ExperimenterGroup group, @NotNull
Experimenter owner);
/**
* removes the user from the owner list for this group.
*
* Since Beta4.2 (ticket:1434) multiple users can be the "owner" of a group.
*
* @param group
* A currently managed {@link ExperimenterGroup}. Not null.
* @param owner
* A currently managed {@link Experimenter}. Not null.
*/
void unsetGroupOwner(@NotNull
ExperimenterGroup group, @NotNull
Experimenter owner);
/**
* adds the given users to the owner list for this group.
*
* @param group
* A currently managed {@link ExperimenterGroup}. Not null.
* @param owner
* A set of currently managed {@link Experimenter}s. Not null.
*/
void addGroupOwners(@NotNull
ExperimenterGroup group, @NotNull
Experimenter... owner);
/**
* removes the given users from the owner list for this group.
*
* @param group
* A currently managed {@link ExperimenterGroup}. Not null.
* @param owner
* A set of currently managed {@link Experimenter}s. Not null.
*/
void removeGroupOwners(@NotNull
ExperimenterGroup group, @NotNull
Experimenter... owner);
/**
* removes a user by removing the password information for that user as well
* as all {@link GroupExperimenterMap} instances.
*
* @param user
* Experimenter to be deleted. Not null.
*/
void deleteExperimenter(@NotNull
Experimenter user);
/**
* removes a group by first removing all users in the group, and then
* deleting the actual {@link ExperimenterGroup} instance.
*
* @param group
* {@link ExperimenterGroup} to be deleted. Not null.
*/
void deleteGroup(@NotNull
ExperimenterGroup group);
// ~ Permissions and Ownership
// =========================================================================
/**
* call
* {@link ome.model.internal.Details#setOwner(Experimenter) details.setOwner()}
* on this instance. It is valid for the instance to be
* {@link IObject#unload() unloaded} (or constructed with an
* unloading-constructor.)
*
* @param iObject
* An entity or an unloaded reference to an entity. Not null.
* @param omeName
* The user name who should gain ownership of this entity. Not
* null.
*/
void changeOwner(@NotNull
IObject iObject, @NotNull
String omeName);
/**
* call
* {@link ome.model.internal.Details#setGroup(ExperimenterGroup) details.setGroup()}
* on this instance. It is valid for the instance to be
* {@link IObject#unload() unloaded} (or constructed with an
* unloading-constructor.)
*
* @param iObject
* An entity or an unloaded reference to an entity. Not null.
* @param groupName
* The group name who should gain ownership of this entity. Not
* null.
*/
void changeGroup(@NotNull
IObject iObject, @NotNull
String groupName);
/**
* call
* {@link ome.model.internal.Details#setPermissions(Permissions) defaults.setPermissions()}
* on this instance. It is valid for the instance to be
* {@link IObject#unload() unloaded} (or constructed with an
* unloading-constructor.)
*
* @param iObject
* An entity or an unloaded reference to an entity. Not null.
* @param perms
* The permissions value for this entity. Not null.
*/
void changePermissions(@NotNull
IObject iObject, @NotNull
Permissions perms);
/**
* Moves the given objects into the "user" group to make them visible
* and linkable from all security contexts.
*
* @param iObjects
* @see <a href="https://trac.openmicroscopy.org/ome/ticket/1794">ticket 1794</a>
*/
void moveToCommonSpace(IObject... iObjects);
// ~ Authentication and Authorization
// =========================================================================
/**
* Can be used after repeated {@link AuthenticationException} instances are
* thrown, to request that an email with a temporary password be sent. The
* given email must match the email for the user listed under the name
* argument.
*
* Does not require a session to be active.
*
* @param name
* @param email
* @throws AuthenticationException
* when name and email do not match
* @deprecated
*/
@Deprecated
void reportForgottenPassword(String name, String email)
throws AuthenticationException;
/**
* Used after an {@link ome.conditions.ExpiredCredentialException} instance is thrown.
*
* Does not require
*/
void changeExpiredCredentials(String name, String oldCred, String newCred)
throws AuthenticationException;
/**
* change the password for the current user.
* <p>
* <em>Warning:</em>This method requires the user to be authenticated
* with a password and not with a one-time session id. To avoid this
* problem, use {@link #changePasswordWithOldPassword(String, String)}.
* </p>
*
* @param newPassword
* Possibly null to allow logging in with no password.
* @throws ome.conditions.SecurityViolation
* if the user is not authenticated with a password.
* @see <a href="http://trac.openmicroscopy.org.uk/ome/ticket/911">ticket:911</a>
* @see <a href="http://trac.openmicroscopy.org.uk/ome/ticket/3201">ticket:3201</a>
*/
void changePassword(@Hidden
String newPassword);
/**
* change the password for the current user by passing the old password.
*
* @param oldPassword
* Not-null. Must pass validation in the security sub-system.
* @param newPassword
* Possibly null to allow logging in with no password.
* @throws ome.conditions.SecurityViolation
* if the oldPassword is incorrect.
*/
void changePasswordWithOldPassword(
@Hidden @NotNull String oldPassword,
@Hidden String newPassword);
/**
* change the password for the a given user.
*
* @param newPassword
* Not-null. Might must pass validation in the security
* sub-system.
* @throws ome.conditions.SecurityViolation
* if the new password is too weak.
*/
void changeUserPassword(@NotNull
String omeName, @Hidden
String newPassword);
/**
* uses JMX to refresh the login cache <em>if supported</em>. Some
* backends may not provide refreshing. This may be called internally during
* some other administrative tasks. The exact implementation of this depends
* on the application server and the authentication/authorization backend.
*/
void synchronizeLoginCache();
// ~ Security context
// =========================================================================
/**
* returns the active {@link Roles} in use by the server.
*
* @return Non-null, immutable {@link Roles} instance.
*/
Roles getSecurityRoles();
/**
* returns an implementation of {@link EventContext} loaded with the
* security for the current user and thread. If called remotely, not all
* values of {@link EventContext} will be sensible.
*
* @return Non-null, immutable {@link EventContext} instance
*/
EventContext getEventContext();
}