/
Permissions.java
899 lines (776 loc) · 29.1 KB
/
Permissions.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
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
/*
* Copyright (C) 2006-2012 University of Dundee
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package ome.model.internal;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Transient;
import ome.conditions.ApiUsageException;
import ome.model.IObject;
import static ome.model.internal.Permissions.Role.*;
import static ome.model.internal.Permissions.Right.*;
import static ome.model.internal.Permissions.Flag.*;
/**
* class responsible for storing all Right/Role-based information for entities
* as well as various flags for the containing {@link Details} instance. It is
* strongly encouraged to <em>not</em> base any code on the implementation of
* the rights, roles, and flag but rather to rely on the public methods.
* <p>
* In the future, further roles, rights, and flags may be added to this class.
* This will change the representation in the database, but the simple
* grant/revoke/isSet logic will remain the same.
* </p>
*
* @see <a
* href="http://trac.openmicroscopy.org.uk/ome/ticket/180">ticket:180</a>
*/
public class Permissions implements Serializable {
private static final long serialVersionUID = 708953452345658023L;
/**
* enumeration of currently active roles. The {@link #USER} role is active
* when the contents of {@link Details#getOwner()} equals the current user
* as determined from the Security system (Server-side only). Similary, the
* {@link #GROUP} role is active when the contents of
* {@link Details#getGroup()} matches the current group. {@link #WORLD} is
* used for any non-USER, non-GROUP user.
*
* For more advanced, ACL, methods taking
* {@link ome.model.meta.Experimenter} references can be implemented.
*/
public enum Role {
USER(8), GROUP(4), WORLD(0);
private final int shift;
Role(int shift) {
this.shift = shift;
}
int shift() {
return this.shift;
}
}
/**
* enumeration of granted rights. The {@link #READ} right allows for a user
* with the given role to retrieve an entity. This means that all fields of
* that entity can be retrieved. Care is taken by the server, that once an
* entity was readable and another entity was attached to it, that further
* READ access will not throw an exception. In turn,
* care should be taken by users to not overly soon grant {@link #READ}
* permissions lest they no longer be revokable. As of 4.4, this also permits
* certain view-based linkages of objects (e.g. RenderingDef, Thumbnail).
*
* The {@link #ANNOTATE} right allows a user with the given role to link
* annotations and other non-core data to an entity.
*
* The {@link #WRITE} right allows for a user with the given role to alter
* the fields of an entity, including changing the contents of its
* collection, assigning it to another collection, or deleting it.
* This does not include changing the fields of those linked
* entities, only whether or not they are members of the given collection.
*
* Note: if WRITE is granted, ANNOTATE will also be granted.
*/
public enum Right {
ANNOTATE(1), WRITE(2), READ(4);
private final int mask;
Right(int mask) {
this.mask = mask;
}
int mask() {
return this.mask;
}
}
/**
* Currently unused.
*/
public enum Flag {
UNUSED(1 << 19);
/*
* Implementation note: -------------------- Flags work with reverse
* logic such that the default permissions can remain -1L (all 1s), a
* flag is "set" when it's bit is set to 0. This holds for everything
* over 16.
*/
private final int bit;
Flag(int bit) {
this.bit = bit;
}
int bit() {
return this.bit;
}
}
// ~ Constructors
// =========================================================================
/**
* simple contructor. Will turn on all {@link Right rights} for all
* {@link Role roles}
*/
public Permissions() {
}
/**
* copy constructor. Will create a new {@link Permissions} with the same
* {@link Right rights} as the argument.
*/
public Permissions(Permissions p) {
if (p == null) {
throw new IllegalArgumentException(
"Permissions argument cannot be null.");
}
if (p == DUMMY) {
throw new IllegalArgumentException("No valid permissions available! DUMMY permissions are not intended for copying. " +
"Make sure that you have not passed omero.group=-1 for a save without context");
}
this.revokeAll(p);
copyRestrictions(p.restrictions);
}
// ~ Fields
// =========================================================================
/**
* represents the lower 64-bits of permissions data.
*/
private long perm1 = -1; // all bits turned on.
// These are duplicated in Constants.ice
public static final int LINKRESTRICTION = 0;
public static final int EDITRESTRICTION = 1;
public static final int DELETERESTRICTION = 2;
public static final int ANNOTATERESTRICTION = 3;
/**
* Calculated restrictions which are based on both the store
* representation({@link #perm1}) and the current calling context.
*/
private boolean[] restrictions;
// ~ Getters
// =========================================================================
/** tests that a given {@link Role} has the given {@link Right}. */
public boolean isGranted(Role role, Right right) {
return (perm1 & right.mask() << role.shift()) == right.mask() << role
.shift();
}
/** tests that a given {@link Flag} is set. */
public boolean isSet(Flag flag) {
return (perm1 & flag.bit()) != flag.bit();
}
/**
* returns the order of the bit representing the given {@link Flag}. This
* is dependent on the internal representation of {@link Permission} and
* should only be used when necessary.
*
* @see ome.tools.hibernate.SecurityFilter
*/
public static int bit(Flag flag) {
return flag.bit();
}
/**
* returns the order of the bit representing the given {@link Role} and
* {@link Right}. This is dependent on the internal representation of
* {@link Permissions} and should only be used when necessary.
*
* @see ome.tools.hibernate.SecurityFilter
*/
public static int bit(Role role, Right right) {
return right.mask() << role.shift();
}
public static Permissions parseString(String rwrwrw) {
Permissions p = new Permissions(EMPTY);
String regex = "([Rr_-][AaWw_-]){3}";
if (rwrwrw == null || !rwrwrw.matches(regex)) {
throw new ApiUsageException("Permissions are of the form: " + regex);
}
char c;
c = rwrwrw.charAt(0);
if (c == 'r' || c == 'R') {
p.grant(USER, READ);
}
c = rwrwrw.charAt(1);
if (c == 'a' || c == 'A') {
p.grant(USER, ANNOTATE);
} else if (c == 'w' || c == 'W') {
p.grant(USER, ANNOTATE);
p.grant(USER, WRITE);
}
c = rwrwrw.charAt(2);
if (c == 'r' || c == 'R') {
p.grant(GROUP, READ);
}
c = rwrwrw.charAt(3);
if (c == 'a' || c == 'A') {
p.grant(GROUP, ANNOTATE);
} else if (c == 'w' || c == 'W') {
p.grant(GROUP, ANNOTATE);
p.grant(GROUP, WRITE);
}
c = rwrwrw.charAt(4);
if (c == 'r' || c == 'R') {
p.grant(WORLD, READ);
}
c = rwrwrw.charAt(5);
if (c == 'a' || c == 'A') {
p.grant(WORLD, ANNOTATE);
} else if (c == 'w' || c == 'W') {
p.grant(WORLD, ANNOTATE);
p.grant(WORLD, WRITE);
}
return p;
}
public static boolean isDisallow(final boolean[] restrictions, final int restriction) {
if (restrictions != null && restrictions.length > restriction) {
return restrictions[restriction];
}
return false;
}
@Transient
public boolean isDisallowAnnotate() {
return isDisallow(restrictions, ANNOTATERESTRICTION);
}
@Transient
public boolean isDisallowDelete() {
return isDisallow(restrictions, DELETERESTRICTION);
}
@Transient
public boolean isDisallowEdit() {
return isDisallow(restrictions, EDITRESTRICTION);
}
@Transient
public boolean isDisallowLink() {
return isDisallow(restrictions, LINKRESTRICTION);
}
/**
* Produce a copy of restrictions for use elsewhere.
*/
public boolean[] copyRestrictions() {
if (restrictions == null) {
return null;
}
boolean[] copy = new boolean[restrictions.length];
System.arraycopy(restrictions, 0, copy, 0, restrictions.length);
return copy;
}
/**
* Safely copy the source array. If it is null or contains no "true" values,
* then the restrictions field will remain null.
*/
public void copyRestrictions(final boolean[] source) {
if (noTrues(source)) {
this.restrictions = null;
} else {
if (restrictions == null || source.length != restrictions.length) {
restrictions = new boolean[source.length];
}
System.arraycopy(source, 0, restrictions, 0, source.length);
}
}
/**
* Copy restrictions based on the integer returned by BasicACLVoter.
*/
public void copyRestrictions(int allow) {
if (allow == 15) { // Would be all false.
this.restrictions = null;
return;
}
if (restrictions == null) {
this.restrictions = new boolean[4]; // All false
}
this.restrictions[LINKRESTRICTION] |= (0 == (allow & (1 << LINKRESTRICTION)));
this.restrictions[EDITRESTRICTION] |= (0 == (allow & (1 << EDITRESTRICTION)));
this.restrictions[DELETERESTRICTION] |= (0 == (allow & (1 << DELETERESTRICTION)));
this.restrictions[ANNOTATERESTRICTION] |= (0 == (allow & (1 << ANNOTATERESTRICTION)));
}
private static boolean noTrues(boolean[] source) {
if (source == null) {
return true;
}
for (int i = 0; i < source.length; i++) {
if (source[i]) {
return false;
}
}
return true;
}
// ~ Setters (return this)
// =========================================================================
/**
* turns on the {@link Right rights} for the given {@link Role role}. Null
* or empty rights are simply ignored. For example, <code>
* somePermissions().grant(USER,READ,WRITE,USE);
* </code> will guarantee
* that the current user has all rights on this entity.
*/
public Permissions grant(Role role, Right... rights) {
if (rights != null && rights.length > 0) {
for (Right right : rights) {
perm1 = perm1 | singleBitOn(role, right);
}
}
return this;
}
/**
* turns off the {@link Right rights} for the given {@link Role role}. Null
* or empty rights are simply ignored. For example, <code>
* new Permissions().revoke(WORLD,WRITE,USE);
* </code> will return a
* Permissions instance which cannot be altered or linked to by members of
* WORLD.
*/
public Permissions revoke(Role role, Right... rights) {
if (rights != null && rights.length > 0) {
for (Right right : rights) {
perm1 = perm1 & singleBitOut(role, right);
}
}
return this;
}
/**
* takes a permissions instance and ORs it with the current instance. This
* means that any privileges which have been granted to the argument will
* also be granted to the current instance. For example, <code>
* Permissions mask = new Permissions().grant(WORLD,READ);
* someEntity.getDetails().getPermissions().grantAllk(mask);
* </code> will allow READ access (and possibly more) to
* <code>someEntity</code> for members of WORLD.
*/
public Permissions grantAll(Permissions mask) {
if (mask == null) {
return this;
}
long maskPerm1 = mask.getPerm1();
this.perm1 = this.perm1 | maskPerm1;
return this;
}
/**
* takes a permissions instance and ANDs it with the current instance. This
* means that any privileges which have been revoked from the argument will
* also be revoked from the current instance. For example, <code>
* Permissions mask = new Permissions().revoke(WORLD,READ,WRITE,USE);
* someEntity.getDetails().getPermissions().applyMask(mask);
* </code> will disallow all access to <code>someEntity</code> for members
* of WORLD.
*
* This also implies that applyMask can be used to make copies of
* Permissions. For example, <code>
* new Permissions().applyMask( somePermissions );
* </code> will produce a copy of
* <code>somePermissions</code>.
*
* Note: the logic here is different from Unix UMASKS.
*/
public Permissions revokeAll(Permissions mask) {
if (mask == null) {
return this;
}
long maskPerm1 = mask.getPerm1();
this.perm1 = this.perm1 & maskPerm1;
return this;
}
/** turn a given {@link Flag} on. A null {@link Flag} will be ignored. */
public Permissions set(Flag flag) {
if (flag == null) {
return this;
}
this.perm1 &= -1L ^ flag.bit();
return this;
}
/** turn a given {@link Flag} off. A null {@link Flag} will be ignored. */
public Permissions unSet(Flag flag) {
if (flag == null) {
return this;
}
this.perm1 |= 0L ^ flag.bit();
return this;
}
public static void setDisallow(boolean[] restrictions,
int restriction, boolean disallow) {
// The array is already long enough, just set the value
if (restrictions != null && restrictions.length >= restriction) {
restrictions[restriction] = disallow;
} else {
// if !disallow, then we won't need to set anything,
// since the default value will be false.
if (disallow) {
boolean[] copy = new boolean[restriction+1];
if (restrictions != null) {
System.arraycopy(restrictions, 0, copy, 0, restrictions.length);
}
copy[restriction] = disallow; // i.e. true
restrictions = copy;
}
}
}
public Permissions setDisallowAnnotate(boolean disallowAnnotate) {
setDisallow(restrictions, ANNOTATERESTRICTION, disallowAnnotate);
return this;
}
public Permissions setDisallowDelete(boolean disallowDelete) {
setDisallow(restrictions, DELETERESTRICTION, disallowDelete);
return this;
}
public Permissions setDisallowEdit(boolean disallowEdit) {
setDisallow(restrictions, EDITRESTRICTION, disallowEdit);
return this;
}
public Permissions setDisallowLink(boolean disallowLink) {
setDisallow(restrictions, LINKRESTRICTION, disallowLink);
return this;
}
// ~ Overrides
// =========================================================================
/**
* produces a String representation of the {@link Permissions} similar to
* those on a Unix filesystem. Unset bits are represented by a dash, while
* other bits are represented by a symbolic value in the correct bit
* position. For example, a Permissions with all {@link Right rights}
* granted to all but WORLD {@link Role roles} would look like: rwrw--
*/
@Override
public String toString() {
StringBuilder sb = new StringBuilder(16);
sb.append(isGranted(USER, READ) ? "r" : "-");
sb.append(annotateOrWorld(USER));
sb.append(isGranted(GROUP, READ) ? "r" : "-");
sb.append(annotateOrWorld(GROUP));
sb.append(isGranted(WORLD, READ) ? "r" : "-");
sb.append(annotateOrWorld(WORLD));
return sb.toString();
}
private String annotateOrWorld(Role role) {
if (isGranted(role, WRITE)) {
return "w";
} else if (isGranted(role, ANNOTATE)) {
return "a";
} else {
return "-";
}
}
/**
* returns true if two {@link Permissions} instances have all the same
* {@link Right} / {@link Role} pairs granted.
*/
public boolean sameRights(Permissions p) {
if (p == this) {
return true;
}
for (Role ro : Role.values()) {
for (Right rt : Right.values()) {
if (isGranted(ro, rt) != p.isGranted(ro, rt)) {
return false;
}
}
}
return true;
}
/**
* two {@link Permissions} instances are <code>identical</code> if they have
* the same bit representation.
*
* @see <a
* href="http://trac.openmicroscopy.org.uk/ome/ticket/291">ticket:291</a>
*/
// @Override
public boolean identical(Permissions p) {
// if (!(obj instanceof Permissions)) return false;
//
// Permissions p = (Permissions) obj;
if (p == this) {
return true;
}
if (p.perm1 == this.perm1) {
return true;
}
return false;
}
// /** hashCode based on the bit representation of this {@link Permissions}
// * instance.
// */
// @Override
// public int hashCode() {
// int result = 11;
// result = 17 * result + (int)(perm1^(perm1>>>32));
// return result;
// }
// ~ Property accessors : used primarily by Hibernate
// =========================================================================
@Column(name = "permissions", nullable = false, updatable = false)
protected long getPerm1() {
return this.perm1;
}
protected void setPerm1(long value) {
this.perm1 = value;
}
// ~ Helpers
// =========================================================================
/** returns a long with only a single 0 defined by role/right */
final protected static long singleBitOut(Role role, Right right) {
return -1L ^ right.mask() << role.shift();
}
/** returns a long with only a single 1 defined by role/right */
final protected static long singleBitOn(Role role, Right right) {
return 0L | right.mask() << role.shift();
}
/**
* an immutable wrapper around {@link Permission} instances so that commonly
* used permissions can be made available as public final static constants.
*/
private static class ImmutablePermissions extends Permissions implements
Serializable {
private static final long serialVersionUID = -4407900270934589522L;
/**
* Factory method to create an immutable Permissions object.
*/
public static Permissions immutable(Permissions p) {
return new ImmutablePermissions(p);
}
/**
* the delegate {@link Permissions} which this immutable wrapper bases
* all of its logic on. Not final for reasons of serialization.
*/
private Permissions delegate;
/**
* the sole constructor for an {@link ImmutablePermissions}. Note: this
* does not behave like {@link Permissions#Permissions(Permissions)} --
* the copy constructor. Rather stores the {@link Permissions} instance
* for delegation
*
* @param p
* Non-null {@link Permissions} instance.
*/
ImmutablePermissions(Permissions p) {
if (p == null) {
throw new IllegalArgumentException(
"Permissions may not be null");
}
this.delegate = new Permissions(p);
}
// ~ SETTERS
// =====================================================================
/**
* throws {@link UnsupportedOperationException}
*/
@Override
public Permissions grant(Role role, Right... rights) {
throw new UnsupportedOperationException();
}
/**
* throws {@link UnsupportedOperationException}
*/
@Override
public Permissions revoke(Role role, Right... rights) {
throw new UnsupportedOperationException();
}
/**
* throws {@link UnsupportedOperationException}
*/
@Override
public Permissions grantAll(Permissions mask) {
throw new UnsupportedOperationException();
}
/**
* throws {@link UnsupportedOperationException}
*/
@Override
public Permissions revokeAll(Permissions mask) {
throw new UnsupportedOperationException();
}
/**
* delegates to {@link #set(ome.model.internal.Permissions.Flag)}
*/
@Override
public Permissions set(Flag flag) {
return delegate.set(flag);
}
/**
* delegates to {@link #unSet(ome.model.internal.Permissions.Flag)}
*/
@Override
public Permissions unSet(Flag flag) {
return delegate.unSet(flag);
}
// ~ GETTERS
// =========================================================================
/**
* delegates to {@link #delegate}
*/
@Override
public boolean isGranted(Role role, Right right) {
return delegate.isGranted(role, right);
}
/**
* delegates to {@link #delegate}
*/
@Override
protected long getPerm1() {
return delegate.getPerm1();
}
/**
* delegates to {@link #delegate}
*/
@Override
protected void setPerm1(long value) {
delegate.setPerm1(value);
}
/**
* delegates to {@link #isSet(ome.model.internal.Permissions.Flag)}
*/
@Override
public boolean isSet(Flag flag) {
return delegate.isSet(flag);
}
// ~ Other
// =====================================================================
/**
* delegates to {@link #identical(Permissions)}
*/
@Override
public boolean identical(Permissions p) {
return delegate.identical(p);
}
/**
* delegates to {@link #sameRights(Permissions)}
*/
@Override
public boolean sameRights(Permissions p) {
return delegate.sameRights(p);
}
/**
* delegates to {@link #toString()}
*/
@Override
public String toString() {
return delegate.toString();
}
// ~ Serialization
// =====================================================================
private void readObject(ObjectInputStream s) throws IOException,
ClassNotFoundException {
Permissions p = (Permissions) s.readObject();
if (p == null) {
throw new IllegalArgumentException(
"Permissions may not be null");
}
this.delegate = new Permissions(p);
}
private void writeObject(ObjectOutputStream s) throws IOException {
s.writeObject(delegate);
}
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// NOTE: when rights or roles change, the definition of EMPTY needs to
// be kept in sync.
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/**
* an immutable {@link Permissions} instance with all {@link Right rights}
* turned off.
*/
public final static Permissions EMPTY = new ImmutablePermissions(
new Permissions().revoke(USER, READ, ANNOTATE, WRITE).revoke(GROUP, READ,
ANNOTATE, WRITE).revoke(WORLD, READ, ANNOTATE, WRITE));
/**
* Marker object which can be set on objects to show that the Permissions
* instance given contains no value.
*/
public final static Permissions DUMMY = new ImmutablePermissions(EMPTY);
// ~ Systematic
// =========================================================================
/*
* All possible (sensible) permission combinations are:
*
* R_____ user immutable RW____ user private RWR___ group readable RWRW__
* group private RWRWR_ group writeable RWRWRW world writeable RWR_R_ user
* writeable R_R_R_ world immutable R_R___ group immutable
*/
/**
* R______ : user and only the user can only read
*/
public final static Permissions USER_IMMUTABLE = new ImmutablePermissions(
new Permissions(EMPTY).grant(USER, READ));
/**
* RW____ : user and only user can read and write
*/
public final static Permissions USER_PRIVATE = new ImmutablePermissions(
new Permissions(EMPTY).grant(USER, READ, ANNOTATE, WRITE));
/**
* RWR___ : user can read and write, group can read
*/
public final static Permissions GROUP_READABLE = new ImmutablePermissions(
new Permissions(USER_PRIVATE).grant(GROUP, READ));
/**
* RWRW__ : user and group can read and write
*/
public final static Permissions GROUP_PRIVATE = new ImmutablePermissions(
new Permissions(GROUP_READABLE).grant(GROUP, ANNOTATE, WRITE));
/**
* RWRWR_ : user and group can read and write, world can read
*/
public final static Permissions GROUP_WRITEABLE = new ImmutablePermissions(
new Permissions(GROUP_PRIVATE).grant(WORLD, READ));
/**
* RWRWRW : everyone can read and write
*/
public final static Permissions WORLD_WRITEABLE = new ImmutablePermissions(
new Permissions(GROUP_WRITEABLE).grant(WORLD, ANNOTATE, WRITE));
/**
* RWR_R_ : all can read, user can write
*/
public final static Permissions USER_WRITEABLE = new ImmutablePermissions(
new Permissions(GROUP_READABLE).grant(WORLD, READ));
/**
* R_R_R_ : all can only read
*/
public final static Permissions WORLD_IMMUTABLE = new ImmutablePermissions(
new Permissions(USER_WRITEABLE).revoke(USER, ANNOTATE, WRITE));
/**
* R_R___ : user and group can only read
*/
public final static Permissions GROUP_IMMUTABLE = new ImmutablePermissions(
new Permissions(WORLD_IMMUTABLE).revoke(WORLD, READ));
// ~ Non-systematic (easy to remember)
// =========================================================================
/**
* an immutable {@link Permissions} instance with all {@link Right#WRITE}
* rights turned off. Identical to {@link #WORLD_IMMUTABLE}
*/
public final static Permissions READ_ONLY = WORLD_IMMUTABLE;
/**
* an immutable {@link Permissions} instance with permissions only for the
* object owner.. Identical to {@link #USER_PRIVATE}.
*
* @see <a href="http://trac.openmicroscopy.org.uk/ome/ticket/1434">ticket:1434</a>
*/
public final static Permissions PRIVATE = USER_PRIVATE;
/**
* an immutable {@link Permissions} instance with permissions for group
* members to read other members' data. Identical to
* {@link #GROUP_READABLE}.
*
* @see <a href="http://trac.openmicroscopy.org.uk/ome/ticket/1434">ticket:1434</a>
* @see <a href="http://trac.openmicroscopy.org.uk/ome/ticket/1992">ticket:1992</a>
*/
public final static Permissions COLLAB_READONLY = GROUP_READABLE;
/**
* an immutable {@link Permissions} instance with read and write permissions
* for group members. Identical to {@link #GROUP_PRIVATE}.
*
* @see <a href="http://trac.openmicroscopy.org.uk/ome/ticket/1434">ticket:1434</a>
* @see <a href="http://trac.openmicroscopy.org.uk/ome/ticket/1992">ticket:1992</a>
*/
public final static Permissions COLLAB_READLINK = GROUP_PRIVATE;
/**
* an immutable {@link Permissions} instance with all {@link Right Rights}
* granted. Identical to {@link #WORLD_WRITEABLE}
*/
public final static Permissions PUBLIC = WORLD_WRITEABLE;
}