T
- Type of the entity, this service works for.N
- Type of the according creation entity, this service works for.E
- The type of the exception to be thrown when the current user does not have a required
permission.public abstract class BasePermissionManagement<T,N,E extends AuthorizationException> extends Object implements PermissionManagement<T,N,E>
Constructor and Description |
---|
BasePermissionManagement() |
Modifier and Type | Method and Description |
---|---|
void |
addPermissionFilter(PermissionFilter<T,N> filter)
Adds a filter to the internal list of filters.
|
protected abstract E |
createPermissonViolationException(T entity,
Permission<T> permission)
Create an exception that should be thrown when the current user does not have a required
permission
|
protected abstract T |
getEntity(Long entityId)
Returns the entity for the given id.
|
protected List<PermissionFilter<T,N>> |
getFilters() |
Set<Permission<T>> |
getPermissions(Long entityId)
Returns a collection of permissions for the given entity.
|
Set<Permission<T>> |
getPermissions(T entity)
Returns a collection of permissions for the given entity.
|
Set<Permission<T>> |
getPermissionsForCreation(N entity)
Returns a collection of permissions for creation for the given entity.
|
<R> R |
hasAndGetWithPermission(long entityId,
Permission<T> permission,
Converter<T,R> converter)
Checks the permission and returns the given entity converted with the provided converter if
the current user has the requested permission.
|
boolean |
hasPermission(long entityId,
Permission<T> permission)
Checks if the current user has the permission of the given entity.
|
boolean |
hasPermission(long entityId,
String permissionIdentifier)
Checks if the current user has the permission of the given entity.
|
boolean |
hasPermissionForCreation(Permission<T> permission)
Checks if the current user has the permission to to create entities of the associated type
|
void |
removePermissionFilter(PermissionFilter<T,N> filter)
Removes a filter from the internal list of filters.
|
public void addPermissionFilter(PermissionFilter<T,N> filter)
PermissionManagement
addPermissionFilter
in interface PermissionManagement<T,N,E extends AuthorizationException>
filter
- The filter to add.protected abstract E createPermissonViolationException(T entity, Permission<T> permission)
entity
- the entity for which a permission was required, never nullpermission
- the permission the current user does not haveprotected abstract T getEntity(Long entityId)
entityId
- ID of the entityprotected List<PermissionFilter<T,N>> getFilters()
@Transactional(readOnly=true) public Set<Permission<T>> getPermissions(Long entityId)
PermissionManagement
getPermissions
in interface PermissionManagement<T,N,E extends AuthorizationException>
entityId
- ID of the entitypublic Set<Permission<T>> getPermissions(T entity)
PermissionManagement
getPermissions
in interface PermissionManagement<T,N,E extends AuthorizationException>
entity
- The entity.public Set<Permission<T>> getPermissionsForCreation(N entity)
PermissionManagement
getPermissionsForCreation
in interface PermissionManagement<T,N,E extends AuthorizationException>
entity
- The entity, can be TO or null to check in general@Transactional(readOnly=true) public <R> R hasAndGetWithPermission(long entityId, Permission<T> permission, Converter<T,R> converter) throws E extends AuthorizationException, NotFoundException
PermissionManagement
hasAndGetWithPermission
in interface PermissionManagement<T,N,E extends AuthorizationException>
R
- the target type of the conversionentityId
- ID of the entitypermission
- The permission the user must have.converter
- the converter to convert the resultE
- in case the current user doesn't have the given permission.NotFoundException
- in case the entity does not existE extends AuthorizationException
@Transactional(readOnly=true) public boolean hasPermission(long entityId, Permission<T> permission)
PermissionManagement
hasPermission
in interface PermissionManagement<T,N,E extends AuthorizationException>
entityId
- ID of the entitypermission
- The permission to check.@Transactional(readOnly=true) public boolean hasPermission(long entityId, String permissionIdentifier)
PermissionManagement
hasPermission
in interface PermissionManagement<T,N,E extends AuthorizationException>
entityId
- ID of the entitypermissionIdentifier
- The permission to check.public boolean hasPermissionForCreation(Permission<T> permission)
PermissionManagement
hasPermissionForCreation
in interface PermissionManagement<T,N,E extends AuthorizationException>
permission
- The permission to check.public void removePermissionFilter(PermissionFilter<T,N> filter)
PermissionManagement
removePermissionFilter
in interface PermissionManagement<T,N,E extends AuthorizationException>
filter
- The filter to remove.Copyright © 2019 Communote team. All rights reserved.