diff --git a/appinfo/routes.php b/appinfo/routes.php index cae7aad..724f4e5 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -24,11 +24,6 @@ namespace OCA\User_SAML\AppInfo; (new Application())->registerRoutes( $this, [ - 'resources' => [ - 'AuthSettings' => [ - 'url' => '/authtokens' - ], - ], 'routes' => [ [ 'name' => 'SAML#login', @@ -55,7 +50,7 @@ namespace OCA\User_SAML\AppInfo; 'url' => '/saml/notProvisioned', 'verb' => 'GET', ], - ] + ], ] ); diff --git a/js/personal.js b/js/personal.js deleted file mode 100644 index 4897e78..0000000 --- a/js/personal.js +++ /dev/null @@ -1,9 +0,0 @@ -$(function() { - - // Show token views - var collection = new OCA.User_SAML.AuthTokenCollection(); - var view = new OCA.User_SAML.AuthTokenView({ - collection: collection - }); - view.reload(); -}); \ No newline at end of file diff --git a/js/personal/authtoken-collection.js b/js/personal/authtoken-collection.js deleted file mode 100644 index 4c0cf38..0000000 --- a/js/personal/authtoken-collection.js +++ /dev/null @@ -1,52 +0,0 @@ -/* global Backbone */ - -/** - * @author Christoph Wurst - * - * @copyright Copyright (c) 2016, ownCloud, Inc. - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see - * - */ - -(function(OCA, Backbone) { - 'use strict'; - - OCA.User_SAML = OCA.User_SAML || {}; - - var AuthTokenCollection = Backbone.Collection.extend({ - - model: OCA.User_SAML.AuthToken, - - /** - * Show recently used sessions/devices first - * - * @param {OCA.User_SAML.AuthToken} t1 - * @param {OCA.User_SAML.AuthToken} t2 - * @returns {Boolean} - */ - comparator: function (t1, t2) { - var ts1 = parseInt(t1.get('lastActivity'), 10); - var ts2 = parseInt(t2.get('lastActivity'), 10); - return ts1 < ts2; - }, - - tokenType: null, - - url: OC.generateUrl('/apps/user_saml/authtokens') - }); - - OCA.User_SAML.AuthTokenCollection = AuthTokenCollection; - -})(OCA, Backbone); diff --git a/js/personal/authtoken.js b/js/personal/authtoken.js deleted file mode 100644 index 3271713..0000000 --- a/js/personal/authtoken.js +++ /dev/null @@ -1,33 +0,0 @@ -/* global Backbone */ - -/** - * @author Christoph Wurst - * - * @copyright Copyright (c) 2016, ownCloud, Inc. - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see - * - */ - -(function(OCA, Backbone) { - 'use strict'; - - OCA.User_SAML = OCA.User_SAML || {}; - - var AuthToken = Backbone.Model.extend({ - }); - - OCA.User_SAML.AuthToken = AuthToken; - -})(OCA, Backbone); diff --git a/js/personal/authtoken_view.js b/js/personal/authtoken_view.js deleted file mode 100644 index dfe60bf..0000000 --- a/js/personal/authtoken_view.js +++ /dev/null @@ -1,230 +0,0 @@ -/* global Backbone, Handlebars, moment */ - -/** - * @author Christoph Wurst - * - * @copyright Copyright (c) 2016, ownCloud, Inc. - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see - * - */ - -(function(OCA, _, Backbone, $, Handlebars, moment) { - 'use strict'; - - OCA.User_SAML = OCA.User_SAML|| {}; - - var TEMPLATE_TOKEN = - '' - + '{{name}}' - + '' - + ''; - - var SubView = Backbone.View.extend({ - collection: null, - type: 0, - _template: undefined, - - template: function(data) { - if (_.isUndefined(this._template)) { - this._template = Handlebars.compile(TEMPLATE_TOKEN); - } - - return this._template(data); - }, - - initialize: function(options) { - this.type = options.type; - this.collection = options.collection; - - this.on(this.collection, 'change', this.render); - }, - - render: function() { - var _this = this; - - var list = this.$('.token-list'); - var tokens = this.collection.filter(function(token) { - return parseInt(token.get('type'), 10) === _this.type; - }); - list.html(''); - - // Show header only if there are tokens to show - this._toggleHeader(tokens.length > 0); - - tokens.forEach(function(token) { - var viewData = token.toJSON(); - var ts = viewData.lastActivity * 1000; - viewData.lastActivity = OC.Util.relativeModifiedDate(ts); - viewData.lastActivityTime = OC.Util.formatDate(ts, 'LLL'); - var html = _this.template(viewData); - var $html = $(html); - $html.find('.has-tooltip').tooltip({container: 'body'}); - list.append($html); - }); - }, - - toggleLoading: function(state) { - this.$('.token-list').toggleClass('icon-loading', state); - }, - - _toggleHeader: function(show) { - this.$('.hidden-when-empty').toggleClass('hidden', !show); - } - }); - - var AuthTokenView = Backbone.View.extend({ - collection: null, - - _views: [], - - _form: undefined, - - _tokenName: undefined, - - _addAppPasswordBtn: undefined, - - _result: undefined, - - _newAppPassword: undefined, - - _hideAppPasswordBtn: undefined, - - _addingToken: false, - - initialize: function(options) { - this.collection = options.collection; - - var tokenTypes = [0, 1]; - var _this = this; - _.each(tokenTypes, function(type) { - var el = '#user-saml-apppasswords'; - _this._views.push(new SubView({ - el: el, - type: type, - collection: _this.collection - })); - - var $el = $(el); - $el.on('click', 'a.icon-delete', _.bind(_this._onDeleteToken, _this)); - }); - - this._form = $('#user-saml-app-password-form'); - this._tokenName = $('#user-saml-app-password-name'); - this._addAppPasswordBtn = $('#user-saml-add-app-password'); - this._addAppPasswordBtn.click(_.bind(this._addAppPassword, this)); - - this._result = $('#user-saml-app-password-result'); - this._newAppPassword = $('#user-saml-new-app-password'); - this._newAppPassword.on('focus', _.bind(this._onNewTokenFocus, this)); - this._hideAppPasswordBtn = $('#user-saml-app-password-hide'); - this._hideAppPasswordBtn.click(_.bind(this._hideToken, this)); - }, - - render: function() { - _.each(this._views, function(view) { - view.render(); - view.toggleLoading(false); - }); - }, - - reload: function() { - var _this = this; - - _.each(this._views, function(view) { - view.toggleLoading(true); - }); - - var loadingTokens = this.collection.fetch(); - - $.when(loadingTokens).done(function() { - _this.render(); - }); - $.when(loadingTokens).fail(function() { - OC.Notification.showTemporary(t('core', 'Error while loading browser sessions and device tokens')); - }); - }, - - _addAppPassword: function() { - var _this = this; - this._toggleAddingToken(true); - - var deviceName = this._tokenName.val(); - var creatingToken = $.ajax(OC.generateUrl('/apps/user_saml/authtokens'), { - method: 'POST', - data: { - name: deviceName - } - }); - - $.when(creatingToken).done(function(resp) { - _this.collection.add(resp.deviceToken); - _this.render(); - _this._newAppPassword.val(resp.token); - _this._toggleFormResult(false); - _this._newAppPassword.select(); - _this._tokenName.val(''); - }); - $.when(creatingToken).fail(function() { - OC.Notification.showTemporary(t('core', 'Error while creating device token')); - }); - $.when(creatingToken).always(function() { - _this._toggleAddingToken(false); - }); - }, - - _onNewTokenFocus: function() { - this._newAppPassword.select(); - }, - - _hideToken: function() { - this._toggleFormResult(true); - }, - - _toggleAddingToken: function(state) { - this._addingToken = state; - this._addAppPasswordBtn.toggleClass('icon-loading-small', state); - }, - - _onDeleteToken: function(event) { - var $target = $(event.target); - var $row = $target.closest('tr'); - var id = $row.data('id'); - - var token = this.collection.get(id); - if (_.isUndefined(token)) { - // Ignore event - return; - } - - var destroyingToken = token.destroy(); - - var _this = this; - $.when(destroyingToken).fail(function() { - OC.Notification.showTemporary(t('core', 'Error while deleting the token')); - }); - $.when(destroyingToken).always(function() { - _this.render(); - }); - }, - - _toggleFormResult: function(showForm) { - this._form.toggleClass('hidden', !showForm); - this._result.toggleClass('hidden', showForm); - } - }); - - OCA.User_SAML.AuthTokenView = AuthTokenView; - -})(OCA, _, Backbone, $, Handlebars, moment); diff --git a/lib/Settings/Section.php b/lib/Settings/Section.php index 085462a..5fed8cd 100644 --- a/lib/Settings/Section.php +++ b/lib/Settings/Section.php @@ -30,6 +30,9 @@ class Section implements ISection { /** @var IL10N */ private $l; + /** + * @param IL10N $l + */ public function __construct(IL10N $l) { $this->l = $l; } diff --git a/lib/appinfo/application.php b/lib/appinfo/application.php index c4587b1..240027a 100644 --- a/lib/appinfo/application.php +++ b/lib/appinfo/application.php @@ -38,19 +38,6 @@ class Application extends App { /** * Controller */ - $container->registerService('AuthSettingsController', function(IAppContainer $c) { - /** @var \OC\Server $server */ - $server = $c->query('ServerContainer'); - return new AuthSettingsController( - $c->getAppName(), - $server->getRequest(), - $server->getUserManager(), - $server->getSession(), - $server->getSecureRandom(), - $server->getDb(), - $server->getUserSession()->getUser()->getUID() - ); - }); $container->registerService('SettingsController', function(IAppContainer $c) { /** @var \OC\Server $server */ $server = $c->query('ServerContainer'); @@ -87,6 +74,6 @@ class Application extends App { $c->query('ServerContainer')->getUserSession() ); }); - $container->registerMiddleware('OnlyLoggedInMiddleware'); + $container->registerMiddleWare('OnlyLoggedInMiddleware'); } } diff --git a/lib/controller/authsettingscontroller.php b/lib/controller/authsettingscontroller.php deleted file mode 100644 index ddc0fad..0000000 --- a/lib/controller/authsettingscontroller.php +++ /dev/null @@ -1,167 +0,0 @@ - - * - * @copyright Copyright (c) 2016, ownCloud, Inc. - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see - * - */ -namespace OCA\User_SAML\Controller; - -use OC\AppFramework\Http; -use OCP\AppFramework\Controller; -use OCP\AppFramework\Http\JSONResponse; -use OCP\DB\QueryBuilder\IQueryBuilder; -use OCP\IDb; -use OCP\IRequest; -use OCP\ISession; -use OCP\IUserManager; -use OCP\Security\ISecureRandom; - -class AuthSettingsController extends Controller { - /** @var IUserManager */ - private $userManager; - /** @var ISession */ - private $session; - /** @var string */ - private $uid; - /** @var ISecureRandom */ - private $random; - /** @var IDb */ - private $db; - - /** - * @param string $appName - * @param IRequest $request - * @param IUserManager $userManager - * @param ISession $session - * @param ISecureRandom $random - * @param IDb $db - * @param string $uid - */ - public function __construct($appName, - IRequest $request, - IUserManager $userManager, - ISession $session, - ISecureRandom $random, - IDb $db, - $uid) { - parent::__construct($appName, $request); - $this->userManager = $userManager; - $this->uid = $uid; - $this->session = $session; - $this->random = $random; - $this->db = $db; - } - /** - * @NoAdminRequired - * - * @return JSONResponse - */ - public function index() { - $user = $this->userManager->get($this->uid); - if (is_null($user)) { - return []; - } - - /* @var $qb IQueryBuilder */ - $qb = $this->db->getQueryBuilder(); - $qb->select('id', 'uid', 'name', 'token') - ->from('user_saml_auth_token') - ->where($qb->expr()->eq('uid', $qb->createNamedParameter($user->getUID()))) - ->setMaxResults(1000); - $result = $qb->execute(); - $data = $result->fetchAll(); - $result->closeCursor(); - - foreach($data as $key => $entry) { - unset($data[$key]['token']); - unset($data[$key]['uid']); - $data[$key]['id'] = (int)$data[$key]['id']; - $data[$key]['type'] = 1; - } - - return $data; - } - - /** - * @NoAdminRequired - * - * @param string $name - * @return JSONResponse - */ - public function create($name) { - $token = $this->generateRandomDeviceToken(); - - $values = [ - 'uid' => $this->uid, - 'name' => $name, - 'token' => password_hash($token, PASSWORD_DEFAULT), - ]; - - /* @var $qb IQueryBuilder */ - $qb = $this->db->getQueryBuilder(); - $qb->insert('user_saml_auth_token'); - foreach($values as $column => $value) { - $qb->setValue($column, $qb->createNamedParameter($value)); - } - $qb->execute(); - - return [ - 'token' => $token, - 'loginName' => $name, - 'deviceToken' => [ - 'id' => $qb->getLastInsertId(), - 'name' => $name, - 'type' => 1, - ], - ]; - } - /** - * Return a 20 digit device password - * - * Example: ABCDE-FGHIJ-KLMNO-PQRST - * - * @return string - */ - private function generateRandomDeviceToken() { - $groups = []; - for ($i = 0; $i < 4; $i++) { - $groups[] = $this->random->generate(5, implode('', range('A', 'Z'))); - } - return implode('-', $groups); - } - /** - * @NoAdminRequired - * - * @param string $id - * @return JSONResponse - */ - public function destroy($id) { - $user = $this->userManager->get($this->uid); - if (is_null($user)) { - return []; - } - - /* @var $qb IQueryBuilder */ - $qb = $this->db->getQueryBuilder(); - $qb->delete('user_saml_auth_token') - ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))) - ->andWhere($qb->expr()->eq('uid', $qb->createNamedParameter($user->getUID()))); - $qb->execute(); - - return []; - } -} \ No newline at end of file diff --git a/personal.php b/personal.php deleted file mode 100644 index 6690e93..0000000 --- a/personal.php +++ /dev/null @@ -1,25 +0,0 @@ - - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - */ - -$app = new \OCA\User_SAML\AppInfo\Application(); -/** @var \OCA\User_SAML\Controller\SettingsController $controller */ -$controller = $app->getContainer()->query('SettingsController'); -return $controller->displayPersonalPanel()->render(); diff --git a/templates/personal.php b/templates/personal.php deleted file mode 100644 index 6471658..0000000 --- a/templates/personal.php +++ /dev/null @@ -1,40 +0,0 @@ - - -
-

t('App passwords'));?>

- t("You've linked these apps."));?> - - - - - - - - - -
t('Name'));?>
-

t('An app password is a passcode that gives an app or device permissions to access your %s account.', [$theme->getName()]));?>

-
- - -
- -