@@ -12,99 +12,99 @@ |
||
12 | 12 | |
13 | 13 | class ValidationError |
14 | 14 | { |
15 | - const NAME_EMPTY = "name_empty"; |
|
16 | - const NAME_EXISTS = "name_exists"; |
|
17 | - const NAME_EXISTS_SUL = "name_exists"; |
|
18 | - const NAME_NUMONLY = "name_numonly"; |
|
19 | - const NAME_INVALIDCHAR = "name_invalidchar"; |
|
20 | - const NAME_SANITISED = "name_sanitised"; |
|
21 | - const EMAIL_EMPTY = "email_empty"; |
|
22 | - const EMAIL_WIKIMEDIA = "email_wikimedia"; |
|
23 | - const EMAIL_INVALID = "email_invalid"; |
|
24 | - const EMAIL_MISMATCH = "email_mismatch"; |
|
25 | - const OPEN_REQUEST_NAME = "open_request_name"; |
|
26 | - const BANNED = "banned"; |
|
27 | - const BANNED_TOR = "banned_tor"; |
|
28 | - /** |
|
29 | - * @var array Error text for the above |
|
30 | - */ |
|
31 | - private static $errorText = array( |
|
32 | - self::NAME_EMPTY => 'You\'ve not chosen a username!', |
|
33 | - self::NAME_EXISTS => 'I\'m sorry, but the username you selected is already taken. Please try another. ' |
|
34 | - . 'Please note that Wikipedia automatically capitalizes the first letter of any user name, therefore ' |
|
35 | - . '[[User:example]] would become [[User:Example]].', |
|
36 | - self::NAME_EXISTS_SUL => 'I\'m sorry, but the username you selected is already taken. Please try another. ' |
|
37 | - . 'Please note that Wikipedia automatically capitalizes the first letter of any user name, therefore ' |
|
38 | - . '[[User:example]] would become [[User:Example]].', |
|
39 | - self::NAME_NUMONLY => 'The username you chose is invalid: it consists entirely of numbers. Please retry ' |
|
40 | - . 'with a valid username.', |
|
41 | - self::NAME_INVALIDCHAR => 'There appears to be an invalid character in your username. Please note that the ' |
|
42 | - . 'following characters are not allowed: <code># @ / < > [ ] | { }</code>', |
|
43 | - self::NAME_SANITISED => 'Your requested username has been automatically adjusted due to technical ' |
|
44 | - . 'restrictions. Underscores have been replaced with spaces, and the first character has been capitalised.', |
|
45 | - self::EMAIL_EMPTY => 'You need to supply an email address.', |
|
46 | - self::EMAIL_WIKIMEDIA => 'Please provide your email address here.', |
|
47 | - self::EMAIL_INVALID => 'Invalid E-mail address supplied. Please check you entered it correctly.', |
|
48 | - self::EMAIL_MISMATCH => 'The email addresses you entered do not match. Please try again.', |
|
49 | - self::OPEN_REQUEST_NAME => 'There is already an open request with this name in this system.', |
|
50 | - self::BANNED => 'I\'m sorry, but you are currently banned from requesting accounts using this tool. ' |
|
51 | - . 'However, you can still send an email to [email protected] to request an account.', |
|
52 | - self::BANNED_TOR => 'Tor exit nodes are currently banned from using this tool due to excessive abuse. ' |
|
53 | - . 'Please note that Tor is also currently banned from editing Wikipedia.', |
|
54 | - ); |
|
55 | - /** |
|
56 | - * Summary of $errorCode |
|
57 | - * @var string |
|
58 | - */ |
|
59 | - private $errorCode; |
|
60 | - /** |
|
61 | - * Summary of $isError |
|
62 | - * @var bool |
|
63 | - */ |
|
64 | - private $isError; |
|
15 | + const NAME_EMPTY = "name_empty"; |
|
16 | + const NAME_EXISTS = "name_exists"; |
|
17 | + const NAME_EXISTS_SUL = "name_exists"; |
|
18 | + const NAME_NUMONLY = "name_numonly"; |
|
19 | + const NAME_INVALIDCHAR = "name_invalidchar"; |
|
20 | + const NAME_SANITISED = "name_sanitised"; |
|
21 | + const EMAIL_EMPTY = "email_empty"; |
|
22 | + const EMAIL_WIKIMEDIA = "email_wikimedia"; |
|
23 | + const EMAIL_INVALID = "email_invalid"; |
|
24 | + const EMAIL_MISMATCH = "email_mismatch"; |
|
25 | + const OPEN_REQUEST_NAME = "open_request_name"; |
|
26 | + const BANNED = "banned"; |
|
27 | + const BANNED_TOR = "banned_tor"; |
|
28 | + /** |
|
29 | + * @var array Error text for the above |
|
30 | + */ |
|
31 | + private static $errorText = array( |
|
32 | + self::NAME_EMPTY => 'You\'ve not chosen a username!', |
|
33 | + self::NAME_EXISTS => 'I\'m sorry, but the username you selected is already taken. Please try another. ' |
|
34 | + . 'Please note that Wikipedia automatically capitalizes the first letter of any user name, therefore ' |
|
35 | + . '[[User:example]] would become [[User:Example]].', |
|
36 | + self::NAME_EXISTS_SUL => 'I\'m sorry, but the username you selected is already taken. Please try another. ' |
|
37 | + . 'Please note that Wikipedia automatically capitalizes the first letter of any user name, therefore ' |
|
38 | + . '[[User:example]] would become [[User:Example]].', |
|
39 | + self::NAME_NUMONLY => 'The username you chose is invalid: it consists entirely of numbers. Please retry ' |
|
40 | + . 'with a valid username.', |
|
41 | + self::NAME_INVALIDCHAR => 'There appears to be an invalid character in your username. Please note that the ' |
|
42 | + . 'following characters are not allowed: <code># @ / < > [ ] | { }</code>', |
|
43 | + self::NAME_SANITISED => 'Your requested username has been automatically adjusted due to technical ' |
|
44 | + . 'restrictions. Underscores have been replaced with spaces, and the first character has been capitalised.', |
|
45 | + self::EMAIL_EMPTY => 'You need to supply an email address.', |
|
46 | + self::EMAIL_WIKIMEDIA => 'Please provide your email address here.', |
|
47 | + self::EMAIL_INVALID => 'Invalid E-mail address supplied. Please check you entered it correctly.', |
|
48 | + self::EMAIL_MISMATCH => 'The email addresses you entered do not match. Please try again.', |
|
49 | + self::OPEN_REQUEST_NAME => 'There is already an open request with this name in this system.', |
|
50 | + self::BANNED => 'I\'m sorry, but you are currently banned from requesting accounts using this tool. ' |
|
51 | + . 'However, you can still send an email to [email protected] to request an account.', |
|
52 | + self::BANNED_TOR => 'Tor exit nodes are currently banned from using this tool due to excessive abuse. ' |
|
53 | + . 'Please note that Tor is also currently banned from editing Wikipedia.', |
|
54 | + ); |
|
55 | + /** |
|
56 | + * Summary of $errorCode |
|
57 | + * @var string |
|
58 | + */ |
|
59 | + private $errorCode; |
|
60 | + /** |
|
61 | + * Summary of $isError |
|
62 | + * @var bool |
|
63 | + */ |
|
64 | + private $isError; |
|
65 | 65 | |
66 | - /** |
|
67 | - * Summary of __construct |
|
68 | - * |
|
69 | - * @param string $errorCode |
|
70 | - * @param bool $isError |
|
71 | - */ |
|
72 | - public function __construct($errorCode, $isError = true) |
|
73 | - { |
|
74 | - $this->errorCode = $errorCode; |
|
75 | - $this->isError = $isError; |
|
76 | - } |
|
66 | + /** |
|
67 | + * Summary of __construct |
|
68 | + * |
|
69 | + * @param string $errorCode |
|
70 | + * @param bool $isError |
|
71 | + */ |
|
72 | + public function __construct($errorCode, $isError = true) |
|
73 | + { |
|
74 | + $this->errorCode = $errorCode; |
|
75 | + $this->isError = $isError; |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * Summary of getErrorCode |
|
80 | - * @return string |
|
81 | - */ |
|
82 | - public function getErrorCode() |
|
83 | - { |
|
84 | - return $this->errorCode; |
|
85 | - } |
|
78 | + /** |
|
79 | + * Summary of getErrorCode |
|
80 | + * @return string |
|
81 | + */ |
|
82 | + public function getErrorCode() |
|
83 | + { |
|
84 | + return $this->errorCode; |
|
85 | + } |
|
86 | 86 | |
87 | - /** |
|
88 | - * @return string |
|
89 | - * @throws Exception |
|
90 | - */ |
|
91 | - public function getErrorMessage() |
|
92 | - { |
|
93 | - $text = self::$errorText[$this->errorCode]; |
|
87 | + /** |
|
88 | + * @return string |
|
89 | + * @throws Exception |
|
90 | + */ |
|
91 | + public function getErrorMessage() |
|
92 | + { |
|
93 | + $text = self::$errorText[$this->errorCode]; |
|
94 | 94 | |
95 | - if ($text == null) { |
|
96 | - throw new Exception('Unknown validation error'); |
|
97 | - } |
|
95 | + if ($text == null) { |
|
96 | + throw new Exception('Unknown validation error'); |
|
97 | + } |
|
98 | 98 | |
99 | - return $text; |
|
100 | - } |
|
99 | + return $text; |
|
100 | + } |
|
101 | 101 | |
102 | - /** |
|
103 | - * Summary of isError |
|
104 | - * @return bool |
|
105 | - */ |
|
106 | - public function isError() |
|
107 | - { |
|
108 | - return $this->isError; |
|
109 | - } |
|
102 | + /** |
|
103 | + * Summary of isError |
|
104 | + * @return bool |
|
105 | + */ |
|
106 | + public function isError() |
|
107 | + { |
|
108 | + return $this->isError; |
|
109 | + } |
|
110 | 110 | } |
@@ -12,80 +12,80 @@ |
||
12 | 12 | |
13 | 13 | class Token |
14 | 14 | { |
15 | - /** @var string */ |
|
16 | - private $tokenData; |
|
17 | - /** @var string */ |
|
18 | - private $context; |
|
19 | - /** @var DateTimeImmutable */ |
|
20 | - private $generationTimestamp; |
|
21 | - /** @var DateTimeImmutable */ |
|
22 | - private $usageTimestamp; |
|
23 | - /** @var bool */ |
|
24 | - private $used; |
|
15 | + /** @var string */ |
|
16 | + private $tokenData; |
|
17 | + /** @var string */ |
|
18 | + private $context; |
|
19 | + /** @var DateTimeImmutable */ |
|
20 | + private $generationTimestamp; |
|
21 | + /** @var DateTimeImmutable */ |
|
22 | + private $usageTimestamp; |
|
23 | + /** @var bool */ |
|
24 | + private $used; |
|
25 | 25 | |
26 | - /** |
|
27 | - * Token constructor. |
|
28 | - * |
|
29 | - * @param string $tokenData |
|
30 | - * @param string $context |
|
31 | - */ |
|
32 | - public function __construct($tokenData, $context) |
|
33 | - { |
|
34 | - $this->tokenData = $tokenData; |
|
35 | - $this->context = $context; |
|
36 | - $this->generationTimestamp = new DateTimeImmutable(); |
|
37 | - $this->usageTimestamp = null; |
|
38 | - $this->used = false; |
|
39 | - } |
|
26 | + /** |
|
27 | + * Token constructor. |
|
28 | + * |
|
29 | + * @param string $tokenData |
|
30 | + * @param string $context |
|
31 | + */ |
|
32 | + public function __construct($tokenData, $context) |
|
33 | + { |
|
34 | + $this->tokenData = $tokenData; |
|
35 | + $this->context = $context; |
|
36 | + $this->generationTimestamp = new DateTimeImmutable(); |
|
37 | + $this->usageTimestamp = null; |
|
38 | + $this->used = false; |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * @return DateTimeImmutable |
|
43 | - */ |
|
44 | - public function getGenerationTimestamp() |
|
45 | - { |
|
46 | - return $this->generationTimestamp; |
|
47 | - } |
|
41 | + /** |
|
42 | + * @return DateTimeImmutable |
|
43 | + */ |
|
44 | + public function getGenerationTimestamp() |
|
45 | + { |
|
46 | + return $this->generationTimestamp; |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * @return string |
|
51 | - */ |
|
52 | - public function getContext() |
|
53 | - { |
|
54 | - return $this->context; |
|
55 | - } |
|
49 | + /** |
|
50 | + * @return string |
|
51 | + */ |
|
52 | + public function getContext() |
|
53 | + { |
|
54 | + return $this->context; |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * @return string |
|
59 | - */ |
|
60 | - public function getTokenData() |
|
61 | - { |
|
62 | - return $this->tokenData; |
|
63 | - } |
|
57 | + /** |
|
58 | + * @return string |
|
59 | + */ |
|
60 | + public function getTokenData() |
|
61 | + { |
|
62 | + return $this->tokenData; |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * Returns a value indicating whether the token has already been used or not |
|
67 | - * |
|
68 | - * @return boolean |
|
69 | - */ |
|
70 | - public function isUsed() |
|
71 | - { |
|
72 | - return $this->used; |
|
73 | - } |
|
65 | + /** |
|
66 | + * Returns a value indicating whether the token has already been used or not |
|
67 | + * |
|
68 | + * @return boolean |
|
69 | + */ |
|
70 | + public function isUsed() |
|
71 | + { |
|
72 | + return $this->used; |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * Marks the token as used |
|
77 | - */ |
|
78 | - public function markAsUsed() |
|
79 | - { |
|
80 | - $this->used = true; |
|
81 | - $this->usageTimestamp = new DateTimeImmutable(); |
|
82 | - } |
|
75 | + /** |
|
76 | + * Marks the token as used |
|
77 | + */ |
|
78 | + public function markAsUsed() |
|
79 | + { |
|
80 | + $this->used = true; |
|
81 | + $this->usageTimestamp = new DateTimeImmutable(); |
|
82 | + } |
|
83 | 83 | |
84 | - /** |
|
85 | - * @return DateTimeImmutable |
|
86 | - */ |
|
87 | - public function getUsageTimestamp() |
|
88 | - { |
|
89 | - return $this->usageTimestamp; |
|
90 | - } |
|
84 | + /** |
|
85 | + * @return DateTimeImmutable |
|
86 | + */ |
|
87 | + public function getUsageTimestamp() |
|
88 | + { |
|
89 | + return $this->usageTimestamp; |
|
90 | + } |
|
91 | 91 | } |
92 | 92 | \ No newline at end of file |
@@ -15,186 +15,186 @@ |
||
15 | 15 | */ |
16 | 16 | final class SecurityConfiguration |
17 | 17 | { |
18 | - const ALLOW = "allow"; |
|
19 | - const DENY = "deny"; |
|
20 | - private $admin = "default"; |
|
21 | - private $user = "default"; |
|
22 | - private $checkuser = "default"; |
|
23 | - private $community = "default"; |
|
24 | - private $suspended = "default"; |
|
25 | - private $declined = "default"; |
|
26 | - private $new = "default"; |
|
27 | - private $requireIdentified; |
|
28 | - |
|
29 | - /** |
|
30 | - * Sets whether a checkuser is able to gain access. |
|
31 | - * |
|
32 | - * This is private because it's DANGEROUS. Checkusers are not mutually-exclusive with other rights. As such, a |
|
33 | - * suspended checkuser who tries to access a page which allows checkusers will be granted access to the page, UNLESS |
|
34 | - * that page is also set to DENY (note, not default) New/Declined/Suspended users. I have no problem with this |
|
35 | - * method being used, but please ONLY use it in this class in static methods of Security. Nowhere else. |
|
36 | - * |
|
37 | - * @param string $checkuser |
|
38 | - * |
|
39 | - * @return SecurityConfiguration |
|
40 | - * @category Security-Critical |
|
41 | - */ |
|
42 | - public function setCheckuser($checkuser) |
|
43 | - { |
|
44 | - $this->checkuser = $checkuser; |
|
45 | - |
|
46 | - return $this; |
|
47 | - } |
|
48 | - |
|
49 | - /** |
|
50 | - * Returns if a user is required to be identified. |
|
51 | - * |
|
52 | - * @return boolean |
|
53 | - */ |
|
54 | - public function requiresIdentifiedUser() |
|
55 | - { |
|
56 | - return $this->requireIdentified; |
|
57 | - } |
|
58 | - |
|
59 | - /** |
|
60 | - * @return string |
|
61 | - */ |
|
62 | - public function getAdmin() |
|
63 | - { |
|
64 | - return $this->admin; |
|
65 | - } |
|
66 | - |
|
67 | - /** |
|
68 | - * @param string $admin |
|
69 | - * |
|
70 | - * @return SecurityConfiguration |
|
71 | - * @category Security-Critical |
|
72 | - */ |
|
73 | - public function setAdmin($admin) |
|
74 | - { |
|
75 | - $this->admin = $admin; |
|
76 | - |
|
77 | - return $this; |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * @return string |
|
82 | - */ |
|
83 | - public function getUser() |
|
84 | - { |
|
85 | - return $this->user; |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * @param string $user |
|
90 | - * |
|
91 | - * @return SecurityConfiguration |
|
92 | - * @category Security-Critical |
|
93 | - */ |
|
94 | - public function setUser($user) |
|
95 | - { |
|
96 | - $this->user = $user; |
|
97 | - |
|
98 | - return $this; |
|
99 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * @return string |
|
103 | - */ |
|
104 | - public function getCheckuser() |
|
105 | - { |
|
106 | - return $this->checkuser; |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * @return string |
|
111 | - */ |
|
112 | - public function getCommunity() |
|
113 | - { |
|
114 | - return $this->community; |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * @param string $community |
|
119 | - * |
|
120 | - * @return SecurityConfiguration |
|
121 | - * @category Security-Critical |
|
122 | - */ |
|
123 | - public function setCommunity($community) |
|
124 | - { |
|
125 | - $this->community = $community; |
|
126 | - |
|
127 | - return $this; |
|
128 | - } |
|
129 | - |
|
130 | - /** |
|
131 | - * @return string |
|
132 | - */ |
|
133 | - public function getSuspended() |
|
134 | - { |
|
135 | - return $this->suspended; |
|
136 | - } |
|
137 | - |
|
138 | - /** |
|
139 | - * @param string $suspended |
|
140 | - * |
|
141 | - * @return SecurityConfiguration |
|
142 | - * @category Security-Critical |
|
143 | - */ |
|
144 | - public function setSuspended($suspended) |
|
145 | - { |
|
146 | - $this->suspended = $suspended; |
|
147 | - |
|
148 | - return $this; |
|
149 | - } |
|
150 | - |
|
151 | - /** |
|
152 | - * @return string |
|
153 | - */ |
|
154 | - public function getDeclined() |
|
155 | - { |
|
156 | - return $this->declined; |
|
157 | - } |
|
158 | - |
|
159 | - /** |
|
160 | - * @param string $declined |
|
161 | - * |
|
162 | - * @return SecurityConfiguration |
|
163 | - * @category Security-Critical |
|
164 | - */ |
|
165 | - public function setDeclined($declined) |
|
166 | - { |
|
167 | - $this->declined = $declined; |
|
168 | - |
|
169 | - return $this; |
|
170 | - } |
|
171 | - |
|
172 | - /** |
|
173 | - * @return string |
|
174 | - */ |
|
175 | - public function getNew() |
|
176 | - { |
|
177 | - return $this->new; |
|
178 | - } |
|
179 | - |
|
180 | - /** |
|
181 | - * @param string $new |
|
182 | - * |
|
183 | - * @return SecurityConfiguration |
|
184 | - * @category Security-Critical |
|
185 | - */ |
|
186 | - public function setNew($new) |
|
187 | - { |
|
188 | - $this->new = $new; |
|
189 | - |
|
190 | - return $this; |
|
191 | - } |
|
192 | - |
|
193 | - /** |
|
194 | - * @param boolean $requireIdentified |
|
195 | - */ |
|
196 | - public function setRequireIdentified($requireIdentified) |
|
197 | - { |
|
198 | - $this->requireIdentified = $requireIdentified; |
|
199 | - } |
|
18 | + const ALLOW = "allow"; |
|
19 | + const DENY = "deny"; |
|
20 | + private $admin = "default"; |
|
21 | + private $user = "default"; |
|
22 | + private $checkuser = "default"; |
|
23 | + private $community = "default"; |
|
24 | + private $suspended = "default"; |
|
25 | + private $declined = "default"; |
|
26 | + private $new = "default"; |
|
27 | + private $requireIdentified; |
|
28 | + |
|
29 | + /** |
|
30 | + * Sets whether a checkuser is able to gain access. |
|
31 | + * |
|
32 | + * This is private because it's DANGEROUS. Checkusers are not mutually-exclusive with other rights. As such, a |
|
33 | + * suspended checkuser who tries to access a page which allows checkusers will be granted access to the page, UNLESS |
|
34 | + * that page is also set to DENY (note, not default) New/Declined/Suspended users. I have no problem with this |
|
35 | + * method being used, but please ONLY use it in this class in static methods of Security. Nowhere else. |
|
36 | + * |
|
37 | + * @param string $checkuser |
|
38 | + * |
|
39 | + * @return SecurityConfiguration |
|
40 | + * @category Security-Critical |
|
41 | + */ |
|
42 | + public function setCheckuser($checkuser) |
|
43 | + { |
|
44 | + $this->checkuser = $checkuser; |
|
45 | + |
|
46 | + return $this; |
|
47 | + } |
|
48 | + |
|
49 | + /** |
|
50 | + * Returns if a user is required to be identified. |
|
51 | + * |
|
52 | + * @return boolean |
|
53 | + */ |
|
54 | + public function requiresIdentifiedUser() |
|
55 | + { |
|
56 | + return $this->requireIdentified; |
|
57 | + } |
|
58 | + |
|
59 | + /** |
|
60 | + * @return string |
|
61 | + */ |
|
62 | + public function getAdmin() |
|
63 | + { |
|
64 | + return $this->admin; |
|
65 | + } |
|
66 | + |
|
67 | + /** |
|
68 | + * @param string $admin |
|
69 | + * |
|
70 | + * @return SecurityConfiguration |
|
71 | + * @category Security-Critical |
|
72 | + */ |
|
73 | + public function setAdmin($admin) |
|
74 | + { |
|
75 | + $this->admin = $admin; |
|
76 | + |
|
77 | + return $this; |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * @return string |
|
82 | + */ |
|
83 | + public function getUser() |
|
84 | + { |
|
85 | + return $this->user; |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * @param string $user |
|
90 | + * |
|
91 | + * @return SecurityConfiguration |
|
92 | + * @category Security-Critical |
|
93 | + */ |
|
94 | + public function setUser($user) |
|
95 | + { |
|
96 | + $this->user = $user; |
|
97 | + |
|
98 | + return $this; |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * @return string |
|
103 | + */ |
|
104 | + public function getCheckuser() |
|
105 | + { |
|
106 | + return $this->checkuser; |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * @return string |
|
111 | + */ |
|
112 | + public function getCommunity() |
|
113 | + { |
|
114 | + return $this->community; |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * @param string $community |
|
119 | + * |
|
120 | + * @return SecurityConfiguration |
|
121 | + * @category Security-Critical |
|
122 | + */ |
|
123 | + public function setCommunity($community) |
|
124 | + { |
|
125 | + $this->community = $community; |
|
126 | + |
|
127 | + return $this; |
|
128 | + } |
|
129 | + |
|
130 | + /** |
|
131 | + * @return string |
|
132 | + */ |
|
133 | + public function getSuspended() |
|
134 | + { |
|
135 | + return $this->suspended; |
|
136 | + } |
|
137 | + |
|
138 | + /** |
|
139 | + * @param string $suspended |
|
140 | + * |
|
141 | + * @return SecurityConfiguration |
|
142 | + * @category Security-Critical |
|
143 | + */ |
|
144 | + public function setSuspended($suspended) |
|
145 | + { |
|
146 | + $this->suspended = $suspended; |
|
147 | + |
|
148 | + return $this; |
|
149 | + } |
|
150 | + |
|
151 | + /** |
|
152 | + * @return string |
|
153 | + */ |
|
154 | + public function getDeclined() |
|
155 | + { |
|
156 | + return $this->declined; |
|
157 | + } |
|
158 | + |
|
159 | + /** |
|
160 | + * @param string $declined |
|
161 | + * |
|
162 | + * @return SecurityConfiguration |
|
163 | + * @category Security-Critical |
|
164 | + */ |
|
165 | + public function setDeclined($declined) |
|
166 | + { |
|
167 | + $this->declined = $declined; |
|
168 | + |
|
169 | + return $this; |
|
170 | + } |
|
171 | + |
|
172 | + /** |
|
173 | + * @return string |
|
174 | + */ |
|
175 | + public function getNew() |
|
176 | + { |
|
177 | + return $this->new; |
|
178 | + } |
|
179 | + |
|
180 | + /** |
|
181 | + * @param string $new |
|
182 | + * |
|
183 | + * @return SecurityConfiguration |
|
184 | + * @category Security-Critical |
|
185 | + */ |
|
186 | + public function setNew($new) |
|
187 | + { |
|
188 | + $this->new = $new; |
|
189 | + |
|
190 | + return $this; |
|
191 | + } |
|
192 | + |
|
193 | + /** |
|
194 | + * @param boolean $requireIdentified |
|
195 | + */ |
|
196 | + public function setRequireIdentified($requireIdentified) |
|
197 | + { |
|
198 | + $this->requireIdentified = $requireIdentified; |
|
199 | + } |
|
200 | 200 | } |
201 | 201 | \ No newline at end of file |
@@ -14,84 +14,84 @@ |
||
14 | 14 | |
15 | 15 | final class SecurityManager |
16 | 16 | { |
17 | - /** @var IdentificationVerifier */ |
|
18 | - private $identificationVerifier; |
|
19 | - /** @var SecurityConfigurationFactory */ |
|
20 | - private $securityConfigurationFactory; |
|
17 | + /** @var IdentificationVerifier */ |
|
18 | + private $identificationVerifier; |
|
19 | + /** @var SecurityConfigurationFactory */ |
|
20 | + private $securityConfigurationFactory; |
|
21 | 21 | |
22 | - /** |
|
23 | - * SecurityManager constructor. |
|
24 | - * |
|
25 | - * @param IdentificationVerifier $identificationVerifier |
|
26 | - * @param bool $forceIdentification |
|
27 | - */ |
|
28 | - public function __construct(IdentificationVerifier $identificationVerifier, $forceIdentification) |
|
29 | - { |
|
30 | - $this->identificationVerifier = $identificationVerifier; |
|
22 | + /** |
|
23 | + * SecurityManager constructor. |
|
24 | + * |
|
25 | + * @param IdentificationVerifier $identificationVerifier |
|
26 | + * @param bool $forceIdentification |
|
27 | + */ |
|
28 | + public function __construct(IdentificationVerifier $identificationVerifier, $forceIdentification) |
|
29 | + { |
|
30 | + $this->identificationVerifier = $identificationVerifier; |
|
31 | 31 | |
32 | - $this->securityConfigurationFactory = new SecurityConfigurationFactory($forceIdentification); |
|
33 | - } |
|
32 | + $this->securityConfigurationFactory = new SecurityConfigurationFactory($forceIdentification); |
|
33 | + } |
|
34 | 34 | |
35 | - public function configure() |
|
36 | - { |
|
37 | - return $this->securityConfigurationFactory; |
|
38 | - } |
|
35 | + public function configure() |
|
36 | + { |
|
37 | + return $this->securityConfigurationFactory; |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * @param $value |
|
42 | - * @param $filter |
|
43 | - * |
|
44 | - * @return bool |
|
45 | - * @throws AccessDeniedException |
|
46 | - * @category Security-Critical |
|
47 | - */ |
|
48 | - private function test($value, $filter) |
|
49 | - { |
|
50 | - if (!$filter) { |
|
51 | - return false; |
|
52 | - } |
|
40 | + /** |
|
41 | + * @param $value |
|
42 | + * @param $filter |
|
43 | + * |
|
44 | + * @return bool |
|
45 | + * @throws AccessDeniedException |
|
46 | + * @category Security-Critical |
|
47 | + */ |
|
48 | + private function test($value, $filter) |
|
49 | + { |
|
50 | + if (!$filter) { |
|
51 | + return false; |
|
52 | + } |
|
53 | 53 | |
54 | - if ($value == SecurityConfiguration::DENY) { |
|
55 | - // FILE_NOT_FOUND...? |
|
56 | - throw new AccessDeniedException(); |
|
57 | - } |
|
54 | + if ($value == SecurityConfiguration::DENY) { |
|
55 | + // FILE_NOT_FOUND...? |
|
56 | + throw new AccessDeniedException(); |
|
57 | + } |
|
58 | 58 | |
59 | - return $value === SecurityConfiguration::ALLOW; |
|
60 | - } |
|
59 | + return $value === SecurityConfiguration::ALLOW; |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * Tests if a user is allowed to perform an action. |
|
64 | - * |
|
65 | - * This method should form a hard, deterministic security barrier, and only return true if it is absolutely sure |
|
66 | - * that a user should have access to something. |
|
67 | - * |
|
68 | - * @param SecurityConfiguration $config |
|
69 | - * @param User $user |
|
70 | - * |
|
71 | - * @return bool |
|
72 | - * |
|
73 | - * @category Security-Critical |
|
74 | - */ |
|
75 | - public function allows(SecurityConfiguration $config, User $user) |
|
76 | - { |
|
77 | - if ($config->requiresIdentifiedUser() && !$user->isCommunityUser() && !$user->isIdentified($this->identificationVerifier)) { |
|
78 | - return false; |
|
79 | - } |
|
62 | + /** |
|
63 | + * Tests if a user is allowed to perform an action. |
|
64 | + * |
|
65 | + * This method should form a hard, deterministic security barrier, and only return true if it is absolutely sure |
|
66 | + * that a user should have access to something. |
|
67 | + * |
|
68 | + * @param SecurityConfiguration $config |
|
69 | + * @param User $user |
|
70 | + * |
|
71 | + * @return bool |
|
72 | + * |
|
73 | + * @category Security-Critical |
|
74 | + */ |
|
75 | + public function allows(SecurityConfiguration $config, User $user) |
|
76 | + { |
|
77 | + if ($config->requiresIdentifiedUser() && !$user->isCommunityUser() && !$user->isIdentified($this->identificationVerifier)) { |
|
78 | + return false; |
|
79 | + } |
|
80 | 80 | |
81 | - try { |
|
82 | - $allowed = $this->test($config->getAdmin(), $user->isAdmin()) |
|
83 | - || $this->test($config->getUser(), $user->isUser()) |
|
84 | - || $this->test($config->getCommunity(), $user->isCommunityUser()) |
|
85 | - || $this->test($config->getSuspended(), $user->isSuspended()) |
|
86 | - || $this->test($config->getDeclined(), $user->isDeclined()) |
|
87 | - || $this->test($config->getNew(), $user->isNewUser()) |
|
88 | - || $this->test($config->getCheckuser(), $user->isCheckuser()); |
|
81 | + try { |
|
82 | + $allowed = $this->test($config->getAdmin(), $user->isAdmin()) |
|
83 | + || $this->test($config->getUser(), $user->isUser()) |
|
84 | + || $this->test($config->getCommunity(), $user->isCommunityUser()) |
|
85 | + || $this->test($config->getSuspended(), $user->isSuspended()) |
|
86 | + || $this->test($config->getDeclined(), $user->isDeclined()) |
|
87 | + || $this->test($config->getNew(), $user->isNewUser()) |
|
88 | + || $this->test($config->getCheckuser(), $user->isCheckuser()); |
|
89 | 89 | |
90 | - return $allowed; |
|
91 | - } |
|
92 | - catch (AccessDeniedException $ex) { |
|
93 | - // something is set to deny. |
|
94 | - return false; |
|
95 | - } |
|
96 | - } |
|
90 | + return $allowed; |
|
91 | + } |
|
92 | + catch (AccessDeniedException $ex) { |
|
93 | + // something is set to deny. |
|
94 | + return false; |
|
95 | + } |
|
96 | + } |
|
97 | 97 | } |
98 | 98 | \ No newline at end of file |
@@ -13,91 +13,91 @@ |
||
13 | 13 | |
14 | 14 | class TokenManager |
15 | 15 | { |
16 | - /** |
|
17 | - * Validates a CSRF token |
|
18 | - * |
|
19 | - * @param string $data The token data string itself |
|
20 | - * @param string|null $context Token context for extra validation |
|
21 | - * |
|
22 | - * @return bool |
|
23 | - */ |
|
24 | - public function validateToken($data, $context = null) |
|
25 | - { |
|
26 | - if (!is_string($data) || strlen($data) === 0) { |
|
27 | - // Nothing to validate |
|
28 | - return false; |
|
29 | - } |
|
30 | - |
|
31 | - $tokens = WebRequest::getSessionTokenData(); |
|
32 | - |
|
33 | - // if the token doesn't exist, then it's not valid |
|
34 | - if (!array_key_exists($data, $tokens)) { |
|
35 | - return false; |
|
36 | - } |
|
37 | - |
|
38 | - /** @var Token $token */ |
|
39 | - $token = unserialize($tokens[$data]); |
|
40 | - |
|
41 | - if ($token->getTokenData() !== $data) { |
|
42 | - return false; |
|
43 | - } |
|
44 | - |
|
45 | - if ($token->getContext() !== $context) { |
|
46 | - return false; |
|
47 | - } |
|
48 | - |
|
49 | - if ($token->isUsed()) { |
|
50 | - return false; |
|
51 | - } |
|
52 | - |
|
53 | - // mark the token as used, and save it back to the session |
|
54 | - $token->markAsUsed(); |
|
55 | - $this->storeToken($token); |
|
56 | - |
|
57 | - return true; |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * @param string|null $context An optional context for extra validation |
|
62 | - * |
|
63 | - * @return Token |
|
64 | - */ |
|
65 | - public function getNewToken($context = null) |
|
66 | - { |
|
67 | - $token = new Token($this->generateTokenData(), $context); |
|
68 | - $this->storeToken($token); |
|
69 | - |
|
70 | - return $token; |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * Stores a token in the session data |
|
75 | - * |
|
76 | - * @param Token $token |
|
77 | - */ |
|
78 | - private function storeToken(Token $token) |
|
79 | - { |
|
80 | - $tokens = WebRequest::getSessionTokenData(); |
|
81 | - $tokens[$token->getTokenData()] = serialize($token); |
|
82 | - WebRequest::setSessionTokenData($tokens); |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * Generates a security token |
|
87 | - * |
|
88 | - * @return string |
|
89 | - * @throws Exception |
|
90 | - * |
|
91 | - * @category Security-Critical |
|
92 | - */ |
|
93 | - private function generateTokenData() |
|
94 | - { |
|
95 | - $genBytes = openssl_random_pseudo_bytes(33); |
|
96 | - |
|
97 | - if ($genBytes !== false) { |
|
98 | - return base64_encode($genBytes); |
|
99 | - } |
|
100 | - |
|
101 | - throw new Exception('Unable to generate secure token.'); |
|
102 | - } |
|
16 | + /** |
|
17 | + * Validates a CSRF token |
|
18 | + * |
|
19 | + * @param string $data The token data string itself |
|
20 | + * @param string|null $context Token context for extra validation |
|
21 | + * |
|
22 | + * @return bool |
|
23 | + */ |
|
24 | + public function validateToken($data, $context = null) |
|
25 | + { |
|
26 | + if (!is_string($data) || strlen($data) === 0) { |
|
27 | + // Nothing to validate |
|
28 | + return false; |
|
29 | + } |
|
30 | + |
|
31 | + $tokens = WebRequest::getSessionTokenData(); |
|
32 | + |
|
33 | + // if the token doesn't exist, then it's not valid |
|
34 | + if (!array_key_exists($data, $tokens)) { |
|
35 | + return false; |
|
36 | + } |
|
37 | + |
|
38 | + /** @var Token $token */ |
|
39 | + $token = unserialize($tokens[$data]); |
|
40 | + |
|
41 | + if ($token->getTokenData() !== $data) { |
|
42 | + return false; |
|
43 | + } |
|
44 | + |
|
45 | + if ($token->getContext() !== $context) { |
|
46 | + return false; |
|
47 | + } |
|
48 | + |
|
49 | + if ($token->isUsed()) { |
|
50 | + return false; |
|
51 | + } |
|
52 | + |
|
53 | + // mark the token as used, and save it back to the session |
|
54 | + $token->markAsUsed(); |
|
55 | + $this->storeToken($token); |
|
56 | + |
|
57 | + return true; |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * @param string|null $context An optional context for extra validation |
|
62 | + * |
|
63 | + * @return Token |
|
64 | + */ |
|
65 | + public function getNewToken($context = null) |
|
66 | + { |
|
67 | + $token = new Token($this->generateTokenData(), $context); |
|
68 | + $this->storeToken($token); |
|
69 | + |
|
70 | + return $token; |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * Stores a token in the session data |
|
75 | + * |
|
76 | + * @param Token $token |
|
77 | + */ |
|
78 | + private function storeToken(Token $token) |
|
79 | + { |
|
80 | + $tokens = WebRequest::getSessionTokenData(); |
|
81 | + $tokens[$token->getTokenData()] = serialize($token); |
|
82 | + WebRequest::setSessionTokenData($tokens); |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * Generates a security token |
|
87 | + * |
|
88 | + * @return string |
|
89 | + * @throws Exception |
|
90 | + * |
|
91 | + * @category Security-Critical |
|
92 | + */ |
|
93 | + private function generateTokenData() |
|
94 | + { |
|
95 | + $genBytes = openssl_random_pseudo_bytes(33); |
|
96 | + |
|
97 | + if ($genBytes !== false) { |
|
98 | + return base64_encode($genBytes); |
|
99 | + } |
|
100 | + |
|
101 | + throw new Exception('Unable to generate secure token.'); |
|
102 | + } |
|
103 | 103 | } |
104 | 104 | \ No newline at end of file |
@@ -10,152 +10,152 @@ |
||
10 | 10 | |
11 | 11 | final class SecurityConfigurationFactory |
12 | 12 | { |
13 | - /** |
|
14 | - * @var bool |
|
15 | - */ |
|
16 | - private $forceIdentified; |
|
17 | - |
|
18 | - /** |
|
19 | - * Security constructor. |
|
20 | - * |
|
21 | - * @param bool $forceIdentified |
|
22 | - */ |
|
23 | - public function __construct($forceIdentified) |
|
24 | - { |
|
25 | - $this->forceIdentified = $forceIdentified; |
|
26 | - } |
|
27 | - |
|
28 | - /** |
|
29 | - * Returns a pre-built security configuration for an internal page. |
|
30 | - * |
|
31 | - * @category Security-Critical |
|
32 | - * @return SecurityConfiguration |
|
33 | - */ |
|
34 | - public function asInternalPage() |
|
35 | - { |
|
36 | - $config = new SecurityConfiguration(); |
|
37 | - $config->setAdmin(SecurityConfiguration::ALLOW) |
|
38 | - ->setUser(SecurityConfiguration::ALLOW); |
|
39 | - |
|
40 | - $config->setRequireIdentified($this->forceIdentified); |
|
41 | - |
|
42 | - return $config; |
|
43 | - } |
|
44 | - |
|
45 | - /** |
|
46 | - * Returns a pre-built security configuration for a tool admin only page. |
|
47 | - * |
|
48 | - * @category Security-Critical |
|
49 | - * @return SecurityConfiguration |
|
50 | - */ |
|
51 | - public function asAdminPage() |
|
52 | - { |
|
53 | - $config = new SecurityConfiguration(); |
|
54 | - $config->setAdmin(SecurityConfiguration::ALLOW); |
|
55 | - |
|
56 | - $config->setRequireIdentified($this->forceIdentified); |
|
57 | - |
|
58 | - return $config; |
|
59 | - } |
|
60 | - |
|
61 | - /** |
|
62 | - * Returns a pre-built security configuration for a page accessible to *ALL* logged in users, including suspended |
|
63 | - * and new users. This probably isn't the setting you want. |
|
64 | - * |
|
65 | - * @category Security-Critical |
|
66 | - * @return SecurityConfiguration |
|
67 | - */ |
|
68 | - public function asAllLoggedInUsersPage() |
|
69 | - { |
|
70 | - $config = new SecurityConfiguration(); |
|
71 | - $config->setAdmin(SecurityConfiguration::ALLOW) |
|
72 | - ->setUser(SecurityConfiguration::ALLOW) |
|
73 | - ->setDeclined(SecurityConfiguration::ALLOW) |
|
74 | - ->setNew(SecurityConfiguration::ALLOW) |
|
75 | - ->setSuspended(SecurityConfiguration::ALLOW); |
|
76 | - |
|
77 | - $config->setRequireIdentified($this->forceIdentified); |
|
78 | - |
|
79 | - return $config; |
|
80 | - } |
|
81 | - |
|
82 | - /** |
|
83 | - * @return SecurityConfiguration |
|
84 | - * @category Security-Critical |
|
85 | - */ |
|
86 | - public function asCheckUserData() |
|
87 | - { |
|
88 | - $config = new SecurityConfiguration(); |
|
89 | - $config->setCheckuser(SecurityConfiguration::ALLOW) |
|
90 | - ->setCommunity(SecurityConfiguration::DENY) |
|
91 | - ->setSuspended(SecurityConfiguration::DENY) |
|
92 | - ->setDeclined(SecurityConfiguration::DENY) |
|
93 | - ->setNew(SecurityConfiguration::DENY); |
|
94 | - |
|
95 | - $config->setRequireIdentified($this->forceIdentified); |
|
96 | - |
|
97 | - return $config; |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * Returns a pre-built security configuration for a public page. |
|
102 | - * |
|
103 | - * @category Security-Critical |
|
104 | - * @return SecurityConfiguration |
|
105 | - */ |
|
106 | - public function asPublicPage() |
|
107 | - { |
|
108 | - $config = new SecurityConfiguration(); |
|
109 | - $config->setAdmin(SecurityConfiguration::ALLOW) |
|
110 | - ->setUser(SecurityConfiguration::ALLOW) |
|
111 | - ->setCheckuser(SecurityConfiguration::ALLOW) |
|
112 | - ->setCommunity(SecurityConfiguration::ALLOW) |
|
113 | - ->setSuspended(SecurityConfiguration::ALLOW) |
|
114 | - ->setDeclined(SecurityConfiguration::ALLOW) |
|
115 | - ->setNew(SecurityConfiguration::ALLOW); |
|
116 | - |
|
117 | - // Public pages shouldn't be inaccessible to logged-in, unidentified users. |
|
118 | - // Otherwise, logged in but unidentified users can't even log out. |
|
119 | - $config->setRequireIdentified(false); |
|
120 | - |
|
121 | - return $config; |
|
122 | - } |
|
123 | - |
|
124 | - /** |
|
125 | - * Special case for zoom page private data. |
|
126 | - * |
|
127 | - * This will only return true if you are either a checkuser or a tool admin, taking special note of disabled |
|
128 | - * accounts which happen to be check users |
|
129 | - * |
|
130 | - * @return SecurityConfiguration |
|
131 | - */ |
|
132 | - public function asGeneralPrivateDataAccess() |
|
133 | - { |
|
134 | - $config = new SecurityConfiguration(); |
|
135 | - $config |
|
136 | - // Basic configuration, admins and check users allowed |
|
137 | - ->setAdmin(SecurityConfiguration::ALLOW) |
|
138 | - ->setCheckuser(SecurityConfiguration::ALLOW) |
|
139 | - // Deny these, even if they were allowed by the above |
|
140 | - ->setCommunity(SecurityConfiguration::DENY) |
|
141 | - ->setSuspended(SecurityConfiguration::DENY) |
|
142 | - ->setDeclined(SecurityConfiguration::DENY) |
|
143 | - ->setNew(SecurityConfiguration::DENY); |
|
144 | - |
|
145 | - // You must also be identified to access this data |
|
146 | - $config->setRequireIdentified($this->forceIdentified); |
|
147 | - |
|
148 | - return $config; |
|
149 | - } |
|
150 | - |
|
151 | - /** |
|
152 | - * @category Security-Critical |
|
153 | - * @return SecurityConfiguration |
|
154 | - */ |
|
155 | - public function asNone() |
|
156 | - { |
|
157 | - $config = new SecurityConfiguration(); |
|
158 | - |
|
159 | - return $config; |
|
160 | - } |
|
13 | + /** |
|
14 | + * @var bool |
|
15 | + */ |
|
16 | + private $forceIdentified; |
|
17 | + |
|
18 | + /** |
|
19 | + * Security constructor. |
|
20 | + * |
|
21 | + * @param bool $forceIdentified |
|
22 | + */ |
|
23 | + public function __construct($forceIdentified) |
|
24 | + { |
|
25 | + $this->forceIdentified = $forceIdentified; |
|
26 | + } |
|
27 | + |
|
28 | + /** |
|
29 | + * Returns a pre-built security configuration for an internal page. |
|
30 | + * |
|
31 | + * @category Security-Critical |
|
32 | + * @return SecurityConfiguration |
|
33 | + */ |
|
34 | + public function asInternalPage() |
|
35 | + { |
|
36 | + $config = new SecurityConfiguration(); |
|
37 | + $config->setAdmin(SecurityConfiguration::ALLOW) |
|
38 | + ->setUser(SecurityConfiguration::ALLOW); |
|
39 | + |
|
40 | + $config->setRequireIdentified($this->forceIdentified); |
|
41 | + |
|
42 | + return $config; |
|
43 | + } |
|
44 | + |
|
45 | + /** |
|
46 | + * Returns a pre-built security configuration for a tool admin only page. |
|
47 | + * |
|
48 | + * @category Security-Critical |
|
49 | + * @return SecurityConfiguration |
|
50 | + */ |
|
51 | + public function asAdminPage() |
|
52 | + { |
|
53 | + $config = new SecurityConfiguration(); |
|
54 | + $config->setAdmin(SecurityConfiguration::ALLOW); |
|
55 | + |
|
56 | + $config->setRequireIdentified($this->forceIdentified); |
|
57 | + |
|
58 | + return $config; |
|
59 | + } |
|
60 | + |
|
61 | + /** |
|
62 | + * Returns a pre-built security configuration for a page accessible to *ALL* logged in users, including suspended |
|
63 | + * and new users. This probably isn't the setting you want. |
|
64 | + * |
|
65 | + * @category Security-Critical |
|
66 | + * @return SecurityConfiguration |
|
67 | + */ |
|
68 | + public function asAllLoggedInUsersPage() |
|
69 | + { |
|
70 | + $config = new SecurityConfiguration(); |
|
71 | + $config->setAdmin(SecurityConfiguration::ALLOW) |
|
72 | + ->setUser(SecurityConfiguration::ALLOW) |
|
73 | + ->setDeclined(SecurityConfiguration::ALLOW) |
|
74 | + ->setNew(SecurityConfiguration::ALLOW) |
|
75 | + ->setSuspended(SecurityConfiguration::ALLOW); |
|
76 | + |
|
77 | + $config->setRequireIdentified($this->forceIdentified); |
|
78 | + |
|
79 | + return $config; |
|
80 | + } |
|
81 | + |
|
82 | + /** |
|
83 | + * @return SecurityConfiguration |
|
84 | + * @category Security-Critical |
|
85 | + */ |
|
86 | + public function asCheckUserData() |
|
87 | + { |
|
88 | + $config = new SecurityConfiguration(); |
|
89 | + $config->setCheckuser(SecurityConfiguration::ALLOW) |
|
90 | + ->setCommunity(SecurityConfiguration::DENY) |
|
91 | + ->setSuspended(SecurityConfiguration::DENY) |
|
92 | + ->setDeclined(SecurityConfiguration::DENY) |
|
93 | + ->setNew(SecurityConfiguration::DENY); |
|
94 | + |
|
95 | + $config->setRequireIdentified($this->forceIdentified); |
|
96 | + |
|
97 | + return $config; |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * Returns a pre-built security configuration for a public page. |
|
102 | + * |
|
103 | + * @category Security-Critical |
|
104 | + * @return SecurityConfiguration |
|
105 | + */ |
|
106 | + public function asPublicPage() |
|
107 | + { |
|
108 | + $config = new SecurityConfiguration(); |
|
109 | + $config->setAdmin(SecurityConfiguration::ALLOW) |
|
110 | + ->setUser(SecurityConfiguration::ALLOW) |
|
111 | + ->setCheckuser(SecurityConfiguration::ALLOW) |
|
112 | + ->setCommunity(SecurityConfiguration::ALLOW) |
|
113 | + ->setSuspended(SecurityConfiguration::ALLOW) |
|
114 | + ->setDeclined(SecurityConfiguration::ALLOW) |
|
115 | + ->setNew(SecurityConfiguration::ALLOW); |
|
116 | + |
|
117 | + // Public pages shouldn't be inaccessible to logged-in, unidentified users. |
|
118 | + // Otherwise, logged in but unidentified users can't even log out. |
|
119 | + $config->setRequireIdentified(false); |
|
120 | + |
|
121 | + return $config; |
|
122 | + } |
|
123 | + |
|
124 | + /** |
|
125 | + * Special case for zoom page private data. |
|
126 | + * |
|
127 | + * This will only return true if you are either a checkuser or a tool admin, taking special note of disabled |
|
128 | + * accounts which happen to be check users |
|
129 | + * |
|
130 | + * @return SecurityConfiguration |
|
131 | + */ |
|
132 | + public function asGeneralPrivateDataAccess() |
|
133 | + { |
|
134 | + $config = new SecurityConfiguration(); |
|
135 | + $config |
|
136 | + // Basic configuration, admins and check users allowed |
|
137 | + ->setAdmin(SecurityConfiguration::ALLOW) |
|
138 | + ->setCheckuser(SecurityConfiguration::ALLOW) |
|
139 | + // Deny these, even if they were allowed by the above |
|
140 | + ->setCommunity(SecurityConfiguration::DENY) |
|
141 | + ->setSuspended(SecurityConfiguration::DENY) |
|
142 | + ->setDeclined(SecurityConfiguration::DENY) |
|
143 | + ->setNew(SecurityConfiguration::DENY); |
|
144 | + |
|
145 | + // You must also be identified to access this data |
|
146 | + $config->setRequireIdentified($this->forceIdentified); |
|
147 | + |
|
148 | + return $config; |
|
149 | + } |
|
150 | + |
|
151 | + /** |
|
152 | + * @category Security-Critical |
|
153 | + * @return SecurityConfiguration |
|
154 | + */ |
|
155 | + public function asNone() |
|
156 | + { |
|
157 | + $config = new SecurityConfiguration(); |
|
158 | + |
|
159 | + return $config; |
|
160 | + } |
|
161 | 161 | } |
162 | 162 | \ No newline at end of file |
@@ -20,43 +20,43 @@ |
||
20 | 20 | |
21 | 21 | class ApiRequestRouter implements IRequestRouter |
22 | 22 | { |
23 | - /** |
|
24 | - * @return string[] |
|
25 | - */ |
|
26 | - public static function getActionList() |
|
27 | - { |
|
28 | - return array("count", "status", "stats", "help", "monitor"); |
|
29 | - } |
|
23 | + /** |
|
24 | + * @return string[] |
|
25 | + */ |
|
26 | + public static function getActionList() |
|
27 | + { |
|
28 | + return array("count", "status", "stats", "help", "monitor"); |
|
29 | + } |
|
30 | 30 | |
31 | - /** |
|
32 | - * @return IRoutedTask |
|
33 | - * @throws Exception |
|
34 | - */ |
|
35 | - public function route() |
|
36 | - { |
|
37 | - $requestAction = WebRequest::getString('action'); |
|
31 | + /** |
|
32 | + * @return IRoutedTask |
|
33 | + * @throws Exception |
|
34 | + */ |
|
35 | + public function route() |
|
36 | + { |
|
37 | + $requestAction = WebRequest::getString('action'); |
|
38 | 38 | |
39 | - switch ($requestAction) { |
|
40 | - case "count": |
|
41 | - $result = new CountAction(); |
|
42 | - break; |
|
43 | - case "status": |
|
44 | - $result = new StatusAction(); |
|
45 | - break; |
|
46 | - case "stats": |
|
47 | - $result = new StatsAction(); |
|
48 | - break; |
|
49 | - case "help": |
|
50 | - $result = new HelpAction(); |
|
51 | - break; |
|
52 | - case "monitor": |
|
53 | - $result = new MonitorAction(); |
|
54 | - break; |
|
55 | - default: |
|
56 | - $result = new UnknownAction(); |
|
57 | - break; |
|
58 | - } |
|
39 | + switch ($requestAction) { |
|
40 | + case "count": |
|
41 | + $result = new CountAction(); |
|
42 | + break; |
|
43 | + case "status": |
|
44 | + $result = new StatusAction(); |
|
45 | + break; |
|
46 | + case "stats": |
|
47 | + $result = new StatsAction(); |
|
48 | + break; |
|
49 | + case "help": |
|
50 | + $result = new HelpAction(); |
|
51 | + break; |
|
52 | + case "monitor": |
|
53 | + $result = new MonitorAction(); |
|
54 | + break; |
|
55 | + default: |
|
56 | + $result = new UnknownAction(); |
|
57 | + break; |
|
58 | + } |
|
59 | 59 | |
60 | - return $result; |
|
61 | - } |
|
60 | + return $result; |
|
61 | + } |
|
62 | 62 | } |
63 | 63 | \ No newline at end of file |
@@ -17,9 +17,9 @@ |
||
17 | 17 | */ |
18 | 18 | class OAuthRequestRouter extends RequestRouter |
19 | 19 | { |
20 | - protected function getRouteFromPath($pathInfo) |
|
21 | - { |
|
22 | - // Hardcode the route for this entry point |
|
23 | - return array(PageOAuth::class, 'callback'); |
|
24 | - } |
|
20 | + protected function getRouteFromPath($pathInfo) |
|
21 | + { |
|
22 | + // Hardcode the route for this entry point |
|
23 | + return array(PageOAuth::class, 'callback'); |
|
24 | + } |
|
25 | 25 | } |
26 | 26 | \ No newline at end of file |
@@ -18,9 +18,9 @@ |
||
18 | 18 | */ |
19 | 19 | interface IRequestRouter |
20 | 20 | { |
21 | - /** |
|
22 | - * @return IRoutedTask |
|
23 | - * @throws Exception |
|
24 | - */ |
|
25 | - public function route(); |
|
21 | + /** |
|
22 | + * @return IRoutedTask |
|
23 | + * @throws Exception |
|
24 | + */ |
|
25 | + public function route(); |
|
26 | 26 | } |
27 | 27 | \ No newline at end of file |