allow anonymous options request

Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
Robin Appelman 2018-03-12 19:07:03 +01:00
parent a7f0e35225
commit 57c0a4d474
2 changed files with 24 additions and 6 deletions

View file

@ -82,10 +82,7 @@ if($returnScript === true) {
} }
$app = new \OCA\User_SAML\AppInfo\Application(); $app = new \OCA\User_SAML\AppInfo\Application();
$dispatcher = \OC::$server->getEventDispatcher(); $app->registerDavAuth();
if ($type === 'environment-variable') {
$app->registerDavAuth();
}
$redirectSituation = false; $redirectSituation = false;

View file

@ -23,13 +23,20 @@ namespace OCA\User_SAML;
use OCP\IConfig; use OCP\IConfig;
use OCP\ISession; use OCP\ISession;
use Sabre\DAV\CorePlugin;
use Sabre\DAV\FS\Directory;
use Sabre\DAV\Server; use Sabre\DAV\Server;
use Sabre\DAV\ServerPlugin; use Sabre\DAV\ServerPlugin;
use Sabre\DAV\Tree;
use Sabre\HTTP\RequestInterface;
use Sabre\HTTP\ResponseInterface;
class DavPlugin extends ServerPlugin { class DavPlugin extends ServerPlugin {
private $session; private $session;
private $config; private $config;
private $auth; private $auth;
/** @var Server */
private $server;
public function __construct(ISession $session, IConfig $config, array $auth) { public function __construct(ISession $session, IConfig $config, array $auth) {
$this->session = $session; $this->session = $session;
@ -41,14 +48,28 @@ class DavPlugin extends ServerPlugin {
public function initialize(Server $server) { public function initialize(Server $server) {
// before auth // before auth
$server->on('beforeMethod', [$this, 'beforeMethod'], 9); $server->on('beforeMethod', [$this, 'beforeMethod'], 9);
$this->server = $server;
} }
public function beforeMethod() { public function beforeMethod(RequestInterface $request, ResponseInterface $response) {
if (!$this->session->exists('user_saml.samlUserData')) { if (
$this->config->getAppValue('user_saml', 'type') === 'environment-variable' &&
!$this->session->exists('user_saml.samlUserData')
) {
$uidMapping = $this->config->getAppValue('user_saml', 'general-uid_mapping'); $uidMapping = $this->config->getAppValue('user_saml', 'general-uid_mapping');
if (isset($this->auth[$uidMapping])) { if (isset($this->auth[$uidMapping])) {
$this->session->set('user_saml.samlUserData', $this->auth); $this->session->set('user_saml.samlUserData', $this->auth);
} }
} }
if ($request->getMethod() === 'OPTIONS' && $request->getPath() === '') {
/** @var CorePlugin $corePlugin */
$corePlugin = $this->server->getPlugin('core');
// setup a fake tree for anonymous access
$this->server->tree = new Tree(new Directory(''));
$corePlugin->httpOptions($request, $response);
$this->server->sapi->sendResponse($response);
return false;
}
} }
} }