Back to Gitbucket

Authenticator

doc/authenticator.md

4.46.13.5 KB
Original Source

Authentication in Controller

GitBucket provides many authenticators to access controlling in the controller.

For example, in the case of RepositoryViewerController, it references three authenticators: ReadableUsersAuthenticator, ReferrerAuthenticator and CollaboratorsAuthenticator.

scala
class RepositoryViewerController extends RepositoryViewerControllerBase
  with RepositoryService with AccountService with ActivityService with IssuesService with WebHookService with CommitsService
  with ReadableUsersAuthenticator with ReferrerAuthenticator with CollaboratorsAuthenticator with PullRequestService with CommitStatusService
  with WebHookPullRequestService with WebHookPullRequestReviewCommentService

trait RepositoryViewerControllerBase extends ControllerBase {
  self: RepositoryService with AccountService with ActivityService with IssuesService with WebHookService with CommitsService
    with ReadableUsersAuthenticator with ReferrerAuthenticator with CollaboratorsAuthenticator with PullRequestService with CommitStatusService
    with WebHookPullRequestService with WebHookPullRequestReviewCommentService =>

  ...

Authenticators provide a method to add guard to actions in the controller:

  • ReadableUsersAuthenticator provides readableUsersOnly method
  • ReferrerAuthenticator provides referrersOnly method
  • CollaboratorsAuthenticator provides collaboratorsOnly method

These methods are available in each action as below:

scala
// Allows only the repository owner (or manager for group repository) and administrators.
get("/:owner/:repository/tree/*")(referrersOnly { repository =>
  ...
})

// Allows only collaborators and administrators.
get("/:owner/:repository/new/*")(collaboratorsOnly { repository =>
  ...
})

// Allows only signed-in users which can access the repository.
post("/:owner/:repository/commit/:id/comment/new", commentForm)(readableUsersOnly { (form, repository) =>
  ...
})

Currently, GitBucket provides below authenticators:

TraitMethodDescription
OneselfAuthenticatoroneselfOnlyAllows only oneself and administrators.
OwnerAuthenticatorownerOnlyAllows only the repository owner and administrators.
UsersAuthenticatorusersOnlyAllows only signed-in users.
AdminAuthenticatoradminOnlyAllows only administrators.
CollaboratorsAuthenticatorcollaboratorsOnlyAllows only collaborators and administrators.
ReferrerAuthenticatorreferrersOnlyAllows only the repository owner (or manager for group repository) and administrators.
ReadableUsersAuthenticatorreadableUsersOnlyAllows only signed-in users which can access the repository.
GroupManagerAuthenticatormanagersOnlyAllows only the group managers.

Of course, if you make a new plugin, you can implement your own authenticator according to requirement in your plugin.