2011-09-02 16:56:40 +04:00
|
|
|
<?php
|
|
|
|
/**
|
2012-05-12 22:46:07 +04:00
|
|
|
* Copyright (c) 2011, 2012 Michiel de Jong <michiel@unhosted.org>
|
|
|
|
* This file is licensed under the Affero General Public License version 3 or
|
|
|
|
* later.
|
|
|
|
* See the COPYING-README file.
|
2011-09-02 16:56:40 +04:00
|
|
|
*/
|
2011-12-07 18:51:47 +04:00
|
|
|
|
2012-05-12 22:46:07 +04:00
|
|
|
|
2011-09-02 16:56:40 +04:00
|
|
|
class OC_Connector_Sabre_Auth_ro_oauth extends Sabre_DAV_Auth_Backend_AbstractBasic {
|
|
|
|
private $validTokens;
|
2012-07-16 21:55:36 +04:00
|
|
|
private $category;
|
2012-02-26 01:59:58 +04:00
|
|
|
public function __construct($validTokensArg, $categoryArg) {
|
2011-09-02 16:56:40 +04:00
|
|
|
$this->validTokens = $validTokensArg;
|
2012-07-16 21:55:36 +04:00
|
|
|
$this->category = $categoryArg;
|
2011-09-02 16:56:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Validates a username and password
|
|
|
|
*
|
|
|
|
* This method should return true or false depending on if login
|
|
|
|
* succeeded.
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
protected function validateUserPass($username, $password){
|
|
|
|
//always give read-only:
|
2012-07-16 21:55:36 +04:00
|
|
|
if(($_SERVER['REQUEST_METHOD'] == 'OPTIONS')
|
2012-02-26 01:59:58 +04:00
|
|
|
|| (isset($this->validTokens[$password]))
|
2012-07-16 21:55:36 +04:00
|
|
|
|| (($_SERVER['REQUEST_METHOD'] == 'GET') && ($this->category == 'public'))
|
|
|
|
) {
|
2011-09-02 16:56:40 +04:00
|
|
|
OC_Util::setUpFS();
|
|
|
|
return true;
|
|
|
|
} else {
|
2012-07-16 21:55:36 +04:00
|
|
|
//var_export($_SERVER);
|
|
|
|
//var_export($this->validTokens);
|
|
|
|
//die('not getting in with "'.$username.'"/"'.$password.'"!');
|
2011-09-02 16:56:40 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//overwriting this to make it not automatically fail if no auth header is found:
|
|
|
|
public function authenticate(Sabre_DAV_Server $server,$realm) {
|
2012-02-22 22:05:52 +04:00
|
|
|
$auth = new Sabre_HTTP_BearerAuth();
|
2011-09-02 16:56:40 +04:00
|
|
|
$auth->setHTTPRequest($server->httpRequest);
|
|
|
|
$auth->setHTTPResponse($server->httpResponse);
|
|
|
|
$auth->setRealm($realm);
|
|
|
|
$userpass = $auth->getUserPass();
|
|
|
|
if (!$userpass) {
|
2012-02-26 01:59:58 +04:00
|
|
|
if(($_SERVER['REQUEST_METHOD'] == 'OPTIONS')
|
2012-07-16 21:55:36 +04:00
|
|
|
||(($_SERVER['REQUEST_METHOD'] == 'GET') && ($this->category == 'public'))
|
|
|
|
) {
|
2011-09-02 16:56:40 +04:00
|
|
|
$userpass = array('', '');
|
|
|
|
} else {
|
|
|
|
$auth->requireLogin();
|
|
|
|
throw new Sabre_DAV_Exception_NotAuthenticated('No basic authentication headers were found');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Authenticates the user
|
|
|
|
if (!$this->validateUserPass($userpass[0],$userpass[1])) {
|
|
|
|
$auth->requireLogin();
|
|
|
|
throw new Sabre_DAV_Exception_NotAuthenticated('Username or password does not match');
|
|
|
|
}
|
|
|
|
$this->currentUser = $userpass[0];
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|