Top Description Fields Constructors Methods
org.osgi.service.dmt

public final Class Acl

extends Object
Class Inheritance
Imports
java.util.ArrayList, .Arrays, .Iterator, .List, .Map, .Map.Entry, .TreeMap

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.

Author
$Id: c58d6f55ec211830489505001946db4b73c9bfdd $

Field Summary

Modifier and TypeField and Description
public static final int
ADD

Principals holding this permission can issue ADD commands on the node having this ACL.

public static final int
ALL_PERMISSION

Principals holding this permission can issue any command on the node having this ACL.

private static final String
public static final int
DELETE

Principals holding this permission can issue DELETE commands on the node having this ACL.

public static final int
EXEC

Principals holding this permission can issue EXEC commands on the node having this ACL.

public static final int
GET

Principals holding this permission can issue GET command on the node having this ACL.

private final int
private static final int[]
private static final String[]
private final TreeMap<String, Integer>
public static final int
REPLACE

Principals holding this permission can issue REPLACE commands on the node having this ACL.

Constructor Summary

AccessConstructor and Description
public
Acl(String
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.
acl
)

Create an instance of the ACL from its canonical string representation.

public
Acl(String[]
The array of principals
principals
,
int[]
The array of permissions
permissions
)

Creates an instance with a specified list of principals and the permissions they hold.

private
Acl(Acl
The ACL that provides all permissions except for permissions of the given principal.
base
,
String
The entity to which permission should be granted.
principal
,
int
The set of permissions to be given. The parameter can be a logical or of the permission constants defined in this class.
permissions
)

Creates an instance identical to the base ACL except for the permissions of the given principal, which are overwritten with the given permissions.

Method Summary

Modifier and TypeMethod and Description
public synchronized Acl

Returns:

a new Acl instance
addPermission
(String
The entity to which permissions should be granted, or "*" to grant permissions to all principals.
principal
,
int
The permissions to be given. The parameter can be a logical or of more permission constants defined in this class.
permissions
)

Create a new Acl instance from this Acl with the given permission added for the given principal.

private static String
appendEntry(String base, char separator, String entry)

private static void
checkPermissions(int perm)

private static void
private static void
checkServerId(String serverId, String errorText)

private static void
deleteFromAll(TreeMap<String, Integer> principalPermissions, int perm)

public synchronized Acl

Returns:

a new Acl instance
deletePermission
(String
The entity from which permissions should be revoked, or "*" to revoke permissions from all principals.
principal
,
int
The permissions to be revoked. The parameter can be a logical or of more permission constants defined in this class.
permissions
)

Create a new Acl instance from this Acl with the given permission revoked from the given principal.

public boolean

Returns:

true if the parameter represents the same ACL as this instance
equals
(Object
the object to compare with this Acl instance
obj
)

Overrides java.lang.Object.equals.

Checks whether the given object is equal to this Acl instance.

public synchronized int

Returns:

The permissions of the given principal. The returned int is a bitmask of the permission constants defined in this class
getPermissions
(String
The entity whose permissions to query, or "*" to query the permissions that are granted globally, to all principals
principal
)

Get the permissions associated to a given principal.

public String[]

Returns:

The array of principals having permissions on this node.
getPrincipals
()

Get the list of principals who have any kind of permissions on this node.

public int

Returns:

hash code for this ACL
hashCode
()

Overrides java.lang.Object.hashCode.

Returns the hash code for this ACL instance.

public synchronized boolean

Returns:

true if the principal holds all the given permissions
isPermitted
(String
The entity to check, or "*" to check whether the given permissions are granted to all principals globally
principal
,
int
The permissions to check
permissions
)

Check whether the given permissions are granted to a certain principal.

private static int
public synchronized Acl

Returns:

a new Acl instance
setPermission
(String
The entity to which permissions should be granted, or "*" to globally grant permissions to all principals.
principal
,
int
The set of permissions to be given. The parameter is a bitmask of the permission constants defined in this class.
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(TreeMap<String, Integer> principalPermissions, String principal, int perm)

private static String[]
split(String input, char sep, int limit)

public synchronized String

Returns:

The string representation as defined in OMA DM.
toString
()

Overrides java.lang.Object.toString.

Give the canonical string representation of this ACL.

private static String
writeCommands(int command)

private String
writeEntry(int command, String acl)

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

ADDback to summary
public static final int ADD

Principals holding this permission can issue ADD commands on the node having this ACL.

ALL_PERMISSIONback to summary
public static final int ALL_PERMISSION

Principals holding this permission can issue any command on the node having this ACL. This permission is the logical OR of ADD, DELETE, EXEC, GET and REPLACE permissions.

ALL_PRINCIPALSback to summary
private static final String ALL_PRINCIPALS
DELETEback to summary
public static final int DELETE

Principals holding this permission can issue DELETE commands on the node having this ACL.

EXECback to summary
public static final int EXEC

Principals holding this permission can issue EXEC commands on the node having this ACL.

GETback to summary
public static final int GET

Principals holding this permission can issue GET command on the node having this ACL.

globalPermissionsback to summary
private final int globalPermissions
PERMISSION_CODESback to summary
private static final int[] PERMISSION_CODES
PERMISSION_NAMESback to summary
private static final String[] PERMISSION_NAMES
principalPermissionsback to summary
private final TreeMap<String, Integer> principalPermissions
REPLACEback to summary
public static final int REPLACE

Principals holding this permission can issue REPLACE commands on the node having this ACL.

Constructor Detail

Aclback to summary
public Acl(String acl)

Create an instance of the ACL from its canonical string representation.

Parameters
acl:String

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.

Exceptions
IllegalArgumentException:
if acl is not a valid OMA DM ACL string
Aclback to summary
public Acl(String[] principals, int[] permissions)

Creates an instance with a specified list of principals and the permissions they hold. The two arrays run in parallel, that is 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).

