public class RoleKey extends Key<RoleKeyData> implements Nameable
A BASE installation comes with a default set of role
keys, one for every type of item. The keys cannot be deleted
and no new ones can be created. The id of a role key for
an item can be found by calling SystemItems.getRoleKeyId(Item)
.
The permission given to a role is applied to all items of the type that the role key is valid for. The following example code will give all users the permission to create samples.
Role r = Role.getById(dbControl, Role.USER); RoleKey rk = RoleKey.getById(dbControl, SystemItems.getRoleKeyId(Item.SAMPLE)); rk.setPermission(r, Permission.CREATE); dbControl.commit();
Modifier and Type | Field and Description |
---|---|
private static QueryRuntimeFilter |
RUNTIME_FILTER
This filter will only return items if the logged in user has
generic read permission to roles.
|
static Item |
TYPE
The type of item represented by this class.
|
MAX_DESCRIPTION_LENGTH, MAX_NAME_LENGTH
Constructor and Description |
---|
RoleKey(RoleKeyData roleKeyData) |
Modifier and Type | Method and Description |
---|---|
static RoleKey |
getById(DbControl dc,
int id)
Get a
RoleKey item when you know the ID. |
static RoleKey |
getByItemType(DbControl dc,
Item itemType)
Get a
RoleKey item when you know the Item type. |
String |
getDescription()
Get the description for the item.
|
Item |
getItemType()
Get the
Item type for the type of items this role key applies to. |
String |
getName()
Get the name of the item.
|
Set<Permission> |
getPermissions(Role role)
Get the permissions for a role.
|
(package private) PluginPermission |
getPluginPermissions() |
static ItemQuery<RoleKey> |
getQuery()
Get a query object configured to retrieve role keys.
|
Item |
getType()
Get the type of item represented by the object.
|
(package private) void |
initPermissions(int granted,
int denied)
CREATE and DELETE permissions are always denied.
|
boolean |
isUsed()
Always return TRUE.
|
void |
setDescription(String description)
Set the description for the item.
|
void |
setName(String name)
Set the name of the item.
|
void |
setPermissions(Role role,
Set<Permission> permissions)
Grant permissions to a role.
|
addUsingItems, addUsingItems, checkPermission, equals, getData, getDbControl, getId, getPermissions, getSessionControl, getUsingItems, getVersion, hashCode, hasPermission, isDetached, isInDatabase, onAfterCommit, onAfterInsert, onBeforeCommit, onRollback, setDbControl, setProjectDefaults, toString, toTransferable, validate
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
getId, getVersion
checkPermission, getPermissions, hasPermission
public static final Item TYPE
Item.ROLEKEY
,
getType()
private static final QueryRuntimeFilter RUNTIME_FILTER
RoleKey(RoleKeyData roleKeyData)
public static RoleKey getById(DbControl dc, int id) throws ItemNotFoundException, PermissionDeniedException, BaseException
RoleKey
item when you know the ID.
The ID of a role key can be found by calling
SystemItems.getRoleKeyId(Item)
.dc
- The DbControl
which will be used for
permission checking and database access.id
- The ID of the item to loadRoleKey
itemItemNotFoundException
- If an item with the specified
ID is not foundPermissionDeniedException
- If the logged in user doesn't
have Permission.READ
permission to the itemBaseException
- If there is another errorpublic static RoleKey getByItemType(DbControl dc, Item itemType) throws ItemNotFoundException, PermissionDeniedException, BaseException
RoleKey
item when you know the Item
type.dc
- The DbControl
which will be used for
permission checking and database access.itemType
- The item type of the role key to loadRoleKey
itemItemNotFoundException
- If a role key for the specified
item type is not foundPermissionDeniedException
- If the logged in user doesn't
have Permission.READ
permission to the itemBaseException
- If there is another errorpublic static ItemQuery<RoleKey> getQuery()
ItemQuery
objectpublic Item getType()
Identifiable
Item
enumeration.getType
in interface Identifiable
public String getName()
Nameable
public void setName(String name) throws PermissionDeniedException, InvalidDataException
Nameable
Nameable.MAX_NAME_LENGTH
constant.setName
in interface Nameable
name
- The new name for the itemPermissionDeniedException
- If the logged in user doesn't
have write permissionInvalidDataException
- If the name is null or longer
than specified by the Nameable.MAX_NAME_LENGTH
constantpublic String getDescription()
Nameable
getDescription
in interface Nameable
String
with a description of the itempublic void setDescription(String description) throws PermissionDeniedException, InvalidDataException
Nameable
Nameable.MAX_DESCRIPTION_LENGTH
constant.setDescription
in interface Nameable
description
- The new description for the itemPermissionDeniedException
- If the logged in user doesn't
have write permissionInvalidDataException
- If the description longer
than specified by the Nameable.MAX_DESCRIPTION_LENGTH
constantpublic boolean isUsed() throws BaseException
isUsed
in class BasicItem<RoleKeyData>
BaseException
- If not able to tell if item is used or not.BasicItem.getUsingItems()
void initPermissions(int granted, int denied) throws BaseException
Role
.initPermissions
in class BasicItem<RoleKeyData>
granted
- Permissions that have been granted by the subclassdenied
- Permissions that have been denied by the subclassBaseException
- If the permissions couldn't be initialisedPluginPermission getPluginPermissions()
getPluginPermissions
in class BasicItem<RoleKeyData>
public Item getItemType()
Item
type for the type of items this role key applies to.Item
objectpublic void setPermissions(Role role, Set<Permission> permissions) throws PermissionDeniedException, InvalidDataException
Permission.DENIED
is
set it will override permissions gained from other keys. Ie.
if a user has a role key with Permission.DENIED
it takes precedence
over all other permissions. Use an empty Set
or null
to remove all permissions for the role.role
- The Role
permissions
- The permissions to grantPermissionDeniedException
- If the logged in user doesn't have
Permission.WRITE
permission for the role keyInvalidDataException
- If the role is nullPermission
public Set<Permission> getPermissions(Role role) throws InvalidDataException
role
- The Role
for which we want to get the permissionEnumSet
containing the granted permissions, or an
empty set if no permissions have been grantedInvalidDataException
- If the role is nullPermission