public interface

PermissionValidationService

com.atlassian.bitbucket.permission.PermissionValidationService

Class Overview

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.

Summary

Public Methods
void validateAuthenticated()
Validate that the user is logged in
void validateForGlobal(Permission permission)
Validate that the current user has the specified global permission
void validateForProject(int projectId, Permission permission)
Validate that the current user has the specified permission for the project
void validateForProject(Project project, Permission permission)
Validate that the current user has the specified permission for the project
void validateForRepository(Repository repository, Permission permission)
Validate that the current user has the specified permission for the repository

Note that anonymous users accessing a public repository do not have the REPO_READ permission.

void validateForRepository(int repositoryId, Permission permission)
Validate that the current user has the specified permission for the repository

Note that anonymous users accessing a public repository do not have the REPO_READ permission.

void validateForUser(ApplicationUser targetUser, 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 itself
void validateForUser(int targetUserId, Permission permission)
Validate that the current user has the specified permission for the target user.
void validateRepositoryAccessible(Repository repository)
Validate that the current user (authenticated or not) has access to the given repository.
void validateRepositoryAccessible(int repositoryId)
Validate that the current user (authenticated or not) has access to the given repository.

Public Methods

public void validateAuthenticated ()

Validate that the user is logged in

Throws
AuthorisationException if anonymous

public void validateForGlobal (Permission permission)

Validate that the current user has the specified global permission

Parameters
permission the requested permission. Must not be null and isGlobal() must be true
Throws
AuthorisationException if the current user is unauthorized

public void validateForProject (int projectId, Permission permission)

Validate that the current user has the specified permission for the project

Parameters
projectId the ID of the target project
permission the requested permission. Must not be null and isGlobal() must be false
Throws
AuthorisationException if the current user is unauthorized

public void validateForProject (Project project, Permission permission)

Validate that the current user has the specified permission for the project

Parameters
project the target project. Must not be null
permission the requested permission. Must not be null and isGlobal() must be false
Throws
AuthorisationException if the current user is unauthorized

public void validateForRepository (Repository repository, Permission permission)

Validate that the current user has the specified permission for the repository

Note that anonymous users accessing a public repository do not have the REPO_READ permission. To perform read access validation that includes public repository access by anonymous users see validateRepositoryAccessible(Repository).

Parameters
repository the target repository. Must not be null
permission the requested permission. Must not be null and isGlobal() must be false
Throws
AuthorisationException if the current user is unauthorized

public void validateForRepository (int repositoryId, Permission permission)

Validate that the current user has the specified permission for the repository

Note that anonymous users accessing a public repository do not have the REPO_READ permission. To perform read access validation that includes public repository access by anonymous users see validateRepositoryAccessible(int).

Parameters
repositoryId the ID of the target repository
permission the requested permission. Must not be null and isGlobal() must be false
Throws
AuthorisationException if the current user is unauthorized

public void validateForUser (ApplicationUser targetUser, Permission permission)

Validate that the current user has the specified permission for the target user.

Parameters
targetUser the target user. Must not be null
permission the requested permission. Must not be null and isGlobal() must be false
Throws
AuthorisationException if the current user is unauthorized

public void validateForUser (Permission permission)

Validate that the current user has the specified permission for itself

Parameters
permission the requested permission. Must not be null and isGlobal() must be false
Throws
AuthorisationException if the current user is unauthorized

public void validateForUser (int targetUserId, Permission permission)

Validate that the current user has the specified permission for the target user.

Parameters
targetUserId the ID of the target user
permission the requested permission. Must not be null and isGlobal() must be false
Throws
AuthorisationException if the current user is unauthorized

public void validateRepositoryAccessible (Repository repository)

Validate that the current user (authenticated or not) has access to the given repository. See isRepositoryAccessible(Repository) for a description of what constitutes "access".

Parameters
repository the target repository. Must not be null
Throws
AuthorisationException if the current user is unauthorized

public void validateRepositoryAccessible (int repositoryId)

Validate that the current user (authenticated or not) has access to the given repository. See 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