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.Serializableclass responsible for storing all Right/Role-based information for entities as well as various flags for the containingDetailsinstance. 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 classPermissions.FlagCurrently unused.static classPermissions.Rightenumeration of granted rights.static classPermissions.Roleenumeration of currently active roles.
-
Field Summary
Fields Modifier and Type Field Description static intANNOTATERESTRICTIONstatic intCHGRPRESTRICTIONstatic intCHOWNRESTRICTIONstatic PermissionsCOLLAB_READLINKan immutablePermissionsinstance with read and write permissions for group members.static PermissionsCOLLAB_READONLYan immutablePermissionsinstance with permissions for group members to read other members' data.static intDELETERESTRICTIONstatic PermissionsDUMMYMarker object which can be set on objects to show that the Permissions instance given contains no value.static intEDITRESTRICTIONstatic PermissionsEMPTYan immutablePermissionsinstance with allrightsturned off.static PermissionsGROUP_IMMUTABLER_R___ : user and group can only readstatic PermissionsGROUP_PRIVATERWRW__ : user and group can read and writestatic PermissionsGROUP_READABLERWR___ : user can read and write, group can readstatic PermissionsGROUP_WRITEABLERWRWR_ : user and group can read and write, world can readstatic intLINKRESTRICTIONstatic PermissionsPRIVATEan immutablePermissionsinstance with permissions only for the object owner..static PermissionsPUBLICan immutablePermissionsinstance with allRightsgranted.static PermissionsREAD_ONLYan immutablePermissionsinstance with allPermissions.Right.WRITErights turned off.static PermissionsUSER_IMMUTABLER______ : user and only the user can only readstatic PermissionsUSER_PRIVATERW____ : user and only user can read and writestatic PermissionsUSER_WRITEABLERWR_R_ : all can read, user can writestatic PermissionsWORLD_IMMUTABLER_R_R_ : all can only readstatic PermissionsWORLD_WRITEABLERWRWRW : 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 voidaddExtendedRestrictions(java.util.Set<java.lang.String> extendedRestrictions)static intbit(Permissions.Flag flag)returns the order of the bit representing the givenPermissions.Flag.static intbit(Permissions.Role role, Permissions.Right right)returns the order of the bit representing the givenPermissions.RoleandPermissions.Right.java.lang.String[]copyExtendedRestrictions()Produce a copy of restrictions for use elsewhere.boolean[]copyRestrictions()Deprecated.voidcopyRestrictions(boolean[] source, java.lang.String[] extendedRestrictions)Deprecated.voidcopyRestrictions(int allow, java.util.Set<java.lang.String> extendedRestrictions)Copy restrictions based on the integer returned by BasicACLVoter.voidcopyRestrictions(java.lang.String[] extendedRestrictions)Safely copy the source array.protected longgetPerm1()boolean[]getRestrictions()Permissionsgrant(Permissions.Role role, Permissions.Right... rights)PermissionsgrantAll(Permissions mask)takes a permissions instance and ORs it with the current instance.booleanidentical(Permissions p)twoPermissionsinstances areidenticalif they have the same bit representation.static booleanisDisallow(boolean[] restrictions, int restriction)booleanisDisallowAnnotate()booleanisDisallowChgrp()booleanisDisallowChown()booleanisDisallowDelete()booleanisDisallowEdit()booleanisDisallowLink()booleanisGranted(Permissions.Role role, Permissions.Right right)tests that a givenPermissions.Rolehas the givenPermissions.Right.booleanisSet(Permissions.Flag flag)tests that a givenPermissions.Flagis set.static PermissionsparseString(java.lang.String rwrwrw)Permissionsrevoke(Permissions.Role role, Permissions.Right... rights)PermissionsrevokeAll(Permissions mask)takes a permissions instance and ANDs it with the current instance.booleansameRights(Permissions p)returns true if twoPermissionsinstances have all the samePermissions.Right/Permissions.Rolepairs granted.Permissionsset(Permissions.Flag flag)turn a givenPermissions.Flagon.static voidsetDisallow(boolean[] restrictions, int restriction, boolean disallow)Deprecated.voidsetDisallow(int restriction, boolean disallow)PermissionssetDisallowAnnotate(boolean disallowAnnotate)PermissionssetDisallowChgrp(boolean disallowChgrp)PermissionssetDisallowChown(boolean disallowChown)PermissionssetDisallowDelete(boolean disallowDelete)PermissionssetDisallowEdit(boolean disallowEdit)PermissionssetDisallowLink(boolean disallowLink)protected voidsetPerm1(long value)protected static longsingleBitOn(Permissions.Role role, Permissions.Right right)returns a long with only a single 1 defined by role/rightprotected static longsingleBitOut(Permissions.Role role, Permissions.Right right)returns a long with only a single 0 defined by role/rightjava.lang.StringtoString()produces a String representation of thePermissionssimilar to those on a Unix filesystem.PermissionsunSet(Permissions.Flag flag)turn a givenPermissions.Flagoff.
-
-
-
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 immutablePermissionsinstance with allrightsturned 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 immutablePermissionsinstance with allPermissions.Right.WRITErights turned off. Identical toWORLD_IMMUTABLE
-
PRIVATE
public static final Permissions PRIVATE
an immutablePermissionsinstance with permissions only for the object owner.. Identical toUSER_PRIVATE.- See Also:
- ticket:1434
-
COLLAB_READONLY
public static final Permissions COLLAB_READONLY
an immutablePermissionsinstance 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 immutablePermissionsinstance 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 newPermissionswith the samerightsas the argument.
-
-
Method Detail
-
isGranted
public boolean isGranted(Permissions.Role role, Permissions.Right right)
tests that a givenPermissions.Rolehas the givenPermissions.Right.
-
isSet
public boolean isSet(Permissions.Flag flag)
tests that a givenPermissions.Flagis 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 ofPermissionsand 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.RoleandPermissions.Right. This is dependent on the internal representation ofPermissionsand 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) tosomeEntityfor 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 tosomeEntityfor 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.Flagon. A nullPermissions.Flagwill be ignored.
-
unSet
public Permissions unSet(Permissions.Flag flag)
turn a givenPermissions.Flagoff. A nullPermissions.Flagwill 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 thePermissionssimilar 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 allrightsgranted to all but WORLDroleswould look like: rwrw--- Overrides:
toStringin classjava.lang.Object
-
sameRights
public boolean sameRights(Permissions p)
returns true if twoPermissionsinstances have all the samePermissions.Right/Permissions.Rolepairs granted.
-
identical
public boolean identical(Permissions p)
twoPermissionsinstances areidenticalif 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
-
-