Interface PermissionValidationService
public interface PermissionValidationService
A utility service for plugin developer to validate that the current user has a specific permission.
This service uses the
PermissionService
to check for a permission and will throw
AuthorisationException
for any failed permission check.-
Method Summary
Modifier and TypeMethodDescriptionvoid
Validate that the user is logged invoid
validateForGlobal
(Permission permission) Validate that the current user has the specified global permissionvoid
validateForProject
(int projectId, Permission permission) Validate that the current user has the specified permission for the projectvoid
validateForProject
(Project project, Permission permission) Validate that the current user has the specified permission for the projectvoid
validateForRepository
(int repositoryId, Permission permission) Validate that the current user has the specified permission for the repositoryvoid
validateForRepository
(Repository repository, Permission permission) Validate that the current user has the specified permission for the repositoryvoid
validateForUser
(int targetUserId, Permission permission) Validate that the current user has the specified permission for the target user.void
validateForUser
(Permission permission) Validate that the current user has the specified permission for itselfvoid
validateForUser
(ApplicationUser targetUser, Permission permission) Validate that the current user has the specified permission for the target user.void
validateRepositoryAccessible
(int repositoryId) Validate that the current user (authenticated or not) has access to the given repository.void
validateRepositoryAccessible
(Repository repository) Validate that the current user (authenticated or not) has access to the given repository.
-
Method Details
-
validateAuthenticated
Validate that the user is logged in- Throws:
AuthorisationException
- if anonymous- See Also:
-
validateForGlobal
Validate that the current user has the specified global permission- Parameters:
permission
- the requested permission. Must not benull
andPermission.isGlobal()
must be true- Throws:
AuthorisationException
- if the current user is unauthorized- See Also:
-
validateForProject
void validateForProject(@Nonnull Project project, @Nonnull Permission permission) throws AuthorisationException Validate that the current user has the specified permission for the project- Parameters:
project
- the target project. Must not benull
permission
- the requested permission. Must not benull
andPermission.isGlobal()
must be false- Throws:
AuthorisationException
- if the current user is unauthorized- See Also:
-
validateForProject
Validate that the current user has the specified permission for the project- Parameters:
projectId
- the ID of the target projectpermission
- the requested permission. Must not benull
andPermission.isGlobal()
must be false- Throws:
AuthorisationException
- if the current user is unauthorized- Since:
- 4.1
- See Also:
-
validateForRepository
void validateForRepository(@Nonnull Repository repository, @Nonnull Permission permission) throws AuthorisationException Validate that the current user has the specified permission for the repositoryNote that anonymous users accessing a public repository do not have the
Permission.REPO_READ
permission. To perform read access validation that includes public repository access by anonymous users seevalidateRepositoryAccessible(Repository)
.- Parameters:
repository
- the target repository. Must not benull
permission
- the requested permission. Must not benull
andPermission.isGlobal()
must be false- Throws:
AuthorisationException
- if the current user is unauthorized- See Also:
-
validateForRepository
Validate that the current user has the specified permission for the repositoryNote that anonymous users accessing a public repository do not have the
Permission.REPO_READ
permission. To perform read access validation that includes public repository access by anonymous users seevalidateRepositoryAccessible(int)
.- Parameters:
repositoryId
- the ID of the target repositorypermission
- the requested permission. Must not benull
andPermission.isGlobal()
must be false- Throws:
AuthorisationException
- if the current user is unauthorized- Since:
- 4.1
- See Also:
-
validateForUser
Validate that the current user has the specified permission for the target user.- Parameters:
targetUser
- the target user. Must not benull
permission
- the requested permission. Must not benull
andPermission.isGlobal()
must be false- Throws:
AuthorisationException
- if the current user is unauthorized- Since:
- 5.5
- See Also:
-
validateForUser
Validate that the current user has the specified permission for the target user.- Parameters:
targetUserId
- the ID of the target userpermission
- the requested permission. Must not benull
andPermission.isGlobal()
must be false- Throws:
AuthorisationException
- if the current user is unauthorized- Since:
- 5.5
- See Also:
-
validateForUser
Validate that the current user has the specified permission for itself- Parameters:
permission
- the requested permission. Must not benull
andPermission.isGlobal()
must be false- Throws:
AuthorisationException
- if the current user is unauthorized- Since:
- 5.5
- See Also:
-
validateRepositoryAccessible
Validate that the current user (authenticated or not) has access to the given repository. SeePermissionService.isRepositoryAccessible(Repository)
for a description of what constitutes "access".- Parameters:
repository
- the target repository. Must not benull
- Throws:
AuthorisationException
- if the current user is unauthorized- Since:
- 4.3
- See Also:
-
validateRepositoryAccessible
void validateRepositoryAccessible(int repositoryId) Validate that the current user (authenticated or not) has access to the given repository. SeePermissionService.isRepositoryAccessible(int)
for a description of what constitutes "access".- Parameters:
repositoryId
- the ID of the target repository- Throws:
AuthorisationException
- if the current user is unauthorized- Since:
- 4.3
- See Also:
-