Skip to content

Commit b5c62d7

Browse files
LukasReschkeMorrisJobke
authored andcommitted
Store user_webdavauth users in DB + code cleanup
This commit introduces the storing of user_webdavauth users in the database which is a pre-requisite of #12620. Furthermore, I refactored the code and removed deprecated code, as a little gimmick I added unit tests for the backend.
1 parent d8f04f5 commit b5c62d7

File tree

12 files changed

+867
-115
lines changed

12 files changed

+867
-115
lines changed
Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,28 @@
11
<?php
2-
32
/**
4-
* ownCloud - user_webdavauth
5-
*
6-
* @author Frank Karlitschek
7-
* @copyright 2012 Frank Karlitschek [email protected]
8-
*
9-
* This library is free software; you can redistribute it and/or
10-
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
11-
* License as published by the Free Software Foundation; either
12-
* version 3 of the License, or any later version.
13-
*
14-
* This library is distributed in the hope that it will be useful,
15-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17-
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
18-
*
19-
* You should have received a copy of the GNU Affero General Public
20-
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
21-
*
22-
*/
23-
24-
require_once OC_App::getAppPath('user_webdavauth').'/user_webdavauth.php';
3+
* @author Frank Karlitschek
4+
* @copyright 2012 Frank Karlitschek [email protected]
5+
* @copyright 2014 Lukas Reschke [email protected]
6+
*
7+
* This file is licensed under the Affero General Public License version 3 or
8+
* later.
9+
* See the COPYING-README file.
10+
*/
2511

26-
OC_APP::registerAdmin('user_webdavauth', 'settings');
12+
namespace OCA\user_webdavauth\AppInfo;
2713

28-
OC_User::registerBackend("WEBDAVAUTH");
29-
OC_User::useBackend( "WEBDAVAUTH" );
14+
use OCA\user_webdavauth\USER_WEBDAVAUTH;
15+
use OCP\Util;
3016

31-
OCP\Util::addTranslations('user_webdavauth');
32-
33-
// add settings page to navigation
34-
$entry = array(
35-
'id' => "user_webdavauth_settings",
36-
'order'=>1,
37-
'href' => OC_Helper::linkTo( "user_webdavauth", "settings.php" ),
38-
'name' => 'WEBDAVAUTH'
17+
$userBackend = new USER_WEBDAVAUTH(
18+
\OC::$server->getConfig(),
19+
\OC::$server->getDb(),
20+
\OC::$server->getHTTPHelper(),
21+
\OC::$server->getLogger(),
22+
\OC::$server->getUserManager(),
23+
\OC::$server->getServerRoot()
3924
);
25+
\OC_User::useBackend($userBackend);
26+
27+
Util::addTranslations('user_webdavauth');
28+
\OC_APP::registerAdmin('user_webdavauth', 'settings');
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?xml version="1.0" encoding="ISO-8859-1" ?>
2+
<database>
3+
4+
<name>*dbname*</name>
5+
<create>true</create>
6+
<overwrite>false</overwrite>
7+
<charset>utf8</charset>
8+
9+
<table>
10+
11+
<name>*dbprefix*webdav_user_mapping</name>
12+
13+
<declaration>
14+
15+
<field>
16+
<name>uid</name>
17+
<type>text</type>
18+
<notnull>true</notnull>
19+
<length>255</length>
20+
</field>
21+
22+
<field>
23+
<name>displayname</name>
24+
<type>text</type>
25+
<notnull>false</notnull>
26+
<length>255</length>
27+
</field>
28+
29+
<index>
30+
<name>webdav_uid</name>
31+
<primary>true</primary>
32+
<field>
33+
<name>uid</name>
34+
</field>
35+
</index>
36+
37+
</declaration>
38+
39+
</table>
40+
41+
</database>

apps/user_webdavauth/appinfo/info.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
<info>
33
<id>user_webdavauth</id>
44
<name>WebDAV user backend</name>
5-
<description>Authenticate users by a WebDAV call. You can use any WebDAV server, ownCloud server or other webserver to authenticate. It should return http 200 for right credentials and http 401 for wrong ones.
5+
<description>Authenticate users by a WebDAV call. You can use any WebDAV server, ownCloud server or other web server to authenticate. It should return a HTTP 2xx status code for correct credentials and a 4xx or 5xx for invalid ones.
66

7-
Attention: This app is not compatible with the LDAP user and group backend. This app is not the webdav interface of ownCloud, if you don't understand what it does then do not enable it.</description>
7+
Attention: This app is not the WebDAV interface of ownCloud, if you don't understand what it does then do not enable it.</description>
88
<licence>AGPL</licence>
99
<author>Frank Karlitschek</author>
10-
<requiremin>4.93</requiremin>
10+
<requiremin>7.0</requiremin>
1111
<shipped>true</shipped>
1212
<types>
1313
<authentication/>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.1.0.1
1+
1.2.0.0

apps/user_webdavauth/settings.php

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,13 @@
11
<?php
2-
32
/**
43
* ownCloud - user_webdavauth
54
*
65
* @author Frank Karlitschek
76
* @copyright 2012 Frank Karlitschek [email protected]
87
*
9-
* This library is free software; you can redistribute it and/or
10-
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
11-
* License as published by the Free Software Foundation; either
12-
* version 3 of the License, or any later version.
13-
*
14-
* This library is distributed in the hope that it will be useful,
15-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17-
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
18-
*
19-
* You should have received a copy of the GNU Affero General Public
20-
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
21-
*
8+
* This file is licensed under the Affero General Public License version 3 or
9+
* later.
10+
* See the COPYING-README file.
2211
*/
2312

2413
OC_Util::checkAdminUser();
@@ -28,12 +17,12 @@
2817
OCP\JSON::callCheck();
2918

3019
if(isset($_POST['webdav_url'])) {
31-
OC_CONFIG::setValue('user_webdavauth_url', strip_tags($_POST['webdav_url']));
20+
\OC::$server->getConfig()->setSystemValue('user_webdavauth_url', $_POST['webdav_url']);
3221
}
3322
}
3423

