Package ome.model.internal
Class Permissions
- java.lang.Object
-
- ome.model.internal.Permissions
-
- All Implemented Interfaces:
java.io.Serializable
public class Permissions extends java.lang.Object implements java.io.Serializable
class responsible for storing all Right/Role-based information for entities as well as various flags for the containingDetails
instance. It is strongly encouraged to not base any code on the implementation of the rights, roles, and flag but rather to rely on the public methods.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.
- See Also:
- ticket:180, Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Permissions.Flag
Currently unused.static class
Permissions.Right
enumeration of granted rights.static class
Permissions.Role
enumeration of currently active roles.
-
Field Summary
Fields Modifier and Type Field Description static int
ANNOTATERESTRICTION
static int
CHGRPRESTRICTION
static int
CHOWNRESTRICTION
static Permissions
COLLAB_READLINK
an immutablePermissions
instance with read and write permissions for group members.static Permissions
COLLAB_READONLY
an immutablePermissions
instance with permissions for group members to read other members' data.static int
DELETERESTRICTION
static Permissions
DUMMY
Marker object which can be set on objects to show that the Permissions instance given contains no value.static int
EDITRESTRICTION
static Permissions
EMPTY
an immutablePermissions
instance with allrights
turned off.static Permissions
GROUP_IMMUTABLE
R_R___ : user and group can only readstatic Permissions
GROUP_PRIVATE
RWRW__ : user and group can read and writestatic Permissions
GROUP_READABLE
RWR___ : user can read and write, group can readstatic Permissions
GROUP_WRITEABLE
RWRWR_ : user and group can read and write, world can readstatic int
LINKRESTRICTION
static Permissions
PRIVATE
an immutablePermissions
instance with permissions only for the object owner..static Permissions
PUBLIC
an immutablePermissions
instance with allRights
granted.static Permissions
READ_ONLY
an immutablePermissions
instance with allPermissions.Right.WRITE
rights turned off.static Permissions
USER_IMMUTABLE
R______ : user and only the user can only readstatic Permissions
USER_PRIVATE
RW____ : user and only user can read and writestatic Permissions
USER_WRITEABLE
RWR_R_ : all can read, user can writestatic Permissions
WORLD_IMMUTABLE
R_R_R_ : all can only readstatic Permissions
WORLD_WRITEABLE
RWRWRW : everyone can read and write
-
Constructor Summary
Constructors Constructor Description Permissions()
simple constructor.Permissions(Permissions p)
copy constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addExtendedRestrictions(java.util.Set<java.lang.String> extendedRestrictions)
static int
bit(Permissions.Flag flag)
returns the order of the bit representing the givenPermissions.Flag
.static int
bit(Permissions.Role role, Permissions.Right right)
returns the order of the bit representing the givenPermissions.Role
andPermissions.Right
.java.lang.String[]
copyExtendedRestrictions()
Produce a copy of restrictions for use elsewhere.boolean[]
copyRestrictions()
Deprecated.void
copyRestrictions(boolean[] source, java.lang.String[] extendedRestrictions)
Deprecated.void
copyRestrictions(int allow, java.util.Set<java.lang.String> extendedRestrictions)
Copy restrictions based on the integer returned by BasicACLVoter.void
copyRestrictions(java.lang.String[] extendedRestrictions)
Safely copy the source array.protected long
getPerm1()
boolean[]
getRestrictions()
Permissions
grant(Permissions.Role role, Permissions.Right... rights)
Permissions
grantAll(Permissions mask)
takes a permissions instance and ORs it with the current instance.boolean
identical(Permissions p)
twoPermissions
instances areidentical
if they have the same bit representation.static boolean
isDisallow(boolean[] restrictions, int restriction)
boolean
isDisallowAnnotate()
boolean
isDisallowChgrp()
boolean
isDisallowChown()
boolean
isDisallowDelete()
boolean
isDisallowEdit()
boolean
isDisallowLink()
boolean
isGranted(Permissions.Role role, Permissions.Right right)
tests that a givenPermissions.Role
has the givenPermissions.Right
.boolean
isSet(Permissions.Flag flag)
tests that a givenPermissions.Flag
is set.static Permissions
parseString(java.lang.String rwrwrw)
Permissions
revoke(Permissions.Role role, Permissions.Right... rights)
Permissions
revokeAll(Permissions mask)
takes a permissions instance and ANDs it with the current instance.boolean
sameRights(Permissions p)
returns true if twoPermissions
instances have all the samePermissions.Right
/Permissions.Role
pairs granted.Permissions
set(Permissions.Flag flag)
turn a givenPermissions.Flag
on.static void
setDisallow(boolean[] restrictions, int restriction, boolean disallow)
Deprecated.void
setDisallow(int restriction, boolean disallow)
Permissions
setDisallowAnnotate(boolean disallowAnnotate)
Permissions
setDisallowChgrp(boolean disallowChgrp)
Permissions
setDisallowChown(boolean disallowChown)
Permissions
setDisallowDelete(boolean disallowDelete)
Permissions
setDisallowEdit(boolean disallowEdit)
Permissions
setDisallowLink(boolean disallowLink)
protected void
setPerm1(long value)
protected static long
singleBitOn(Permissions.Role role, Permissions.Right right)
returns a long with only a single 1 defined by role/rightprotected static long
singleBitOut(Permissions.Role role, Permissions.Right right)
returns a long with only a single 0 defined by role/rightjava.lang.String
toString()
produces a String representation of thePermissions
similar to those on a Unix filesystem.Permissions
unSet(Permissions.Flag flag)
turn a givenPermissions.Flag
off.
-
-
-
Field Detail
-
LINKRESTRICTION
public static final int LINKRESTRICTION
- See Also:
- Constant Field Values
-
EDITRESTRICTION
public static final int EDITRESTRICTION
- See Also:
- Constant Field Values
-
DELETERESTRICTION
public static final int DELETERESTRICTION
- See Also:
- Constant Field Values
-
ANNOTATERESTRICTION
public static final int ANNOTATERESTRICTION
- See Also:
- Constant Field Values
-
CHGRPRESTRICTION
public static final int CHGRPRESTRICTION
- See Also:
- Constant Field Values
-
CHOWNRESTRICTION
public static final int CHOWNRESTRICTION
- See Also:
- Constant Field Values
-
EMPTY
public static final Permissions EMPTY
an immutablePermissions
instance with allrights
turned off.
-
DUMMY
public static final Permissions DUMMY
Marker object which can be set on objects to show that the Permissions instance given contains no value.
-
USER_IMMUTABLE
public static final Permissions USER_IMMUTABLE
R______ : user and only the user can only read
-
USER_PRIVATE
public static final Permissions USER_PRIVATE
RW____ : user and only user can read and write
-
GROUP_READABLE
public static final Permissions GROUP_READABLE
RWR___ : user can read and write, group can read
-
GROUP_PRIVATE
public static final Permissions GROUP_PRIVATE
RWRW__ : user and group can read and write
-
GROUP_WRITEABLE
public static final Permissions GROUP_WRITEABLE
RWRWR_ : user and group can read and write, world can read
-
WORLD_WRITEABLE
public static final Permissions WORLD_WRITEABLE
RWRWRW : everyone can read and write
-
USER_WRITEABLE
public static final Permissions USER_WRITEABLE
RWR_R_ : all can read, user can write
-
WORLD_IMMUTABLE
public static final Permissions WORLD_IMMUTABLE
R_R_R_ : all can only read
-
GROUP_IMMUTABLE
public static final Permissions GROUP_IMMUTABLE
R_R___ : user and group can only read
-
READ_ONLY
public static final Permissions READ_ONLY
an immutablePermissions
instance with allPermissions.Right.WRITE
rights turned off. Identical toWORLD_IMMUTABLE
-
PRIVATE
public static final Permissions PRIVATE
an immutablePermissions
instance with permissions only for the object owner.. Identical toUSER_PRIVATE
.- See Also:
- ticket:1434
-
COLLAB_READONLY
public static final Permissions COLLAB_READONLY
an immutablePermissions
instance with permissions for group members to read other members' data. Identical toGROUP_READABLE
.- See Also:
- ticket:1434, ticket:1992
-
COLLAB_READLINK
public static final Permissions COLLAB_READLINK
an immutablePermissions
instance with read and write permissions for group members. Identical toGROUP_PRIVATE
.- See Also:
- ticket:1434, ticket:1992
-
PUBLIC
public static final Permissions PUBLIC
-
-
Constructor Detail
-
Permissions
public Permissions()
-
Permissions
public Permissions(Permissions p)
copy constructor. Will create a newPermissions
with the samerights
as the argument.
-
-
Method Detail
-
isGranted
public boolean isGranted(Permissions.Role role, Permissions.Right right)
tests that a givenPermissions.Role
has the givenPermissions.Right
.
-
isSet
public boolean isSet(Permissions.Flag flag)
tests that a givenPermissions.Flag
is set.
-
bit
public static int bit(Permissions.Flag flag)
returns the order of the bit representing the givenPermissions.Flag
. This is dependent on the internal representation ofPermissions
and should only be used when necessary.
-
bit
public static int bit(Permissions.Role role, Permissions.Right right)
returns the order of the bit representing the givenPermissions.Role
andPermissions.Right
. This is dependent on the internal representation ofPermissions
and should only be used when necessary.
-
parseString
public static Permissions parseString(java.lang.String rwrwrw)
-
isDisallow
public static boolean isDisallow(boolean[] restrictions, int restriction)
-
isDisallowAnnotate
public boolean isDisallowAnnotate()
-
isDisallowChgrp
public boolean isDisallowChgrp()
-
isDisallowChown
public boolean isDisallowChown()
-
isDisallowDelete
public boolean isDisallowDelete()
-
isDisallowEdit
public boolean isDisallowEdit()
-
isDisallowLink
public boolean isDisallowLink()
-
addExtendedRestrictions
public void addExtendedRestrictions(java.util.Set<java.lang.String> extendedRestrictions)
-
getRestrictions
public boolean[] getRestrictions()
-
copyRestrictions
@Deprecated public boolean[] copyRestrictions()
Deprecated.Produce a copy of restrictions for use elsewhere.
-
copyExtendedRestrictions
public java.lang.String[] copyExtendedRestrictions()
Produce a copy of restrictions for use elsewhere.
-
copyRestrictions
public void copyRestrictions(java.lang.String[] extendedRestrictions)
Safely copy the source array.
-
copyRestrictions
@Deprecated public void copyRestrictions(boolean[] source, java.lang.String[] extendedRestrictions)
Deprecated.Safely copy the source array. If it is null or contains no "true" values, then the restrictions field will remain null.
-
copyRestrictions
public void copyRestrictions(int allow, java.util.Set<java.lang.String> extendedRestrictions)
Copy restrictions based on the integer returned by BasicACLVoter.
-
grant
public Permissions grant(Permissions.Role role, Permissions.Right... rights)
-
revoke
public Permissions revoke(Permissions.Role role, Permissions.Right... rights)
-
grantAll
public Permissions grantAll(Permissions mask)
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,Permissions mask = new Permissions().grant(WORLD,READ); someEntity.getDetails().getPermissions().grantAllk(mask);
will allow READ access (and possibly more) tosomeEntity
for members of WORLD.
-
revokeAll
public Permissions revokeAll(Permissions mask)
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,Permissions mask = new Permissions().revoke(WORLD,READ,WRITE,USE); someEntity.getDetails().getPermissions().applyMask(mask);
will disallow all access tosomeEntity
for members of WORLD. This also implies that applyMask can be used to make copies of Permissions. For example,new Permissions().applyMask( somePermissions );
will produce a copy ofsomePermissions
. Note: the logic here is different from Unix UMASKS.
-
set
public Permissions set(Permissions.Flag flag)
turn a givenPermissions.Flag
on. A nullPermissions.Flag
will be ignored.
-
unSet
public Permissions unSet(Permissions.Flag flag)
turn a givenPermissions.Flag
off. A nullPermissions.Flag
will be ignored.
-
setDisallow
@Deprecated public static void setDisallow(boolean[] restrictions, int restriction, boolean disallow)
Deprecated.
-
setDisallow
public void setDisallow(int restriction, boolean disallow)
-
setDisallowAnnotate
public Permissions setDisallowAnnotate(boolean disallowAnnotate)
-
setDisallowChgrp
public Permissions setDisallowChgrp(boolean disallowChgrp)
-
setDisallowChown
public Permissions setDisallowChown(boolean disallowChown)
-
setDisallowDelete
public Permissions setDisallowDelete(boolean disallowDelete)
-
setDisallowEdit
public Permissions setDisallowEdit(boolean disallowEdit)
-
setDisallowLink
public Permissions setDisallowLink(boolean disallowLink)
-
toString
public java.lang.String toString()
produces a String representation of thePermissions
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 allrights
granted to all but WORLDroles
would look like: rwrw--- Overrides:
toString
in classjava.lang.Object
-
sameRights
public boolean sameRights(Permissions p)
returns true if twoPermissions
instances have all the samePermissions.Right
/Permissions.Role
pairs granted.
-
identical
public boolean identical(Permissions p)
twoPermissions
instances areidentical
if they have the same bit representation.- See Also:
- ticket:291
-
getPerm1
protected long getPerm1()
-
setPerm1
protected void setPerm1(long value)
-
singleBitOut
protected static final long singleBitOut(Permissions.Role role, Permissions.Right right)
returns a long with only a single 0 defined by role/right
-
singleBitOn
protected static final long singleBitOn(Permissions.Role role, Permissions.Right right)
returns a long with only a single 1 defined by role/right
-
-