Authorizer.php 2.62 KB
Newer Older
1
2
3
4
5
6
7
<?php


namespace Source\Authorization;

interface Authorizer
{
8
9
10
11
12
    /**
     * @param string|null $id
     */
    public function setCurrentUserId(?string $id): void;

13
14
15
16
17
18
19
    /**
     * Returns list of permission from \Source\Authorization\Permissions that the user has
     *
     * @return string[]
     */
    public function getPermissions(): array;

20
    /**
21
22
23
     * The user needs ALL of the permissions.
     *
     * @param string[] $permissions
24
     * @return bool
25
     * @throws \Source\Exceptions\EntityNotFoundException
26
     */
27
    public function allowsAll(array $permissions): bool;
28
29

    /**
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
     * The user needs only ONE of the permissions
     *
     * @param string[] $permissions
     * @return bool
     * @throws \Source\Exceptions\EntityNotFoundException
     */
    public function allowsOne(array $permissions): bool;

    /**
     * Permissions to check against from \Source\Authorization\Permissions
     * Te user needs ALL of the permissions
     *
     * @param string[] $permissions
     * @throws \Source\Exceptions\AuthorizationException
     * @throws \Source\Exceptions\EntityNotFoundException
     */
    public function protectAll(array $permissions): void;

    /**
     * Permissions to check against from \Source\Authorization\Permissions
     * The user only needs ONE of the permissions
     *
     * @param string[] $permissions
53
     * @throws \Source\Exceptions\AuthorizationException
54
     * @throws \Source\Exceptions\EntityNotFoundException
55
     */
56
    public function protectOne(array $permissions): void;
Jacob Priddy's avatar
Jacob Priddy committed
57
58
59
60
61
62
63
64
65
66
67

    /**
     * Permissions to check against from \Source\Authorization\Permissions
     * The user needs the permission
     *
     * @param string $permission
     * @throws \Source\Exceptions\AuthorizationException
     * @throws \Source\Exceptions\EntityNotFoundException
     */
    public function protect(string $permission): void;

68
69
70
71
72
73
74
75
76
77
    /**
     * Permissions to check against from \Source\Authorization\Permissions
     * The user needs the permission
     *
     * @param string $permission
     * @return bool
     * @throws \Source\Exceptions\EntityNotFoundException
     */
    public function allows(string $permission): bool;

Jacob Priddy's avatar
Jacob Priddy committed
78
79
    /**
     * Protects the admin user from being modified.
80
81
     * Throws an exception if the currently authenticated user does not have
     * the permissions to perform an action on the passed user or group
Jacob Priddy's avatar
Jacob Priddy committed
82
83
84
85
86
87
88
     *
     * @param string      $userId
     * @param string|null $groupId
     * @throws \Source\Exceptions\AuthorizationException
     * @throws \Source\Exceptions\EntityNotFoundException
     */
    public function protectAdminRights(string $userId, ?string $groupId = null): void;
89
}