3524
// fill template
36-
$tmpl = new OC_Template( 'user_webdavauth', 'settings');
37-
$tmpl->assign( 'webdav_url', OC_Config::getValue( "user_webdavauth_url" ));
25+
$tmpl = new OC_Template('user_webdavauth', 'settings');
26+
$tmpl->assign('webdav_url', \OC::$server->getConfig()->getSystemValue('user_webdavauth_url'));
3827

3928
return $tmpl->fetchPage();
Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
1+
<?php
2+
/** @var array $_ */
3+
?>
14
<form id="webdavauth" class="section" action="#" method="post">
25
<h2><?php p($l->t('WebDAV Authentication'));?></h2>
3-
<p><label for="webdav_url"><?php p($l->t('Address:').' ');?><input type="url" placeholder="https://example.com/webdav" id="webdav_url" name="webdav_url" value="<?php p($_['webdav_url']); ?>"></label>
4-
<input type="hidden" name="requesttoken" value="<?php p($_['requesttoken']) ?>" id="requesttoken">
5-
<input type="submit" value="<?php p($l->t('Save')); ?>" />
6-
<br /><?php p($l->t('The user credentials will be sent to this address. This plugin checks the response and will interpret the HTTP statuscodes 401 and 403 as invalid credentials, and all other responses as valid credentials.')); ?>
6+
<p>
7+
<label for="webdav_url"><?php p($l->t('Address:').' ');?>
8+
<input type="url" placeholder="https://example.com/webdav" id="webdav_url" name="webdav_url" value="<?php p($_['webdav_url']); ?>">
9+
</label>
10+
<input type="hidden" name="requesttoken" value="<?php p($_['requesttoken']) ?>" id="requesttoken">
11+
<input type="submit" value="<?php p($l->t('Save')); ?>" />
12+
<br />
13+
<?php p($l->t('The user credentials will be sent to this address. This plugin checks the response and will interpret the HTTP status codes 2xx and 403 as valid credentials, and all other responses as invalid credentials.')); ?>
14+
</p>
715
</form>

0 commit comments

Comments
 (0)