Parameters
principals:String[]

The array of principals

permissions:int[]

The array of permissions

Exceptions
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 array
Aclback to summary
private Acl(Acl base, 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.

Assumes that the permissions parameter has been checked. All modifications of an Acl (add, delete, set) are done through this method.

Parameters
base:Acl

The ACL that provides all permissions except for permissions of the given principal.

principal:String

The entity to which permission should be granted.

permissions:int

The set of permissions to be given. The parameter can be a logical or of the permission constants defined in this class.

Method Detail

addPermissionback to summary
public synchronized Acl addPermission(String principal, int permissions)

Create a new Acl instance from this Acl with the given permission added for the given principal. The already existing permissions of the principal are not affected.

Parameters
principal:String

The entity to which permissions should be granted, or "*" to grant permissions to all principals.

permissions:int

The permissions to be given. The parameter can be a logical or of more permission constants defined in this class.

Returns:Acl

a new Acl instance

Exceptions
IllegalArgumentException:
if principal is not a valid principal name or if permissions is not a valid combination of the permission constants defined in this class
appendEntryback to summary
private static String appendEntry(String base, char separator, String entry)
checkPermissionsback to summary
private static void checkPermissions(int perm)
checkPrincipalback to summary
private static void checkPrincipal(String principal)
checkServerIdback to summary
private static void checkServerId(String serverId, String errorText)
deleteFromAllback to summary
private static void deleteFromAll(TreeMap<String, Integer> principalPermissions, int perm)
deletePermissionback to summary
public synchronized Acl deletePermission(String principal, int permissions)

Create a new 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.

Parameters
principal:String

The entity from which permissions should be revoked, or "*" to revoke permissions from all principals.

permissions:int

The permissions to be revoked. The parameter can be a logical or of more permission constants defined in this class.

Returns:Acl

a new Acl instance

Exceptions
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 principal
equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Checks whether the given object is equal to this Acl instance. Two Acl instances are equal if they allow the same set of permissions for the same set of principals.

Parameters
obj:Object

the object to compare with this Acl instance

Returns:boolean

true if the parameter represents the same ACL as this instance

Annotations
@Override
getPermissionsback to summary
public synchronized int getPermissions(String principal)

Get the permissions associated to a given principal.

Parameters
principal:String

The entity whose permissions to query, or "*" to query the permissions that are granted globally, to all principals

Returns:int

The permissions of the given principal. The returned int is a bitmask of the permission constants defined in this class

Exceptions
IllegalArgumentException:
if principal is not a valid principal name
getPrincipalsback to summary
public String[] 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:String[]

The array of principals having permissions on this node.

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Returns the hash code for this ACL instance. If two Acl instances are equal according to the equals(Object) method, then calling this method on each of them must produce the same integer result.

Returns:int

hash code for this ACL

Annotations
@Override
isPermittedback to summary
public synchronized boolean isPermitted(String principal, int permissions)

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:String

The entity to check, or "*" to check whether the given permissions are granted to all principals globally

permissions:int

The permissions to check

Returns:boolean

true if the principal holds all the given permissions

Exceptions
IllegalArgumentException:
if principal is not a valid principal name or if permissions is not a valid combination of the permission constants defined in this class
parseCommandback to summary
private static int parseCommand(String command)
setPermissionback to summary
public synchronized Acl setPermission(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.

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:String

The entity to which permissions should be granted, or "*" to globally grant permissions to all principals.

permissions:int

The set of permissions to be given. The parameter is a bitmask of the permission constants defined in this class.

Returns:Acl

a new Acl instance

Exceptions
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 principal
setPrincipalPermissionback to summary
private static void setPrincipalPermission(TreeMap<String, Integer> principalPermissions, String principal, int perm)
splitback to summary
private static String[] split(String input, char sep, int limit)
toStringback to summary
public synchronized String toString()

Overrides java.lang.Object.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.

Returns:String

The string representation as defined in OMA DM.

Annotations
@Override
writeCommandsback to summary
private static String writeCommands(int command)
writeEntryback to summary
private String writeEntry(int command, String acl)