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();
$dispatcher = \OC::$server->getEventDispatcher();
if ($type === 'environment-variable') {
$app->registerDavAuth();
}
$app->registerDavAuth();
$redirectSituation = false;

View File

@ -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;
}
}
}