Remove unused code
This is now also part of core Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
This commit is contained in:
parent
5ca41b2b2b
commit
9b97c7350b
|
@ -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',
|
||||
],
|
||||
]
|
||||
],
|
||||
]
|
||||
);
|
||||
|
||||
|
|
|
@ -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();
|
||||
});
|
|
@ -1,52 +0,0 @@
|
|||
/* global Backbone */
|
||||
|
||||
/**
|
||||
* @author Christoph Wurst <christoph@owncloud.com>
|
||||
*
|
||||
* @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 <http://www.gnu.org/licenses/>
|
||||
*
|
||||
*/
|
||||
|
||||
(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);
|
|
@ -1,33 +0,0 @@
|
|||
/* global Backbone */
|
||||
|
||||
/**
|
||||
* @author Christoph Wurst <christoph@owncloud.com>
|
||||
*
|
||||
* @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 <http://www.gnu.org/licenses/>
|
||||
*
|
||||
*/
|
||||
|
||||
(function(OCA, Backbone) {
|
||||
'use strict';
|
||||
|
||||
OCA.User_SAML = OCA.User_SAML || {};
|
||||
|
||||
var AuthToken = Backbone.Model.extend({
|
||||
});
|
||||
|
||||
OCA.User_SAML.AuthToken = AuthToken;
|
||||
|
||||
})(OCA, Backbone);
|
|
@ -1,230 +0,0 @@
|
|||
/* global Backbone, Handlebars, moment */
|
||||
|
||||
/**
|
||||
* @author Christoph Wurst <christoph@owncloud.com>
|
||||
*
|
||||
* @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 <http://www.gnu.org/licenses/>
|
||||
*
|
||||
*/
|
||||
|
||||
(function(OCA, _, Backbone, $, Handlebars, moment) {
|
||||
'use strict';
|
||||
|
||||
OCA.User_SAML = OCA.User_SAML|| {};
|
||||
|
||||
var TEMPLATE_TOKEN =
|
||||
'<tr data-id="{{id}}">'
|
||||
+ '<td class="has-tooltip" title="{{name}}"><span class="token-name">{{name}}</span></td>'
|
||||
+ '<td><a class="icon-delete has-tooltip" title="' + t('core', 'Disconnect') + '"></a></td>'
|
||||
+ '<tr>';
|
||||
|
||||
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);
|
|
@ -30,6 +30,9 @@ class Section implements ISection {
|
|||
/** @var IL10N */
|
||||
private $l;
|
||||
|
||||
/**
|
||||
* @param IL10N $l
|
||||
*/
|
||||
public function __construct(IL10N $l) {
|
||||
$this->l = $l;
|
||||
}
|
||||
|
|
|
@ -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');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,167 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* @author Christoph Wurst <christoph@owncloud.com>
|
||||
*
|
||||
* @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 <http://www.gnu.org/licenses/>
|
||||
*
|
||||
*/
|
||||
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 [];
|
||||
}
|
||||
}
|
25
personal.php
25
personal.php
|
@ -1,25 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
|
||||
*
|
||||
* @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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
$app = new \OCA\User_SAML\AppInfo\Application();
|
||||
/** @var \OCA\User_SAML\Controller\SettingsController $controller */
|
||||
$controller = $app->getContainer()->query('SettingsController');
|
||||
return $controller->displayPersonalPanel()->render();
|
|
@ -1,40 +0,0 @@
|
|||
<?php
|
||||
style('user_saml', 'personal');
|
||||
|
||||
script('user_saml', [
|
||||
'personal/authtoken',
|
||||
'personal/authtoken-collection',
|
||||
'personal/authtoken_view',
|
||||
'personal',
|
||||
]);
|
||||
|
||||
/** @var array $_ */
|
||||
?>
|
||||
|
||||
<div id="user-saml-apppasswords" class="section">
|
||||
<h2><?php p($l->t('App passwords'));?></h2>
|
||||
<span class="hidden-when-empty"><?php p($l->t("You've linked these apps."));?></span>
|
||||
<table>
|
||||
<thead class="hidden-when-empty">
|
||||
<tr>
|
||||
<th><?php p($l->t('Name'));?></th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="token-list icon-loading">
|
||||
</tbody>
|
||||
</table>
|
||||
<p><?php p($l->t('An app password is a passcode that gives an app or device permissions to access your %s account.', [$theme->getName()]));?></p>
|
||||
<div id="user-saml-app-password-form">
|
||||
<input id="user-saml-app-password-name" type="text" placeholder="<?php p($l->t('App name')); ?>">
|
||||
<button id="user-saml-add-app-password" class="button"><?php p($l->t('Create new app password')); ?></button>
|
||||
</div>
|
||||
<div id="user-saml-app-password-result" class="hidden">
|
||||
<span><?php p($l->t('Use the credentials below to configure your app or device.')); ?></span>
|
||||
<div class="user-saml-app-password-row">
|
||||
<span class="user-saml-app-password-label"><?php p($l->t('Password')); ?></span>
|
||||
<input id="user-saml-new-app-password" type="text" readonly="readonly"/>
|
||||
<button id="user-saml-app-password-hide" class="button"><?php p($l->t('Done')); ?></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
Loading…
Reference in New Issue