@@ -43,95 +43,95 @@ |
||
43 | 43 | */ |
44 | 44 | abstract class PublicShareController extends Controller { |
45 | 45 | |
46 | - /** @var ISession */ |
|
47 | - protected $session; |
|
48 | - |
|
49 | - /** @var string */ |
|
50 | - private $token; |
|
51 | - |
|
52 | - /** |
|
53 | - * @since 14.0.0 |
|
54 | - */ |
|
55 | - public function __construct(string $appName, |
|
56 | - IRequest $request, |
|
57 | - ISession $session) { |
|
58 | - parent::__construct($appName, $request); |
|
59 | - |
|
60 | - $this->session = $session; |
|
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * Middleware set the token for the request |
|
65 | - * |
|
66 | - * @since 14.0.0 |
|
67 | - */ |
|
68 | - final public function setToken(string $token) { |
|
69 | - $this->token = $token; |
|
70 | - } |
|
71 | - |
|
72 | - /** |
|
73 | - * Get the token for this request |
|
74 | - * |
|
75 | - * @since 14.0.0 |
|
76 | - */ |
|
77 | - final public function getToken(): string { |
|
78 | - return $this->token; |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * Get a hash of the password for this share |
|
83 | - * |
|
84 | - * To ensure access is blocked when the password to a share is changed we store |
|
85 | - * a hash of the password for this token. |
|
86 | - * |
|
87 | - * @since 14.0.0 |
|
88 | - */ |
|
89 | - abstract protected function getPasswordHash(): string; |
|
90 | - |
|
91 | - /** |
|
92 | - * Is the provided token a valid token |
|
93 | - * |
|
94 | - * This function is already called from the middleware directly after setting the token. |
|
95 | - * |
|
96 | - * @since 14.0.0 |
|
97 | - */ |
|
98 | - abstract public function isValidToken(): bool; |
|
99 | - |
|
100 | - /** |
|
101 | - * Is a share with this token password protected |
|
102 | - * |
|
103 | - * @since 14.0.0 |
|
104 | - */ |
|
105 | - abstract protected function isPasswordProtected(): bool; |
|
106 | - |
|
107 | - /** |
|
108 | - * Check if a share is authenticated or not |
|
109 | - * |
|
110 | - * @since 14.0.0 |
|
111 | - */ |
|
112 | - public function isAuthenticated(): bool { |
|
113 | - // Always authenticated against non password protected shares |
|
114 | - if (!$this->isPasswordProtected()) { |
|
115 | - return true; |
|
116 | - } |
|
117 | - |
|
118 | - // If we are authenticated properly |
|
119 | - if ($this->session->get('public_link_authenticated_token') === $this->getToken() && |
|
120 | - $this->session->get('public_link_authenticated_password_hash') === $this->getPasswordHash()) { |
|
121 | - return true; |
|
122 | - } |
|
123 | - |
|
124 | - // Fail by default if nothing matches |
|
125 | - return false; |
|
126 | - } |
|
127 | - |
|
128 | - /** |
|
129 | - * Function called if the share is not found. |
|
130 | - * |
|
131 | - * You can use this to do some logging for example |
|
132 | - * |
|
133 | - * @since 14.0.0 |
|
134 | - */ |
|
135 | - public function shareNotFound() { |
|
136 | - } |
|
46 | + /** @var ISession */ |
|
47 | + protected $session; |
|
48 | + |
|
49 | + /** @var string */ |
|
50 | + private $token; |
|
51 | + |
|
52 | + /** |
|
53 | + * @since 14.0.0 |
|
54 | + */ |
|
55 | + public function __construct(string $appName, |
|
56 | + IRequest $request, |
|
57 | + ISession $session) { |
|
58 | + parent::__construct($appName, $request); |
|
59 | + |
|
60 | + $this->session = $session; |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * Middleware set the token for the request |
|
65 | + * |
|
66 | + * @since 14.0.0 |
|
67 | + */ |
|
68 | + final public function setToken(string $token) { |
|
69 | + $this->token = $token; |
|
70 | + } |
|
71 | + |
|
72 | + /** |
|
73 | + * Get the token for this request |
|
74 | + * |
|
75 | + * @since 14.0.0 |
|
76 | + */ |
|
77 | + final public function getToken(): string { |
|
78 | + return $this->token; |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * Get a hash of the password for this share |
|
83 | + * |
|
84 | + * To ensure access is blocked when the password to a share is changed we store |
|
85 | + * a hash of the password for this token. |
|
86 | + * |
|
87 | + * @since 14.0.0 |
|
88 | + */ |
|
89 | + abstract protected function getPasswordHash(): string; |
|
90 | + |
|
91 | + /** |
|
92 | + * Is the provided token a valid token |
|
93 | + * |
|
94 | + * This function is already called from the middleware directly after setting the token. |
|
95 | + * |
|
96 | + * @since 14.0.0 |
|
97 | + */ |
|
98 | + abstract public function isValidToken(): bool; |
|
99 | + |
|
100 | + /** |
|
101 | + * Is a share with this token password protected |
|
102 | + * |
|
103 | + * @since 14.0.0 |
|
104 | + */ |
|
105 | + abstract protected function isPasswordProtected(): bool; |
|
106 | + |
|
107 | + /** |
|
108 | + * Check if a share is authenticated or not |
|
109 | + * |
|
110 | + * @since 14.0.0 |
|
111 | + */ |
|
112 | + public function isAuthenticated(): bool { |
|
113 | + // Always authenticated against non password protected shares |
|
114 | + if (!$this->isPasswordProtected()) { |
|
115 | + return true; |
|
116 | + } |
|
117 | + |
|
118 | + // If we are authenticated properly |
|
119 | + if ($this->session->get('public_link_authenticated_token') === $this->getToken() && |
|
120 | + $this->session->get('public_link_authenticated_password_hash') === $this->getPasswordHash()) { |
|
121 | + return true; |
|
122 | + } |
|
123 | + |
|
124 | + // Fail by default if nothing matches |
|
125 | + return false; |
|
126 | + } |
|
127 | + |
|
128 | + /** |
|
129 | + * Function called if the share is not found. |
|
130 | + * |
|
131 | + * You can use this to do some logging for example |
|
132 | + * |
|
133 | + * @since 14.0.0 |
|
134 | + */ |
|
135 | + public function shareNotFound() { |
|
136 | + } |
|
137 | 137 | } |