diff --git a/appinfo/app.php b/appinfo/app.php index 74f8aa8..57baa18 100644 --- a/appinfo/app.php +++ b/appinfo/app.php @@ -82,10 +82,7 @@ if($returnScript === true) { } $app = new \OCA\User_SAML\AppInfo\Application(); -$dispatcher = \OC::$server->getEventDispatcher(); -if ($type === 'environment-variable') { - $app->registerDavAuth(); -} +$app->registerDavAuth(); $redirectSituation = false; diff --git a/lib/DavPlugin.php b/lib/DavPlugin.php index 1545d71..c90c9a6 100644 --- a/lib/DavPlugin.php +++ b/lib/DavPlugin.php @@ -23,13 +23,20 @@ namespace OCA\User_SAML; use OCP\IConfig; use OCP\ISession; +use Sabre\DAV\CorePlugin; +use Sabre\DAV\FS\Directory; use Sabre\DAV\Server; use Sabre\DAV\ServerPlugin; +use Sabre\DAV\Tree; +use Sabre\HTTP\RequestInterface; +use Sabre\HTTP\ResponseInterface; class DavPlugin extends ServerPlugin { private $session; private $config; private $auth; + /** @var Server */ + private $server; public function __construct(ISession $session, IConfig $config, array $auth) { $this->session = $session; @@ -41,14 +48,28 @@ class DavPlugin extends ServerPlugin { public function initialize(Server $server) { // before auth $server->on('beforeMethod', [$this, 'beforeMethod'], 9); + $this->server = $server; } - public function beforeMethod() { - if (!$this->session->exists('user_saml.samlUserData')) { + public function beforeMethod(RequestInterface $request, ResponseInterface $response) { + if ( + $this->config->getAppValue('user_saml', 'type') === 'environment-variable' && + !$this->session->exists('user_saml.samlUserData') + ) { $uidMapping = $this->config->getAppValue('user_saml', 'general-uid_mapping'); if (isset($this->auth[$uidMapping])) { $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; + } } }