@@ -16,50 +16,50 @@ |
||
16 | 16 | */ |
17 | 17 | interface BackendInterface |
18 | 18 | { |
19 | - /** |
|
20 | - * When this method is called, the backend must check if authentication was |
|
21 | - * successful. |
|
22 | - * |
|
23 | - * The returned value must be one of the following |
|
24 | - * |
|
25 | - * [true, "principals/username"] |
|
26 | - * [false, "reason for failure"] |
|
27 | - * |
|
28 | - * If authentication was successful, it's expected that the authentication |
|
29 | - * backend returns a so-called principal url. |
|
30 | - * |
|
31 | - * Examples of a principal url: |
|
32 | - * |
|
33 | - * principals/admin |
|
34 | - * principals/user1 |
|
35 | - * principals/users/joe |
|
36 | - * principals/uid/123457 |
|
37 | - * |
|
38 | - * If you don't use WebDAV ACL (RFC3744) we recommend that you simply |
|
39 | - * return a string such as: |
|
40 | - * |
|
41 | - * principals/users/[username] |
|
42 | - * |
|
43 | - * @return array |
|
44 | - */ |
|
45 | - public function check(RequestInterface $request, ResponseInterface $response); |
|
19 | + /** |
|
20 | + * When this method is called, the backend must check if authentication was |
|
21 | + * successful. |
|
22 | + * |
|
23 | + * The returned value must be one of the following |
|
24 | + * |
|
25 | + * [true, "principals/username"] |
|
26 | + * [false, "reason for failure"] |
|
27 | + * |
|
28 | + * If authentication was successful, it's expected that the authentication |
|
29 | + * backend returns a so-called principal url. |
|
30 | + * |
|
31 | + * Examples of a principal url: |
|
32 | + * |
|
33 | + * principals/admin |
|
34 | + * principals/user1 |
|
35 | + * principals/users/joe |
|
36 | + * principals/uid/123457 |
|
37 | + * |
|
38 | + * If you don't use WebDAV ACL (RFC3744) we recommend that you simply |
|
39 | + * return a string such as: |
|
40 | + * |
|
41 | + * principals/users/[username] |
|
42 | + * |
|
43 | + * @return array |
|
44 | + */ |
|
45 | + public function check(RequestInterface $request, ResponseInterface $response); |
|
46 | 46 | |
47 | - /** |
|
48 | - * This method is called when a user could not be authenticated, and |
|
49 | - * authentication was required for the current request. |
|
50 | - * |
|
51 | - * This gives you the opportunity to set authentication headers. The 401 |
|
52 | - * status code will already be set. |
|
53 | - * |
|
54 | - * In this case of Basic Auth, this would for example mean that the |
|
55 | - * following header needs to be set: |
|
56 | - * |
|
57 | - * $response->addHeader('WWW-Authenticate', 'Basic realm=SabreDAV'); |
|
58 | - * |
|
59 | - * Keep in mind that in the case of multiple authentication backends, other |
|
60 | - * WWW-Authenticate headers may already have been set, and you'll want to |
|
61 | - * append your own WWW-Authenticate header instead of overwriting the |
|
62 | - * existing one. |
|
63 | - */ |
|
64 | - public function challenge(RequestInterface $request, ResponseInterface $response); |
|
47 | + /** |
|
48 | + * This method is called when a user could not be authenticated, and |
|
49 | + * authentication was required for the current request. |
|
50 | + * |
|
51 | + * This gives you the opportunity to set authentication headers. The 401 |
|
52 | + * status code will already be set. |
|
53 | + * |
|
54 | + * In this case of Basic Auth, this would for example mean that the |
|
55 | + * following header needs to be set: |
|
56 | + * |
|
57 | + * $response->addHeader('WWW-Authenticate', 'Basic realm=SabreDAV'); |
|
58 | + * |
|
59 | + * Keep in mind that in the case of multiple authentication backends, other |
|
60 | + * WWW-Authenticate headers may already have been set, and you'll want to |
|
61 | + * append your own WWW-Authenticate header instead of overwriting the |
|
62 | + * existing one. |
|
63 | + */ |
|
64 | + public function challenge(RequestInterface $request, ResponseInterface $response); |
|
65 | 65 | } |
@@ -18,39 +18,39 @@ |
||
18 | 18 | */ |
19 | 19 | class BasicCallBack extends AbstractBasic |
20 | 20 | { |
21 | - /** |
|
22 | - * Callback. |
|
23 | - * |
|
24 | - * @var callable |
|
25 | - */ |
|
26 | - protected $callBack; |
|
21 | + /** |
|
22 | + * Callback. |
|
23 | + * |
|
24 | + * @var callable |
|
25 | + */ |
|
26 | + protected $callBack; |
|
27 | 27 | |
28 | - /** |
|
29 | - * Creates the backend. |
|
30 | - * |
|
31 | - * A callback must be provided to handle checking the username and |
|
32 | - * password. |
|
33 | - */ |
|
34 | - public function __construct(callable $callBack) |
|
35 | - { |
|
36 | - $this->callBack = $callBack; |
|
37 | - } |
|
28 | + /** |
|
29 | + * Creates the backend. |
|
30 | + * |
|
31 | + * A callback must be provided to handle checking the username and |
|
32 | + * password. |
|
33 | + */ |
|
34 | + public function __construct(callable $callBack) |
|
35 | + { |
|
36 | + $this->callBack = $callBack; |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * Validates a username and password. |
|
41 | - * |
|
42 | - * This method should return true or false depending on if login |
|
43 | - * succeeded. |
|
44 | - * |
|
45 | - * @param string $username |
|
46 | - * @param string $password |
|
47 | - * |
|
48 | - * @return bool |
|
49 | - */ |
|
50 | - protected function validateUserPass($username, $password) |
|
51 | - { |
|
52 | - $cb = $this->callBack; |
|
39 | + /** |
|
40 | + * Validates a username and password. |
|
41 | + * |
|
42 | + * This method should return true or false depending on if login |
|
43 | + * succeeded. |
|
44 | + * |
|
45 | + * @param string $username |
|
46 | + * @param string $password |
|
47 | + * |
|
48 | + * @return bool |
|
49 | + */ |
|
50 | + protected function validateUserPass($username, $password) |
|
51 | + { |
|
52 | + $cb = $this->callBack; |
|
53 | 53 | |
54 | - return $cb($username, $password); |
|
55 | - } |
|
54 | + return $cb($username, $password); |
|
55 | + } |
|
56 | 56 | } |
@@ -22,115 +22,115 @@ |
||
22 | 22 | */ |
23 | 23 | abstract class AbstractBasic implements BackendInterface |
24 | 24 | { |
25 | - /** |
|
26 | - * Authentication Realm. |
|
27 | - * |
|
28 | - * The realm is often displayed by browser clients when showing the |
|
29 | - * authentication dialog. |
|
30 | - * |
|
31 | - * @var string |
|
32 | - */ |
|
33 | - protected $realm = 'sabre/dav'; |
|
25 | + /** |
|
26 | + * Authentication Realm. |
|
27 | + * |
|
28 | + * The realm is often displayed by browser clients when showing the |
|
29 | + * authentication dialog. |
|
30 | + * |
|
31 | + * @var string |
|
32 | + */ |
|
33 | + protected $realm = 'sabre/dav'; |
|
34 | 34 | |
35 | - /** |
|
36 | - * This is the prefix that will be used to generate principal urls. |
|
37 | - * |
|
38 | - * @var string |
|
39 | - */ |
|
40 | - protected $principalPrefix = 'principals/'; |
|
35 | + /** |
|
36 | + * This is the prefix that will be used to generate principal urls. |
|
37 | + * |
|
38 | + * @var string |
|
39 | + */ |
|
40 | + protected $principalPrefix = 'principals/'; |
|
41 | 41 | |
42 | - /** |
|
43 | - * Validates a username and password. |
|
44 | - * |
|
45 | - * This method should return true or false depending on if login |
|
46 | - * succeeded. |
|
47 | - * |
|
48 | - * @param string $username |
|
49 | - * @param string $password |
|
50 | - * |
|
51 | - * @return bool |
|
52 | - */ |
|
53 | - abstract protected function validateUserPass($username, $password); |
|
42 | + /** |
|
43 | + * Validates a username and password. |
|
44 | + * |
|
45 | + * This method should return true or false depending on if login |
|
46 | + * succeeded. |
|
47 | + * |
|
48 | + * @param string $username |
|
49 | + * @param string $password |
|
50 | + * |
|
51 | + * @return bool |
|
52 | + */ |
|
53 | + abstract protected function validateUserPass($username, $password); |
|
54 | 54 | |
55 | - /** |
|
56 | - * Sets the authentication realm for this backend. |
|
57 | - * |
|
58 | - * @param string $realm |
|
59 | - */ |
|
60 | - public function setRealm($realm) |
|
61 | - { |
|
62 | - $this->realm = $realm; |
|
63 | - } |
|
55 | + /** |
|
56 | + * Sets the authentication realm for this backend. |
|
57 | + * |
|
58 | + * @param string $realm |
|
59 | + */ |
|
60 | + public function setRealm($realm) |
|
61 | + { |
|
62 | + $this->realm = $realm; |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * When this method is called, the backend must check if authentication was |
|
67 | - * successful. |
|
68 | - * |
|
69 | - * The returned value must be one of the following |
|
70 | - * |
|
71 | - * [true, "principals/username"] |
|
72 | - * [false, "reason for failure"] |
|
73 | - * |
|
74 | - * If authentication was successful, it's expected that the authentication |
|
75 | - * backend returns a so-called principal url. |
|
76 | - * |
|
77 | - * Examples of a principal url: |
|
78 | - * |
|
79 | - * principals/admin |
|
80 | - * principals/user1 |
|
81 | - * principals/users/joe |
|
82 | - * principals/uid/123457 |
|
83 | - * |
|
84 | - * If you don't use WebDAV ACL (RFC3744) we recommend that you simply |
|
85 | - * return a string such as: |
|
86 | - * |
|
87 | - * principals/users/[username] |
|
88 | - * |
|
89 | - * @return array |
|
90 | - */ |
|
91 | - public function check(RequestInterface $request, ResponseInterface $response) |
|
92 | - { |
|
93 | - $auth = new HTTP\Auth\Basic( |
|
94 | - $this->realm, |
|
95 | - $request, |
|
96 | - $response |
|
97 | - ); |
|
65 | + /** |
|
66 | + * When this method is called, the backend must check if authentication was |
|
67 | + * successful. |
|
68 | + * |
|
69 | + * The returned value must be one of the following |
|
70 | + * |
|
71 | + * [true, "principals/username"] |
|
72 | + * [false, "reason for failure"] |
|
73 | + * |
|
74 | + * If authentication was successful, it's expected that the authentication |
|
75 | + * backend returns a so-called principal url. |
|
76 | + * |
|
77 | + * Examples of a principal url: |
|
78 | + * |
|
79 | + * principals/admin |
|
80 | + * principals/user1 |
|
81 | + * principals/users/joe |
|
82 | + * principals/uid/123457 |
|
83 | + * |
|
84 | + * If you don't use WebDAV ACL (RFC3744) we recommend that you simply |
|
85 | + * return a string such as: |
|
86 | + * |
|
87 | + * principals/users/[username] |
|
88 | + * |
|
89 | + * @return array |
|
90 | + */ |
|
91 | + public function check(RequestInterface $request, ResponseInterface $response) |
|
92 | + { |
|
93 | + $auth = new HTTP\Auth\Basic( |
|
94 | + $this->realm, |
|
95 | + $request, |
|
96 | + $response |
|
97 | + ); |
|
98 | 98 | |
99 | - $userpass = $auth->getCredentials(); |
|
100 | - if (!$userpass) { |
|
101 | - return [false, "No 'Authorization: Basic' header found. Either the client didn't send one, or the server is misconfigured"]; |
|
102 | - } |
|
103 | - if (!$this->validateUserPass($userpass[0], $userpass[1])) { |
|
104 | - return [false, 'Username or password was incorrect']; |
|
105 | - } |
|
99 | + $userpass = $auth->getCredentials(); |
|
100 | + if (!$userpass) { |
|
101 | + return [false, "No 'Authorization: Basic' header found. Either the client didn't send one, or the server is misconfigured"]; |
|
102 | + } |
|
103 | + if (!$this->validateUserPass($userpass[0], $userpass[1])) { |
|
104 | + return [false, 'Username or password was incorrect']; |
|
105 | + } |
|
106 | 106 | |
107 | - return [true, $this->principalPrefix.$userpass[0]]; |
|
108 | - } |
|
107 | + return [true, $this->principalPrefix.$userpass[0]]; |
|
108 | + } |
|
109 | 109 | |
110 | - /** |
|
111 | - * This method is called when a user could not be authenticated, and |
|
112 | - * authentication was required for the current request. |
|
113 | - * |
|
114 | - * This gives you the opportunity to set authentication headers. The 401 |
|
115 | - * status code will already be set. |
|
116 | - * |
|
117 | - * In this case of Basic Auth, this would for example mean that the |
|
118 | - * following header needs to be set: |
|
119 | - * |
|
120 | - * $response->addHeader('WWW-Authenticate', 'Basic realm=SabreDAV'); |
|
121 | - * |
|
122 | - * Keep in mind that in the case of multiple authentication backends, other |
|
123 | - * WWW-Authenticate headers may already have been set, and you'll want to |
|
124 | - * append your own WWW-Authenticate header instead of overwriting the |
|
125 | - * existing one. |
|
126 | - */ |
|
127 | - public function challenge(RequestInterface $request, ResponseInterface $response) |
|
128 | - { |
|
129 | - $auth = new HTTP\Auth\Basic( |
|
130 | - $this->realm, |
|
131 | - $request, |
|
132 | - $response |
|
133 | - ); |
|
134 | - $auth->requireLogin(); |
|
135 | - } |
|
110 | + /** |
|
111 | + * This method is called when a user could not be authenticated, and |
|
112 | + * authentication was required for the current request. |
|
113 | + * |
|
114 | + * This gives you the opportunity to set authentication headers. The 401 |
|
115 | + * status code will already be set. |
|
116 | + * |
|
117 | + * In this case of Basic Auth, this would for example mean that the |
|
118 | + * following header needs to be set: |
|
119 | + * |
|
120 | + * $response->addHeader('WWW-Authenticate', 'Basic realm=SabreDAV'); |
|
121 | + * |
|
122 | + * Keep in mind that in the case of multiple authentication backends, other |
|
123 | + * WWW-Authenticate headers may already have been set, and you'll want to |
|
124 | + * append your own WWW-Authenticate header instead of overwriting the |
|
125 | + * existing one. |
|
126 | + */ |
|
127 | + public function challenge(RequestInterface $request, ResponseInterface $response) |
|
128 | + { |
|
129 | + $auth = new HTTP\Auth\Basic( |
|
130 | + $this->realm, |
|
131 | + $request, |
|
132 | + $response |
|
133 | + ); |
|
134 | + $auth->requireLogin(); |
|
135 | + } |
|
136 | 136 | } |
@@ -22,139 +22,139 @@ |
||
22 | 22 | */ |
23 | 23 | abstract class AbstractDigest implements BackendInterface |
24 | 24 | { |
25 | - /** |
|
26 | - * Authentication Realm. |
|
27 | - * |
|
28 | - * The realm is often displayed by browser clients when showing the |
|
29 | - * authentication dialog. |
|
30 | - * |
|
31 | - * @var string |
|
32 | - */ |
|
33 | - protected $realm = 'SabreDAV'; |
|
34 | - |
|
35 | - /** |
|
36 | - * This is the prefix that will be used to generate principal urls. |
|
37 | - * |
|
38 | - * @var string |
|
39 | - */ |
|
40 | - protected $principalPrefix = 'principals/'; |
|
41 | - |
|
42 | - /** |
|
43 | - * Sets the authentication realm for this backend. |
|
44 | - * |
|
45 | - * Be aware that for Digest authentication, the realm influences the digest |
|
46 | - * hash. Choose the realm wisely, because if you change it later, all the |
|
47 | - * existing hashes will break and nobody can authenticate. |
|
48 | - * |
|
49 | - * @param string $realm |
|
50 | - */ |
|
51 | - public function setRealm($realm) |
|
52 | - { |
|
53 | - $this->realm = $realm; |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * Returns a users digest hash based on the username and realm. |
|
58 | - * |
|
59 | - * If the user was not known, null must be returned. |
|
60 | - * |
|
61 | - * @param string $realm |
|
62 | - * @param string $username |
|
63 | - * |
|
64 | - * @return string|null |
|
65 | - */ |
|
66 | - abstract public function getDigestHash($realm, $username); |
|
67 | - |
|
68 | - /** |
|
69 | - * When this method is called, the backend must check if authentication was |
|
70 | - * successful. |
|
71 | - * |
|
72 | - * The returned value must be one of the following |
|
73 | - * |
|
74 | - * [true, "principals/username"] |
|
75 | - * [false, "reason for failure"] |
|
76 | - * |
|
77 | - * If authentication was successful, it's expected that the authentication |
|
78 | - * backend returns a so-called principal url. |
|
79 | - * |
|
80 | - * Examples of a principal url: |
|
81 | - * |
|
82 | - * principals/admin |
|
83 | - * principals/user1 |
|
84 | - * principals/users/joe |
|
85 | - * principals/uid/123457 |
|
86 | - * |
|
87 | - * If you don't use WebDAV ACL (RFC3744) we recommend that you simply |
|
88 | - * return a string such as: |
|
89 | - * |
|
90 | - * principals/users/[username] |
|
91 | - * |
|
92 | - * @return array |
|
93 | - */ |
|
94 | - public function check(RequestInterface $request, ResponseInterface $response) |
|
95 | - { |
|
96 | - $digest = new HTTP\Auth\Digest( |
|
97 | - $this->realm, |
|
98 | - $request, |
|
99 | - $response |
|
100 | - ); |
|
101 | - $digest->init(); |
|
102 | - |
|
103 | - $username = $digest->getUsername(); |
|
104 | - |
|
105 | - // No username was given |
|
106 | - if (!$username) { |
|
107 | - return [false, "No 'Authorization: Digest' header found. Either the client didn't send one, or the server is misconfigured"]; |
|
108 | - } |
|
109 | - |
|
110 | - $hash = $this->getDigestHash($this->realm, $username); |
|
111 | - // If this was false, the user account didn't exist |
|
112 | - if (false === $hash || is_null($hash)) { |
|
113 | - return [false, 'Username or password was incorrect']; |
|
114 | - } |
|
115 | - if (!is_string($hash)) { |
|
116 | - throw new DAV\Exception('The returned value from getDigestHash must be a string or null'); |
|
117 | - } |
|
118 | - |
|
119 | - // If this was false, the password or part of the hash was incorrect. |
|
120 | - if (!$digest->validateA1($hash)) { |
|
121 | - return [false, 'Username or password was incorrect']; |
|
122 | - } |
|
123 | - |
|
124 | - return [true, $this->principalPrefix.$username]; |
|
125 | - } |
|
126 | - |
|
127 | - /** |
|
128 | - * This method is called when a user could not be authenticated, and |
|
129 | - * authentication was required for the current request. |
|
130 | - * |
|
131 | - * This gives you the opportunity to set authentication headers. The 401 |
|
132 | - * status code will already be set. |
|
133 | - * |
|
134 | - * In this case of Basic Auth, this would for example mean that the |
|
135 | - * following header needs to be set: |
|
136 | - * |
|
137 | - * $response->addHeader('WWW-Authenticate', 'Basic realm=SabreDAV'); |
|
138 | - * |
|
139 | - * Keep in mind that in the case of multiple authentication backends, other |
|
140 | - * WWW-Authenticate headers may already have been set, and you'll want to |
|
141 | - * append your own WWW-Authenticate header instead of overwriting the |
|
142 | - * existing one. |
|
143 | - */ |
|
144 | - public function challenge(RequestInterface $request, ResponseInterface $response) |
|
145 | - { |
|
146 | - $auth = new HTTP\Auth\Digest( |
|
147 | - $this->realm, |
|
148 | - $request, |
|
149 | - $response |
|
150 | - ); |
|
151 | - $auth->init(); |
|
152 | - |
|
153 | - $oldStatus = $response->getStatus() ?: 200; |
|
154 | - $auth->requireLogin(); |
|
155 | - |
|
156 | - // Preventing the digest utility from modifying the http status code, |
|
157 | - // this should be handled by the main plugin. |
|
158 | - $response->setStatus($oldStatus); |
|
159 | - } |
|
25 | + /** |
|
26 | + * Authentication Realm. |
|
27 | + * |
|
28 | + * The realm is often displayed by browser clients when showing the |
|
29 | + * authentication dialog. |
|
30 | + * |
|
31 | + * @var string |
|
32 | + */ |
|
33 | + protected $realm = 'SabreDAV'; |
|
34 | + |
|
35 | + /** |
|
36 | + * This is the prefix that will be used to generate principal urls. |
|
37 | + * |
|
38 | + * @var string |
|
39 | + */ |
|
40 | + protected $principalPrefix = 'principals/'; |
|
41 | + |
|
42 | + /** |
|
43 | + * Sets the authentication realm for this backend. |
|
44 | + * |
|
45 | + * Be aware that for Digest authentication, the realm influences the digest |
|
46 | + * hash. Choose the realm wisely, because if you change it later, all the |
|
47 | + * existing hashes will break and nobody can authenticate. |
|
48 | + * |
|
49 | + * @param string $realm |
|
50 | + */ |
|
51 | + public function setRealm($realm) |
|
52 | + { |
|
53 | + $this->realm = $realm; |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * Returns a users digest hash based on the username and realm. |
|
58 | + * |
|
59 | + * If the user was not known, null must be returned. |
|
60 | + * |
|
61 | + * @param string $realm |
|
62 | + * @param string $username |
|
63 | + * |
|
64 | + * @return string|null |
|
65 | + */ |
|
66 | + abstract public function getDigestHash($realm, $username); |
|
67 | + |
|
68 | + /** |
|
69 | + * When this method is called, the backend must check if authentication was |
|
70 | + * successful. |
|
71 | + * |
|
72 | + * The returned value must be one of the following |
|
73 | + * |
|
74 | + * [true, "principals/username"] |
|
75 | + * [false, "reason for failure"] |
|
76 | + * |
|
77 | + * If authentication was successful, it's expected that the authentication |
|
78 | + * backend returns a so-called principal url. |
|
79 | + * |
|
80 | + * Examples of a principal url: |
|
81 | + * |
|
82 | + * principals/admin |
|
83 | + * principals/user1 |
|
84 | + * principals/users/joe |
|
85 | + * principals/uid/123457 |
|
86 | + * |
|
87 | + * If you don't use WebDAV ACL (RFC3744) we recommend that you simply |
|
88 | + * return a string such as: |
|
89 | + * |
|
90 | + * principals/users/[username] |
|
91 | + * |
|
92 | + * @return array |
|
93 | + */ |
|
94 | + public function check(RequestInterface $request, ResponseInterface $response) |
|
95 | + { |
|
96 | + $digest = new HTTP\Auth\Digest( |
|
97 | + $this->realm, |
|
98 | + $request, |
|
99 | + $response |
|
100 | + ); |
|
101 | + $digest->init(); |
|
102 | + |
|
103 | + $username = $digest->getUsername(); |
|
104 | + |
|
105 | + // No username was given |
|
106 | + if (!$username) { |
|
107 | + return [false, "No 'Authorization: Digest' header found. Either the client didn't send one, or the server is misconfigured"]; |
|
108 | + } |
|
109 | + |
|
110 | + $hash = $this->getDigestHash($this->realm, $username); |
|
111 | + // If this was false, the user account didn't exist |
|
112 | + if (false === $hash || is_null($hash)) { |
|
113 | + return [false, 'Username or password was incorrect']; |
|
114 | + } |
|
115 | + if (!is_string($hash)) { |
|
116 | + throw new DAV\Exception('The returned value from getDigestHash must be a string or null'); |
|
117 | + } |
|
118 | + |
|
119 | + // If this was false, the password or part of the hash was incorrect. |
|
120 | + if (!$digest->validateA1($hash)) { |
|
121 | + return [false, 'Username or password was incorrect']; |
|
122 | + } |
|
123 | + |
|
124 | + return [true, $this->principalPrefix.$username]; |
|
125 | + } |
|
126 | + |
|
127 | + /** |
|
128 | + * This method is called when a user could not be authenticated, and |
|
129 | + * authentication was required for the current request. |
|
130 | + * |
|
131 | + * This gives you the opportunity to set authentication headers. The 401 |
|
132 | + * status code will already be set. |
|
133 | + * |
|
134 | + * In this case of Basic Auth, this would for example mean that the |
|
135 | + * following header needs to be set: |
|
136 | + * |
|
137 | + * $response->addHeader('WWW-Authenticate', 'Basic realm=SabreDAV'); |
|
138 | + * |
|
139 | + * Keep in mind that in the case of multiple authentication backends, other |
|
140 | + * WWW-Authenticate headers may already have been set, and you'll want to |
|
141 | + * append your own WWW-Authenticate header instead of overwriting the |
|
142 | + * existing one. |
|
143 | + */ |
|
144 | + public function challenge(RequestInterface $request, ResponseInterface $response) |
|
145 | + { |
|
146 | + $auth = new HTTP\Auth\Digest( |
|
147 | + $this->realm, |
|
148 | + $request, |
|
149 | + $response |
|
150 | + ); |
|
151 | + $auth->init(); |
|
152 | + |
|
153 | + $oldStatus = $response->getStatus() ?: 200; |
|
154 | + $auth->requireLogin(); |
|
155 | + |
|
156 | + // Preventing the digest utility from modifying the http status code, |
|
157 | + // this should be handled by the main plugin. |
|
158 | + $response->setStatus($oldStatus); |
|
159 | + } |
|
160 | 160 | } |
@@ -17,58 +17,58 @@ |
||
17 | 17 | */ |
18 | 18 | class File extends AbstractDigest |
19 | 19 | { |
20 | - /** |
|
21 | - * List of users. |
|
22 | - * |
|
23 | - * @var array |
|
24 | - */ |
|
25 | - protected $users = []; |
|
20 | + /** |
|
21 | + * List of users. |
|
22 | + * |
|
23 | + * @var array |
|
24 | + */ |
|
25 | + protected $users = []; |
|
26 | 26 | |
27 | - /** |
|
28 | - * Creates the backend object. |
|
29 | - * |
|
30 | - * If the filename argument is passed in, it will parse out the specified file first. |
|
31 | - * |
|
32 | - * @param string|null $filename |
|
33 | - */ |
|
34 | - public function __construct($filename = null) |
|
35 | - { |
|
36 | - if (!is_null($filename)) { |
|
37 | - $this->loadFile($filename); |
|
38 | - } |
|
39 | - } |
|
27 | + /** |
|
28 | + * Creates the backend object. |
|
29 | + * |
|
30 | + * If the filename argument is passed in, it will parse out the specified file first. |
|
31 | + * |
|
32 | + * @param string|null $filename |
|
33 | + */ |
|
34 | + public function __construct($filename = null) |
|
35 | + { |
|
36 | + if (!is_null($filename)) { |
|
37 | + $this->loadFile($filename); |
|
38 | + } |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * Loads an htdigest-formatted file. This method can be called multiple times if |
|
43 | - * more than 1 file is used. |
|
44 | - * |
|
45 | - * @param string $filename |
|
46 | - */ |
|
47 | - public function loadFile($filename) |
|
48 | - { |
|
49 | - foreach (file($filename, FILE_IGNORE_NEW_LINES) as $line) { |
|
50 | - if (2 !== substr_count($line, ':')) { |
|
51 | - throw new DAV\Exception('Malformed htdigest file. Every line should contain 2 colons'); |
|
52 | - } |
|
53 | - list($username, $realm, $A1) = explode(':', $line); |
|
41 | + /** |
|
42 | + * Loads an htdigest-formatted file. This method can be called multiple times if |
|
43 | + * more than 1 file is used. |
|
44 | + * |
|
45 | + * @param string $filename |
|
46 | + */ |
|
47 | + public function loadFile($filename) |
|
48 | + { |
|
49 | + foreach (file($filename, FILE_IGNORE_NEW_LINES) as $line) { |
|
50 | + if (2 !== substr_count($line, ':')) { |
|
51 | + throw new DAV\Exception('Malformed htdigest file. Every line should contain 2 colons'); |
|
52 | + } |
|
53 | + list($username, $realm, $A1) = explode(':', $line); |
|
54 | 54 | |
55 | - if (!preg_match('/^[a-zA-Z0-9]{32}$/', $A1)) { |
|
56 | - throw new DAV\Exception('Malformed htdigest file. Invalid md5 hash'); |
|
57 | - } |
|
58 | - $this->users[$realm.':'.$username] = $A1; |
|
59 | - } |
|
60 | - } |
|
55 | + if (!preg_match('/^[a-zA-Z0-9]{32}$/', $A1)) { |
|
56 | + throw new DAV\Exception('Malformed htdigest file. Invalid md5 hash'); |
|
57 | + } |
|
58 | + $this->users[$realm.':'.$username] = $A1; |
|
59 | + } |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * Returns a users' information. |
|
64 | - * |
|
65 | - * @param string $realm |
|
66 | - * @param string $username |
|
67 | - * |
|
68 | - * @return string |
|
69 | - */ |
|
70 | - public function getDigestHash($realm, $username) |
|
71 | - { |
|
72 | - return isset($this->users[$realm.':'.$username]) ? $this->users[$realm.':'.$username] : false; |
|
73 | - } |
|
62 | + /** |
|
63 | + * Returns a users' information. |
|
64 | + * |
|
65 | + * @param string $realm |
|
66 | + * @param string $username |
|
67 | + * |
|
68 | + * @return string |
|
69 | + */ |
|
70 | + public function getDigestHash($realm, $username) |
|
71 | + { |
|
72 | + return isset($this->users[$realm.':'.$username]) ? $this->users[$realm.':'.$username] : false; |
|
73 | + } |
|
74 | 74 | } |
@@ -23,108 +23,108 @@ |
||
23 | 23 | */ |
24 | 24 | abstract class AbstractBearer implements BackendInterface |
25 | 25 | { |
26 | - /** |
|
27 | - * Authentication Realm. |
|
28 | - * |
|
29 | - * The realm is often displayed by browser clients when showing the |
|
30 | - * authentication dialog. |
|
31 | - * |
|
32 | - * @var string |
|
33 | - */ |
|
34 | - protected $realm = 'sabre/dav'; |
|
26 | + /** |
|
27 | + * Authentication Realm. |
|
28 | + * |
|
29 | + * The realm is often displayed by browser clients when showing the |
|
30 | + * authentication dialog. |
|
31 | + * |
|
32 | + * @var string |
|
33 | + */ |
|
34 | + protected $realm = 'sabre/dav'; |
|
35 | 35 | |
36 | - /** |
|
37 | - * Validates a Bearer token. |
|
38 | - * |
|
39 | - * This method should return the full principal url, or false if the |
|
40 | - * token was incorrect. |
|
41 | - * |
|
42 | - * @param string $bearerToken |
|
43 | - * |
|
44 | - * @return string|false |
|
45 | - */ |
|
46 | - abstract protected function validateBearerToken($bearerToken); |
|
36 | + /** |
|
37 | + * Validates a Bearer token. |
|
38 | + * |
|
39 | + * This method should return the full principal url, or false if the |
|
40 | + * token was incorrect. |
|
41 | + * |
|
42 | + * @param string $bearerToken |
|
43 | + * |
|
44 | + * @return string|false |
|
45 | + */ |
|
46 | + abstract protected function validateBearerToken($bearerToken); |
|
47 | 47 | |
48 | - /** |
|
49 | - * Sets the authentication realm for this backend. |
|
50 | - * |
|
51 | - * @param string $realm |
|
52 | - */ |
|
53 | - public function setRealm($realm) |
|
54 | - { |
|
55 | - $this->realm = $realm; |
|
56 | - } |
|
48 | + /** |
|
49 | + * Sets the authentication realm for this backend. |
|
50 | + * |
|
51 | + * @param string $realm |
|
52 | + */ |
|
53 | + public function setRealm($realm) |
|
54 | + { |
|
55 | + $this->realm = $realm; |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * When this method is called, the backend must check if authentication was |
|
60 | - * successful. |
|
61 | - * |
|
62 | - * The returned value must be one of the following |
|
63 | - * |
|
64 | - * [true, "principals/username"] |
|
65 | - * [false, "reason for failure"] |
|
66 | - * |
|
67 | - * If authentication was successful, it's expected that the authentication |
|
68 | - * backend returns a so-called principal url. |
|
69 | - * |
|
70 | - * Examples of a principal url: |
|
71 | - * |
|
72 | - * principals/admin |
|
73 | - * principals/user1 |
|
74 | - * principals/users/joe |
|
75 | - * principals/uid/123457 |
|
76 | - * |
|
77 | - * If you don't use WebDAV ACL (RFC3744) we recommend that you simply |
|
78 | - * return a string such as: |
|
79 | - * |
|
80 | - * principals/users/[username] |
|
81 | - * |
|
82 | - * @return array |
|
83 | - */ |
|
84 | - public function check(RequestInterface $request, ResponseInterface $response) |
|
85 | - { |
|
86 | - $auth = new HTTP\Auth\Bearer( |
|
87 | - $this->realm, |
|
88 | - $request, |
|
89 | - $response |
|
90 | - ); |
|
58 | + /** |
|
59 | + * When this method is called, the backend must check if authentication was |
|
60 | + * successful. |
|
61 | + * |
|
62 | + * The returned value must be one of the following |
|
63 | + * |
|
64 | + * [true, "principals/username"] |
|
65 | + * [false, "reason for failure"] |
|
66 | + * |
|
67 | + * If authentication was successful, it's expected that the authentication |
|
68 | + * backend returns a so-called principal url. |
|
69 | + * |
|
70 | + * Examples of a principal url: |
|
71 | + * |
|
72 | + * principals/admin |
|
73 | + * principals/user1 |
|
74 | + * principals/users/joe |
|
75 | + * principals/uid/123457 |
|
76 | + * |
|
77 | + * If you don't use WebDAV ACL (RFC3744) we recommend that you simply |
|
78 | + * return a string such as: |
|
79 | + * |
|
80 | + * principals/users/[username] |
|
81 | + * |
|
82 | + * @return array |
|
83 | + */ |
|
84 | + public function check(RequestInterface $request, ResponseInterface $response) |
|
85 | + { |
|
86 | + $auth = new HTTP\Auth\Bearer( |
|
87 | + $this->realm, |
|
88 | + $request, |
|
89 | + $response |
|
90 | + ); |
|
91 | 91 | |
92 | - $bearerToken = $auth->getToken($request); |
|
93 | - if (!$bearerToken) { |
|
94 | - return [false, "No 'Authorization: Bearer' header found. Either the client didn't send one, or the server is mis-configured"]; |
|
95 | - } |
|
96 | - $principalUrl = $this->validateBearerToken($bearerToken); |
|
97 | - if (!$principalUrl) { |
|
98 | - return [false, 'Bearer token was incorrect']; |
|
99 | - } |
|
92 | + $bearerToken = $auth->getToken($request); |
|
93 | + if (!$bearerToken) { |
|
94 | + return [false, "No 'Authorization: Bearer' header found. Either the client didn't send one, or the server is mis-configured"]; |
|
95 | + } |
|
96 | + $principalUrl = $this->validateBearerToken($bearerToken); |
|
97 | + if (!$principalUrl) { |
|
98 | + return [false, 'Bearer token was incorrect']; |
|
99 | + } |
|
100 | 100 | |
101 | - return [true, $principalUrl]; |
|
102 | - } |
|
101 | + return [true, $principalUrl]; |
|
102 | + } |
|
103 | 103 | |
104 | - /** |
|
105 | - * This method is called when a user could not be authenticated, and |
|
106 | - * authentication was required for the current request. |
|
107 | - * |
|
108 | - * This gives you the opportunity to set authentication headers. The 401 |
|
109 | - * status code will already be set. |
|
110 | - * |
|
111 | - * In this case of Bearer Auth, this would for example mean that the |
|
112 | - * following header needs to be set: |
|
113 | - * |
|
114 | - * $response->addHeader('WWW-Authenticate', 'Bearer realm=SabreDAV'); |
|
115 | - * |
|
116 | - * Keep in mind that in the case of multiple authentication backends, other |
|
117 | - * WWW-Authenticate headers may already have been set, and you'll want to |
|
118 | - * append your own WWW-Authenticate header instead of overwriting the |
|
119 | - * existing one. |
|
120 | - */ |
|
121 | - public function challenge(RequestInterface $request, ResponseInterface $response) |
|
122 | - { |
|
123 | - $auth = new HTTP\Auth\Bearer( |
|
124 | - $this->realm, |
|
125 | - $request, |
|
126 | - $response |
|
127 | - ); |
|
128 | - $auth->requireLogin(); |
|
129 | - } |
|
104 | + /** |
|
105 | + * This method is called when a user could not be authenticated, and |
|
106 | + * authentication was required for the current request. |
|
107 | + * |
|
108 | + * This gives you the opportunity to set authentication headers. The 401 |
|
109 | + * status code will already be set. |
|
110 | + * |
|
111 | + * In this case of Bearer Auth, this would for example mean that the |
|
112 | + * following header needs to be set: |
|
113 | + * |
|
114 | + * $response->addHeader('WWW-Authenticate', 'Bearer realm=SabreDAV'); |
|
115 | + * |
|
116 | + * Keep in mind that in the case of multiple authentication backends, other |
|
117 | + * WWW-Authenticate headers may already have been set, and you'll want to |
|
118 | + * append your own WWW-Authenticate header instead of overwriting the |
|
119 | + * existing one. |
|
120 | + */ |
|
121 | + public function challenge(RequestInterface $request, ResponseInterface $response) |
|
122 | + { |
|
123 | + $auth = new HTTP\Auth\Bearer( |
|
124 | + $this->realm, |
|
125 | + $request, |
|
126 | + $response |
|
127 | + ); |
|
128 | + $auth->requireLogin(); |
|
129 | + } |
|
130 | 130 | } |
@@ -10,105 +10,105 @@ |
||
10 | 10 | */ |
11 | 11 | class PDOBasicAuth extends AbstractBasic |
12 | 12 | { |
13 | - /** |
|
14 | - * Reference to PDO connection. |
|
15 | - * |
|
16 | - * @var PDO |
|
17 | - */ |
|
18 | - protected $pdo; |
|
13 | + /** |
|
14 | + * Reference to PDO connection. |
|
15 | + * |
|
16 | + * @var PDO |
|
17 | + */ |
|
18 | + protected $pdo; |
|
19 | 19 | |
20 | - /** |
|
21 | - * PDO table name we'll be using. |
|
22 | - * |
|
23 | - * @var string |
|
24 | - */ |
|
25 | - protected $tableName; |
|
20 | + /** |
|
21 | + * PDO table name we'll be using. |
|
22 | + * |
|
23 | + * @var string |
|
24 | + */ |
|
25 | + protected $tableName; |
|
26 | 26 | |
27 | - /** |
|
28 | - * PDO digest column name we'll be using |
|
29 | - * (i.e. digest, password, password_hash). |
|
30 | - * |
|
31 | - * @var string |
|
32 | - */ |
|
33 | - protected $digestColumn; |
|
27 | + /** |
|
28 | + * PDO digest column name we'll be using |
|
29 | + * (i.e. digest, password, password_hash). |
|
30 | + * |
|
31 | + * @var string |
|
32 | + */ |
|
33 | + protected $digestColumn; |
|
34 | 34 | |
35 | - /** |
|
36 | - * PDO uuid(unique user identifier) column name we'll be using |
|
37 | - * (i.e. username, email). |
|
38 | - * |
|
39 | - * @var string |
|
40 | - */ |
|
41 | - protected $uuidColumn; |
|
35 | + /** |
|
36 | + * PDO uuid(unique user identifier) column name we'll be using |
|
37 | + * (i.e. username, email). |
|
38 | + * |
|
39 | + * @var string |
|
40 | + */ |
|
41 | + protected $uuidColumn; |
|
42 | 42 | |
43 | - /** |
|
44 | - * Digest prefix: |
|
45 | - * if the backend you are using for is prefixing |
|
46 | - * your password hashes set this option to your prefix to |
|
47 | - * cut it off before verfiying. |
|
48 | - * |
|
49 | - * @var string |
|
50 | - */ |
|
51 | - protected $digestPrefix; |
|
43 | + /** |
|
44 | + * Digest prefix: |
|
45 | + * if the backend you are using for is prefixing |
|
46 | + * your password hashes set this option to your prefix to |
|
47 | + * cut it off before verfiying. |
|
48 | + * |
|
49 | + * @var string |
|
50 | + */ |
|
51 | + protected $digestPrefix; |
|
52 | 52 | |
53 | - /** |
|
54 | - * Creates the backend object. |
|
55 | - * |
|
56 | - * If the filename argument is passed in, it will parse out the specified file fist. |
|
57 | - */ |
|
58 | - public function __construct(\PDO $pdo, array $options = []) |
|
59 | - { |
|
60 | - $this->pdo = $pdo; |
|
61 | - if (isset($options['tableName'])) { |
|
62 | - $this->tableName = $options['tableName']; |
|
63 | - } else { |
|
64 | - $this->tableName = 'users'; |
|
65 | - } |
|
66 | - if (isset($options['digestColumn'])) { |
|
67 | - $this->digestColumn = $options['digestColumn']; |
|
68 | - } else { |
|
69 | - $this->digestColumn = 'digest'; |
|
70 | - } |
|
71 | - if (isset($options['uuidColumn'])) { |
|
72 | - $this->uuidColumn = $options['uuidColumn']; |
|
73 | - } else { |
|
74 | - $this->uuidColumn = 'username'; |
|
75 | - } |
|
76 | - if (isset($options['digestPrefix'])) { |
|
77 | - $this->digestPrefix = $options['digestPrefix']; |
|
78 | - } |
|
79 | - } |
|
53 | + /** |
|
54 | + * Creates the backend object. |
|
55 | + * |
|
56 | + * If the filename argument is passed in, it will parse out the specified file fist. |
|
57 | + */ |
|
58 | + public function __construct(\PDO $pdo, array $options = []) |
|
59 | + { |
|
60 | + $this->pdo = $pdo; |
|
61 | + if (isset($options['tableName'])) { |
|
62 | + $this->tableName = $options['tableName']; |
|
63 | + } else { |
|
64 | + $this->tableName = 'users'; |
|
65 | + } |
|
66 | + if (isset($options['digestColumn'])) { |
|
67 | + $this->digestColumn = $options['digestColumn']; |
|
68 | + } else { |
|
69 | + $this->digestColumn = 'digest'; |
|
70 | + } |
|
71 | + if (isset($options['uuidColumn'])) { |
|
72 | + $this->uuidColumn = $options['uuidColumn']; |
|
73 | + } else { |
|
74 | + $this->uuidColumn = 'username'; |
|
75 | + } |
|
76 | + if (isset($options['digestPrefix'])) { |
|
77 | + $this->digestPrefix = $options['digestPrefix']; |
|
78 | + } |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * Validates a username and password. |
|
83 | - * |
|
84 | - * This method should return true or false depending on if login |
|
85 | - * succeeded. |
|
86 | - * |
|
87 | - * @param string $username |
|
88 | - * @param string $password |
|
89 | - * |
|
90 | - * @return bool |
|
91 | - */ |
|
92 | - public function validateUserPass($username, $password) |
|
93 | - { |
|
94 | - $stmt = $this->pdo->prepare('SELECT '.$this->digestColumn.' FROM '.$this->tableName.' WHERE '.$this->uuidColumn.' = ?'); |
|
95 | - $stmt->execute([$username]); |
|
96 | - $result = $stmt->fetchAll(); |
|
81 | + /** |
|
82 | + * Validates a username and password. |
|
83 | + * |
|
84 | + * This method should return true or false depending on if login |
|
85 | + * succeeded. |
|
86 | + * |
|
87 | + * @param string $username |
|
88 | + * @param string $password |
|
89 | + * |
|
90 | + * @return bool |
|
91 | + */ |
|
92 | + public function validateUserPass($username, $password) |
|
93 | + { |
|
94 | + $stmt = $this->pdo->prepare('SELECT '.$this->digestColumn.' FROM '.$this->tableName.' WHERE '.$this->uuidColumn.' = ?'); |
|
95 | + $stmt->execute([$username]); |
|
96 | + $result = $stmt->fetchAll(); |
|
97 | 97 | |
98 | - if (!count($result)) { |
|
99 | - return false; |
|
100 | - } else { |
|
101 | - $digest = $result[0][$this->digestColumn]; |
|
98 | + if (!count($result)) { |
|
99 | + return false; |
|
100 | + } else { |
|
101 | + $digest = $result[0][$this->digestColumn]; |
|
102 | 102 | |
103 | - if (isset($this->digestPrefix)) { |
|
104 | - $digest = substr($digest, strlen($this->digestPrefix)); |
|
105 | - } |
|
103 | + if (isset($this->digestPrefix)) { |
|
104 | + $digest = substr($digest, strlen($this->digestPrefix)); |
|
105 | + } |
|
106 | 106 | |
107 | - if (password_verify($password, $digest)) { |
|
108 | - return true; |
|
109 | - } |
|
107 | + if (password_verify($password, $digest)) { |
|
108 | + return true; |
|
109 | + } |
|
110 | 110 | |
111 | - return false; |
|
112 | - } |
|
113 | - } |
|
111 | + return false; |
|
112 | + } |
|
113 | + } |
|
114 | 114 | } |
@@ -13,43 +13,43 @@ |
||
13 | 13 | */ |
14 | 14 | class PDO extends AbstractDigest |
15 | 15 | { |
16 | - /** |
|
17 | - * Reference to PDO connection. |
|
18 | - * |
|
19 | - * @var PDO |
|
20 | - */ |
|
21 | - protected $pdo; |
|
16 | + /** |
|
17 | + * Reference to PDO connection. |
|
18 | + * |
|
19 | + * @var PDO |
|
20 | + */ |
|
21 | + protected $pdo; |
|
22 | 22 | |
23 | - /** |
|
24 | - * PDO table name we'll be using. |
|
25 | - * |
|
26 | - * @var string |
|
27 | - */ |
|
28 | - public $tableName = 'users'; |
|
23 | + /** |
|
24 | + * PDO table name we'll be using. |
|
25 | + * |
|
26 | + * @var string |
|
27 | + */ |
|
28 | + public $tableName = 'users'; |
|
29 | 29 | |
30 | - /** |
|
31 | - * Creates the backend object. |
|
32 | - * |
|
33 | - * If the filename argument is passed in, it will parse out the specified file fist. |
|
34 | - */ |
|
35 | - public function __construct(\PDO $pdo) |
|
36 | - { |
|
37 | - $this->pdo = $pdo; |
|
38 | - } |
|
30 | + /** |
|
31 | + * Creates the backend object. |
|
32 | + * |
|
33 | + * If the filename argument is passed in, it will parse out the specified file fist. |
|
34 | + */ |
|
35 | + public function __construct(\PDO $pdo) |
|
36 | + { |
|
37 | + $this->pdo = $pdo; |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * Returns the digest hash for a user. |
|
42 | - * |
|
43 | - * @param string $realm |
|
44 | - * @param string $username |
|
45 | - * |
|
46 | - * @return string|null |
|
47 | - */ |
|
48 | - public function getDigestHash($realm, $username) |
|
49 | - { |
|
50 | - $stmt = $this->pdo->prepare('SELECT digesta1 FROM '.$this->tableName.' WHERE username = ?'); |
|
51 | - $stmt->execute([$username]); |
|
40 | + /** |
|
41 | + * Returns the digest hash for a user. |
|
42 | + * |
|
43 | + * @param string $realm |
|
44 | + * @param string $username |
|
45 | + * |
|
46 | + * @return string|null |
|
47 | + */ |
|
48 | + public function getDigestHash($realm, $username) |
|
49 | + { |
|
50 | + $stmt = $this->pdo->prepare('SELECT digesta1 FROM '.$this->tableName.' WHERE username = ?'); |
|
51 | + $stmt->execute([$username]); |
|
52 | 52 | |
53 | - return $stmt->fetchColumn() ?: null; |
|
54 | - } |
|
53 | + return $stmt->fetchColumn() ?: null; |
|
54 | + } |
|
55 | 55 | } |
@@ -13,70 +13,70 @@ |
||
13 | 13 | */ |
14 | 14 | class IMAP extends AbstractBasic |
15 | 15 | { |
16 | - /** |
|
17 | - * IMAP server in the form {host[:port][/flag1/flag2...]}. |
|
18 | - * |
|
19 | - * @see http://php.net/manual/en/function.imap-open.php |
|
20 | - * |
|
21 | - * @var string |
|
22 | - */ |
|
23 | - protected $mailbox; |
|
16 | + /** |
|
17 | + * IMAP server in the form {host[:port][/flag1/flag2...]}. |
|
18 | + * |
|
19 | + * @see http://php.net/manual/en/function.imap-open.php |
|
20 | + * |
|
21 | + * @var string |
|
22 | + */ |
|
23 | + protected $mailbox; |
|
24 | 24 | |
25 | - /** |
|
26 | - * Creates the backend object. |
|
27 | - * |
|
28 | - * @param string $mailbox |
|
29 | - */ |
|
30 | - public function __construct($mailbox) |
|
31 | - { |
|
32 | - $this->mailbox = $mailbox; |
|
33 | - } |
|
25 | + /** |
|
26 | + * Creates the backend object. |
|
27 | + * |
|
28 | + * @param string $mailbox |
|
29 | + */ |
|
30 | + public function __construct($mailbox) |
|
31 | + { |
|
32 | + $this->mailbox = $mailbox; |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * Connects to an IMAP server and tries to authenticate. |
|
37 | - * |
|
38 | - * @param string $username |
|
39 | - * @param string $password |
|
40 | - * |
|
41 | - * @return bool |
|
42 | - */ |
|
43 | - protected function imapOpen($username, $password) |
|
44 | - { |
|
45 | - $success = false; |
|
35 | + /** |
|
36 | + * Connects to an IMAP server and tries to authenticate. |
|
37 | + * |
|
38 | + * @param string $username |
|
39 | + * @param string $password |
|
40 | + * |
|
41 | + * @return bool |
|
42 | + */ |
|
43 | + protected function imapOpen($username, $password) |
|
44 | + { |
|
45 | + $success = false; |
|
46 | 46 | |
47 | - try { |
|
48 | - $imap = imap_open($this->mailbox, $username, $password, OP_HALFOPEN | OP_READONLY, 1); |
|
49 | - if ($imap) { |
|
50 | - $success = true; |
|
51 | - } |
|
52 | - } catch (\ErrorException $e) { |
|
53 | - error_log($e->getMessage()); |
|
54 | - } |
|
47 | + try { |
|
48 | + $imap = imap_open($this->mailbox, $username, $password, OP_HALFOPEN | OP_READONLY, 1); |
|
49 | + if ($imap) { |
|
50 | + $success = true; |
|
51 | + } |
|
52 | + } catch (\ErrorException $e) { |
|
53 | + error_log($e->getMessage()); |
|
54 | + } |
|
55 | 55 | |
56 | - $errors = imap_errors(); |
|
57 | - if ($errors) { |
|
58 | - foreach ($errors as $error) { |
|
59 | - error_log($error); |
|
60 | - } |
|
61 | - } |
|
56 | + $errors = imap_errors(); |
|
57 | + if ($errors) { |
|
58 | + foreach ($errors as $error) { |
|
59 | + error_log($error); |
|
60 | + } |
|
61 | + } |
|
62 | 62 | |
63 | - if (isset($imap) && $imap) { |
|
64 | - imap_close($imap); |
|
65 | - } |
|
63 | + if (isset($imap) && $imap) { |
|
64 | + imap_close($imap); |
|
65 | + } |
|
66 | 66 | |
67 | - return $success; |
|
68 | - } |
|
67 | + return $success; |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * Validates a username and password by trying to authenticate against IMAP. |
|
72 | - * |
|
73 | - * @param string $username |
|
74 | - * @param string $password |
|
75 | - * |
|
76 | - * @return bool |
|
77 | - */ |
|
78 | - protected function validateUserPass($username, $password) |
|
79 | - { |
|
80 | - return $this->imapOpen($username, $password); |
|
81 | - } |
|
70 | + /** |
|
71 | + * Validates a username and password by trying to authenticate against IMAP. |
|
72 | + * |
|
73 | + * @param string $username |
|
74 | + * @param string $password |
|
75 | + * |
|
76 | + * @return bool |
|
77 | + */ |
|
78 | + protected function validateUserPass($username, $password) |
|
79 | + { |
|
80 | + return $this->imapOpen($username, $password); |
|
81 | + } |
|
82 | 82 | } |