public final class Acl
extends java.lang.Object
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.
Modifier and Type | Field and Description |
---|---|
static int |
ADD
Principals holding this permission can issue ADD commands on the node
having this ACL.
|
static int |
ALL_PERMISSION
Principals holding this permission can issue any command on the node
having this ACL.
|
private static java.lang.String |
ALL_PRINCIPALS |
static int |
DELETE
Principals holding this permission can issue DELETE commands on the node
having this ACL.
|
static int |
EXEC
Principals holding this permission can issue EXEC commands on the node
having this ACL.
|
static int |
GET
Principals holding this permission can issue GET command on the node
having this ACL.
|
private int |
globalPermissions |
private static int[] |
PERMISSION_CODES |
private static java.lang.String[] |
PERMISSION_NAMES |
private java.util.TreeMap |
principalPermissions |
static int |
REPLACE
Principals holding this permission can issue REPLACE commands on the node
having this ACL.
|
Modifier | Constructor and Description |
---|---|
private |
Acl(Acl base,
java.lang.String principal,
int permissions)
Creates an instance identical to the
base ACL except for
the permissions of the given principal , which are
overwritten with the given permissions . |
|
Acl(java.lang.String acl)
Create an instance of the ACL from its canonic string representation.
|
|
Acl(java.lang.String[] principals,
int[] permissions)
Creates an instance with a specified list of principals and the
permissions they hold.
|
Modifier and Type | Method and Description |
---|---|
Acl |
addPermission(java.lang.String principal,
int permissions)
Create a new
Acl instance from this Acl with
the given permission added for the given principal. |
private static java.lang.String |
appendEntry(java.lang.String base,
char separator,
java.lang.String entry) |
private static void |
checkPermissions(int perm) |
private static void |
checkPrincipal(java.lang.String principal) |
private static void |
checkServerId(java.lang.String serverId,
java.lang.String errorText) |
private static void |
deleteFromAll(java.util.TreeMap principalPermissions,
int perm) |
Acl |
deletePermission(java.lang.String principal,
int permissions)
Create a new
Acl instance from this Acl with
the given permission revoked from the given principal. |
boolean |
equals(java.lang.Object obj)
Checks whether the given object is equal to this
Acl
instance. |
int |
getPermissions(java.lang.String principal)
Get the permissions associated to a given principal.
|
java.lang.String[] |
getPrincipals()
Get the list of principals who have any kind of permissions on this node.
|
int |
hashcode()
Returns the hash code for this ACL instance.
|
boolean |
isPermitted(java.lang.String principal,
int permissions)
Check whether the given permissions are granted to a certain principal.
|
private static int |
parseCommand(java.lang.String command) |
Acl |
setPermission(java.lang.String principal,
int permissions)
Create a new
Acl instance from this Acl where
all permissions for the given principal are overwritten with the given
permissions. |
private static void |
setPrincipalPermission(java.util.TreeMap principalPermissions,
java.lang.String principal,
int perm) |
private static java.lang.String[] |
split(java.lang.String input,
char sep,
int limit) |
java.lang.String |
toString()
Give the canonic string representation of this ACL.
|
private static java.lang.String |
writeCommands(int command) |
private java.lang.String |
writeEntry(int command,
java.lang.String acl) |
public static final int GET
public static final int ADD
public static final int REPLACE
public static final int DELETE
public static final int EXEC
public static final int ALL_PERMISSION
ADD
,
DELETE
, EXEC
, GET
and REPLACE
permissions.private static final int[] PERMISSION_CODES
private static final java.lang.String[] PERMISSION_NAMES
private static final java.lang.String ALL_PRINCIPALS
private final java.util.TreeMap principalPermissions
private final int globalPermissions
public Acl(java.lang.String acl)
acl
- The string representation of the ACL as defined in OMA DM. If
null
or empty then it represents an empty list of
principals with no permissions.java.lang.IllegalArgumentException
- if acl is not a valid OMA DM ACL stringpublic Acl(java.lang.String[] principals, int[] permissions)
principals[i]
will hold permissions[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).
principals
- The array of principalspermissions
- The array of permissionsjava.lang.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 the principals
arrayprivate Acl(Acl base, java.lang.String principal, int permissions)
base
ACL except for
the permissions of the given principal
, which are
overwritten with the given permissions
.
Assumes that the permissions parameter has been checked. All
modifications of an Acl
(add, delete, set) are done
through this method.
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 logical or
of the permission constants defined
in this class.public boolean equals(java.lang.Object obj)
Acl
instance. Two Acl
instances are equal if they allow the
same set of permissions for the same set of principals.equals
in class java.lang.Object
obj
- the object to compare with this Acl
instancetrue
if the parameter represents the same ACL as
this instancepublic int hashcode()
Acl
instances are equal according to the equals(java.lang.Object)
method, then calling
this method on each of them must produce the same integer result.public Acl addPermission(java.lang.String principal, int permissions)
Acl
instance from this Acl
with
the given permission added for the given principal. The already existing
permissions of the principal are not affected.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
logical or
of more permission constants defined in
this class.Acl
instancejava.lang.IllegalArgumentException
- if principal
is not a
valid principal name or if permissions
is not a
valid combination of the permission constants defined in this
classpublic Acl deletePermission(java.lang.String principal, int permissions)
Acl
instance from this Acl
with
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.
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
logical or
of more permission constants defined in
this class.Acl
instancejava.lang.IllegalArgumentException
- if principal
is not a
valid principal name, if permissions
is 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 principalpublic int getPermissions(java.lang.String principal)
principal
- The entity whose permissions to query, or "*"
to query the permissions that are granted globally, to all
principalsint
is a bitmask of the permission constants defined
in this classjava.lang.IllegalArgumentException
- if principal
is not a
valid principal namepublic boolean isPermitted(java.lang.String principal, int permissions)
(Acl.ADD | Acl.DELETE | Acl.GET)
.principal
- The entity to check, or "*" to check whether
the given permissions are granted to all principals globallypermissions
- The permissions to checktrue
if the principal holds all the given permissionsjava.lang.IllegalArgumentException
- if principal
is not a
valid principal name or if permissions
is not a
valid combination of the permission constants defined in this
classpublic Acl setPermission(java.lang.String principal, int permissions)
Acl
instance from this Acl
where
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).
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.Acl
instancejava.lang.IllegalArgumentException
- if principal
is not a
valid principal name, if permissions
is 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 principalpublic java.lang.String[] getPrincipals()
public java.lang.String toString()
toString
in class java.lang.Object
private java.lang.String writeEntry(int command, java.lang.String acl)
private static void deleteFromAll(java.util.TreeMap principalPermissions, int perm)
private static void setPrincipalPermission(java.util.TreeMap principalPermissions, java.lang.String principal, int perm)
private static java.lang.String writeCommands(int command)
private static java.lang.String appendEntry(java.lang.String base, char separator, java.lang.String entry)
private static int parseCommand(java.lang.String command)
private static void checkPermissions(int perm)
private static void checkPrincipal(java.lang.String principal)
private static void checkServerId(java.lang.String serverId, java.lang.String errorText)
private static java.lang.String[] split(java.lang.String input, char sep, int limit)