Class Acl
Acl is an immutable class representing structured access to DMT ACLs.
Under OMA DM the ACLs are defined as strings with an internal syntax.
The methods of this class taking a principal as parameter accept remote
server IDs (as passed to DmtAdmin.getSession), as well as " * " indicating any
principal.
The syntax for valid remote server IDs:
<server-identifier> ::= All printable characters except
'=', '&', '*', '+' or white-space characters.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intPrincipals holding this permission can issue ADD commands on the node having this ACL.static final intPrincipals holding this permission can issue any command on the node having this ACL.private static final Stringstatic final intPrincipals holding this permission can issue DELETE commands on the node having this ACL.static final intPrincipals holding this permission can issue EXEC commands on the node having this ACL.static final intPrincipals holding this permission can issue GET command on the node having this ACL.private final intprivate static final int[]private static final String[]static final intPrincipals holding this permission can issue REPLACE commands on the node having this ACL. -
Constructor Summary
ConstructorsModifierConstructorDescriptionCreate an instance of the ACL from its canonical string representation.Creates an instance with a specified list of principals and the permissions they hold.privateCreates an instance identical to thebaseACL except for the permissions of the givenprincipal, which are overwritten with the givenpermissions. -
Method Summary
Modifier and TypeMethodDescriptionaddPermission(String principal, int permissions) Create a newAclinstance from thisAclwith the given permission added for the given principal.private static StringappendEntry(String base, char separator, String entry) private static voidcheckPermissions(int perm) private static voidcheckPrincipal(String principal) private static voidcheckServerId(String serverId, String errorText) private static voiddeleteFromAll(TreeMap<String, Integer> principalPermissions, int perm) deletePermission(String principal, int permissions) Create a newAclinstance from thisAclwith the given permission revoked from the given principal.booleanChecks whether the given object is equal to thisAclinstance.intgetPermissions(String principal) Get the permissions associated to a given principal.String[]Get the list of principals who have any kind of permissions on this node.inthashCode()Returns the hash code for this ACL instance.booleanisPermitted(String principal, int permissions) Check whether the given permissions are granted to a certain principal.private static intparseCommand(String command) setPermission(String principal, int permissions) Create a newAclinstance from thisAclwhere all permissions for the given principal are overwritten with the given permissions.private static voidsetPrincipalPermission(TreeMap<String, Integer> principalPermissions, String principal, int perm) private static String[]toString()Give the canonical string representation of this ACL.private static StringwriteCommands(int command) private StringwriteEntry(int command, String acl)
-
Field Details
-
GET
public static final int GETPrincipals holding this permission can issue GET command on the node having this ACL.- See Also:
-
ADD
public static final int ADDPrincipals holding this permission can issue ADD commands on the node having this ACL.- See Also:
-
REPLACE
public static final int REPLACEPrincipals holding this permission can issue REPLACE commands on the node having this ACL.- See Also:
-
DELETE
public static final int DELETEPrincipals holding this permission can issue DELETE commands on the node having this ACL.- See Also:
-
EXEC
public static final int EXECPrincipals holding this permission can issue EXEC commands on the node having this ACL.- See Also:
-
ALL_PERMISSION
public static final int ALL_PERMISSIONPrincipals holding this permission can issue any command on the node having this ACL. This permission is the logical OR ofADD,DELETE,EXEC,GETandREPLACEpermissions.- See Also:
-
PERMISSION_CODES
private static final int[] PERMISSION_CODES -
PERMISSION_NAMES
-
ALL_PRINCIPALS
- See Also:
-
principalPermissions
-
globalPermissions
private final int globalPermissions
-
-
Constructor Details
-
Acl
Create an instance of the ACL from its canonical string representation.- Parameters:
acl- The string representation of the ACL as defined in OMA DM. Ifnullor empty then it represents an empty list of principals with no permissions.- Throws:
IllegalArgumentException- if acl is not a valid OMA DM ACL string
-
Acl
Creates an instance with a specified list of principals and the permissions they hold. The two arrays run in parallel, that isprincipals[i]will holdpermissions[i]in the ACL.A principal name may not appear multiple times in the 'principals' argument. If the "*" principal appears in the array, the corresponding permissions will be granted to all principals (regardless of whether they appear in the array or not).
- Parameters:
principals- The array of principalspermissions- The array of permissions- Throws:
IllegalArgumentException- if the length of the two arrays are not the same, if any array element is invalid, or if a principal appears multiple times in theprincipalsarray
-
Acl
Creates an instance identical to thebaseACL except for the permissions of the givenprincipal, which are overwritten with the givenpermissions.Assumes that the permissions parameter has been checked. All modifications of an
Acl(add, delete, set) are done through this method.- Parameters:
base- The ACL that provides all permissions except for permissions of the given principal.principal- The entity to which permission should be granted.permissions- The set of permissions to be given. The parameter can be a logicalorof the permission constants defined in this class.
-
-
Method Details
-
equals
Checks whether the given object is equal to thisAclinstance. TwoAclinstances are equal if they allow the same set of permissions for the same set of principals. -
hashCode
public int hashCode()Returns the hash code for this ACL instance. If twoAclinstances are equal according to theequals(Object)method, then calling this method on each of them must produce the same integer result. -
addPermission
Create a newAclinstance from thisAclwith the given permission added for the given principal. The already existing permissions of the principal are not affected.- Parameters:
principal- The entity to which permissions should be granted, or "*" to grant permissions to all principals.permissions- The permissions to be given. The parameter can be a logicalorof more permission constants defined in this class.- Returns:
- a new
Aclinstance - Throws:
IllegalArgumentException- ifprincipalis not a valid principal name or ifpermissionsis not a valid combination of the permission constants defined in this class
-
deletePermission
Create a newAclinstance from thisAclwith the given permission revoked from the given principal. Other permissions of the principal are not affected.Note, that it is not valid to revoke a permission from a specific principal if that permission is granted globally to all principals.
- Parameters:
principal- The entity from which permissions should be revoked, or "*" to revoke permissions from all principals.permissions- The permissions to be revoked. The parameter can be a logicalorof more permission constants defined in this class.- Returns:
- a new
Aclinstance - Throws:
IllegalArgumentException- ifprincipalis not a valid principal name, ifpermissionsis not a valid combination of the permission constants defined in this class, or if a globally granted permission would have been revoked from a specific principal
-
getPermissions
Get the permissions associated to a given principal.- Parameters:
principal- The entity whose permissions to query, or "*" to query the permissions that are granted globally, to all principals- Returns:
- The permissions of the given principal. The returned
intis a bitmask of the permission constants defined in this class - Throws:
IllegalArgumentException- ifprincipalis not a valid principal name
-
isPermitted
Check whether the given permissions are granted to a certain principal. The requested permissions are specified as a bitfield, for example(Acl.ADD | Acl.DELETE | Acl.GET).- Parameters:
principal- The entity to check, or "*" to check whether the given permissions are granted to all principals globallypermissions- The permissions to check- Returns:
trueif the principal holds all the given permissions- Throws:
IllegalArgumentException- ifprincipalis not a valid principal name or ifpermissionsis not a valid combination of the permission constants defined in this class
-
setPermission
Create a newAclinstance from thisAclwhere all permissions for the given principal are overwritten with the given permissions.Note, that when changing the permissions of a specific principal, it is not allowed to specify a set of permissions stricter than the global set of permissions (that apply to all principals).
- Parameters:
principal- The entity to which permissions should be granted, or "*" to globally grant permissions to all principals.permissions- The set of permissions to be given. The parameter is a bitmask of the permission constants defined in this class.- Returns:
- a new
Aclinstance - Throws:
IllegalArgumentException- ifprincipalis not a valid principal name, ifpermissionsis not a valid combination of the permission constants defined in this class, or if a globally granted permission would have been revoked from a specific principal
-
getPrincipals
Get the list of principals who have any kind of permissions on this node. The list only includes those principals that have been explicitly assigned permissions (so "*" is never returned), globally set permissions naturally apply to all other principals as well.- Returns:
- The array of principals having permissions on this node.
-
toString
Give the canonical string representation of this ACL. The operations are in the following order: {Add, Delete, Exec, Get, Replace}, principal names are sorted alphabetically. -
writeEntry
-
deleteFromAll
-
setPrincipalPermission
-
writeCommands
-
appendEntry
-
parseCommand
-
checkPermissions
private static void checkPermissions(int perm) -
checkPrincipal
-
checkServerId
-
split
-