From 8caaf3ae20e07bbe0fa6af3a7225c988892a0c9d Mon Sep 17 00:00:00 2001 From: Justin Richer Date: Thu, 26 Feb 2015 16:36:58 -0500 Subject: [PATCH 1/5] whitelist editor now uses checkboxes, closes #773 --- .../src/main/webapp/resources/js/whitelist.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openid-connect-server-webapp/src/main/webapp/resources/js/whitelist.js b/openid-connect-server-webapp/src/main/webapp/resources/js/whitelist.js index 01374c265..125cc4515 100644 --- a/openid-connect-server-webapp/src/main/webapp/resources/js/whitelist.js +++ b/openid-connect-server-webapp/src/main/webapp/resources/js/whitelist.js @@ -340,7 +340,7 @@ var WhiteListFormView = Backbone.View.extend({ var scopeView = new ListWidgetView({ placeholder: $.t('whitelist.whitelist-form.scope-placeholder'), - autocomplete: this.options.client.scope, + autocomplete: this.options.client.get("scope"), helpBlockText: $.t('whitelist.whitelist-form.scope-help'), collection: this.scopeCollection}); $("#scope .controls",this.el).html(scopeView.render().el); From 692e8418d68dc10e17515fa187258a2ed815d8e6 Mon Sep 17 00:00:00 2001 From: Justin Richer Date: Thu, 26 Feb 2015 21:05:01 -0500 Subject: [PATCH 2/5] fixed whitelist deep linking, closes #718 --- .../src/main/webapp/resources/js/admin.js | 71 +++++++++---------- .../src/main/webapp/resources/js/whitelist.js | 71 ++++++++++++++++++- .../webapp/resources/template/whitelist.html | 1 - 3 files changed, 103 insertions(+), 40 deletions(-) diff --git a/openid-connect-server-webapp/src/main/webapp/resources/js/admin.js b/openid-connect-server-webapp/src/main/webapp/resources/js/admin.js index 4c9a9447c..2e83f1622 100644 --- a/openid-connect-server-webapp/src/main/webapp/resources/js/admin.js +++ b/openid-connect-server-webapp/src/main/webapp/resources/js/admin.js @@ -729,33 +729,33 @@ var AppRouter = Backbone.Router.extend({ return; } + this.breadCrumbView.collection.reset(); + this.breadCrumbView.collection.add([ + {text:$.t('admin.home'), href:""}, + {text:$.t('whitelist.manage'), href:"manage/#admin/whitelists"}, + {text:$.t('whitelist.new'), href:"manage/#admin/whitelist/new/" + cid} + ]); + this.updateSidebar('admin/whitelists'); + + //// + var whiteList = this.whiteListList.get(id); + whiteList = new WhiteListModel({id: id}); var client = this.clientList.get(cid); - - // if there's no client this is an error - if (client != null) { - - this.breadCrumbView.collection.reset(); - this.breadCrumbView.collection.add([ - {text:$.t('admin.home'), href:""}, - {text:$.t('whitelist.manage'), href:"manage/#admin/whitelists"}, - {text:$.t('whitelist.new'), href:"manage/#admin/whitelist/new/" + cid} - ]); - - var whiteList = new WhiteListModel(); - whiteList.set({ - clientId: client.get('clientId'), - allowedScopes: client.get('scope') - }, { silent: true }); - - this.whiteListFormView = new WhiteListFormView({model: whiteList, client: client, systemScopeList: this.systemScopeList}); - $('#content').html(this.whiteListFormView.render().el); - setPageTitle($.t('whitelist.new')); - } else { - console.log('ERROR: no client found for ' + cid); + if (!client) { + client = new ClientModel({id: cid}); } + var view = new WhiteListFormView({model: whiteList, client: client, systemScopeList: this.systemScopeList}); + + view.load( + function() { + $('#content').html(view.render().el); + view.delegateEvents(); + setPageTitle($.t('whitelist.manage')); + } + ); }, @@ -776,21 +776,20 @@ var AppRouter = Backbone.Router.extend({ this.updateSidebar('admin/whitelists'); var whiteList = this.whiteListList.get(id); - if (whiteList != null) { - var client = app.clientList.getByClientId(whiteList.get('clientId')); - - // if there's no client, this is an error - if (client != null) { - this.whiteListFormView = new WhiteListFormView({model: whiteList, client: client, systemScopeList: this.systemScopeList}); - $('#content').html(this.whiteListFormView.render().el); - setPageTitle($.t('whitelist.edit')); - - } else { - console.log('ERROR: no client found for ' + whiteList.get('clientId')); - } - } else { - console.error('ERROR: no whitelist found for id ' + id); + if (!whiteList) { + whiteList = new WhiteListModel({id: id}); } + + var view = new WhiteListFormView({model: whiteList, clientList: this.clientList, systemScopeList: this.systemScopeList}); + + view.load( + function() { + $('#content').html(view.render().el); + view.delegateEvents(); + setPageTitle($.t('whitelist.manage')); + } + ); + }, approvedSites:function() { diff --git a/openid-connect-server-webapp/src/main/webapp/resources/js/whitelist.js b/openid-connect-server-webapp/src/main/webapp/resources/js/whitelist.js index 125cc4515..a39a72eda 100644 --- a/openid-connect-server-webapp/src/main/webapp/resources/js/whitelist.js +++ b/openid-connect-server-webapp/src/main/webapp/resources/js/whitelist.js @@ -256,6 +256,73 @@ var WhiteListFormView = Backbone.View.extend({ }, + load:function(callback) { + + if (this.options.client) { + // we know what client we're dealing with already + if (this.model.isFetched && + this.options.client.isFetched()) { + callback(); + return; + } + + $('#loadingbox').sheet('show'); + $('#loading').html( + '' + $.t('whitelist.whitelist') + ' ' + + '' + $.t('common.clients') + ' ' + + '' + $.t('common.scopes') + ' ' + ); + + $.when(this.model.fetchIfNeeded({success:function(e) {$('#loading-whitelist').addClass('label-success');}}), + this.options.client.fetchIfNeeded({success:function(e) {$('#loading-clients').addClass('label-success');}}), + this.options.systemScopeList.fetchIfNeeded({success:function(e) {$('#loading-scopes').addClass('label-success');}})) + .done(function() { + $('#loadingbox').sheet('hide'); + callback(); + }); + + } else { + // we need to get the client information from the list + + if (this.model.isFetched && + this.options.clientList.isFetched && + this.options.systemScopeList.isFetched) { + + var client = this.options.clientList.getByClientId(this.model.get('clientId')); + this.options.client = client; + + callback(); + return; + } + + $('#loadingbox').sheet('show'); + $('#loading').html( + '' + $.t('whitelist.whitelist') + ' ' + + '' + $.t('common.clients') + ' ' + + '' + $.t('common.scopes') + ' ' + ); + + var _self = this; + + $.when(this.model.fetchIfNeeded({success:function(e) {$('#loading-whitelist').addClass('label-success');}}), + this.options.clientList.fetchIfNeeded({success:function(e) {$('#loading-clients').addClass('label-success');}}), + this.options.systemScopeList.fetchIfNeeded({success:function(e) {$('#loading-scopes').addClass('label-success');}})) + .done(function() { + + var client = _self.options.clientList.getByClientId(_self.model.get('clientId')); + _self.options.client = client; + + $('#loadingbox').sheet('hide'); + callback(); + }); + + } + + + + + }, + events:{ 'click .btn-save':'saveWhiteList', 'click .btn-cancel':'cancelWhiteList', @@ -274,9 +341,7 @@ var WhiteListFormView = Backbone.View.extend({ // process allowed scopes var allowedScopes = this.scopeCollection.pluck("item"); - if (this.model.get('id') == null) { - this.model.set({clientId:$('#clientId input').val()}); - } + this.model.set(this.options.client.get('clientId')); var valid = this.model.set({ allowedScopes: allowedScopes diff --git a/openid-connect-server-webapp/src/main/webapp/resources/template/whitelist.html b/openid-connect-server-webapp/src/main/webapp/resources/template/whitelist.html index 3f9cc2e78..102578a71 100644 --- a/openid-connect-server-webapp/src/main/webapp/resources/template/whitelist.html +++ b/openid-connect-server-webapp/src/main/webapp/resources/template/whitelist.html @@ -87,7 +87,6 @@
- <%- client.clientName != null ? client.clientName : ( client.clientId.substr(0,8) + '...' ) %>
From d570497b1623a9b5558a8a94c7f6aa47abd31657 Mon Sep 17 00:00:00 2001 From: Justin Richer Date: Thu, 26 Feb 2015 21:17:40 -0500 Subject: [PATCH 3/5] fixed some bugs in whitelist rendering and saving --- .../src/main/webapp/resources/js/admin.js | 8 +++++--- .../src/main/webapp/resources/js/whitelist.js | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/openid-connect-server-webapp/src/main/webapp/resources/js/admin.js b/openid-connect-server-webapp/src/main/webapp/resources/js/admin.js index 2e83f1622..cf710eead 100644 --- a/openid-connect-server-webapp/src/main/webapp/resources/js/admin.js +++ b/openid-connect-server-webapp/src/main/webapp/resources/js/admin.js @@ -738,9 +738,7 @@ var AppRouter = Backbone.Router.extend({ this.updateSidebar('admin/whitelists'); - //// - var whiteList = this.whiteListList.get(id); - whiteList = new WhiteListModel({id: id}); + var whiteList = new WhiteListModel(); var client = this.clientList.get(cid); if (!client) { @@ -751,6 +749,10 @@ var AppRouter = Backbone.Router.extend({ view.load( function() { + + // set the scopes on the model now that everything's loaded + whiteList.set({allowedScopes: client.get('scope')}, {silent: true}); + $('#content').html(view.render().el); view.delegateEvents(); setPageTitle($.t('whitelist.manage')); diff --git a/openid-connect-server-webapp/src/main/webapp/resources/js/whitelist.js b/openid-connect-server-webapp/src/main/webapp/resources/js/whitelist.js index a39a72eda..524e64ebb 100644 --- a/openid-connect-server-webapp/src/main/webapp/resources/js/whitelist.js +++ b/openid-connect-server-webapp/src/main/webapp/resources/js/whitelist.js @@ -341,7 +341,7 @@ var WhiteListFormView = Backbone.View.extend({ // process allowed scopes var allowedScopes = this.scopeCollection.pluck("item"); - this.model.set(this.options.client.get('clientId')); + this.model.set({clientId: this.options.client.get('clientId')}, {silent: true}); var valid = this.model.set({ allowedScopes: allowedScopes From 45754d3b758b142ad398e4e5d775510848a9c3ab Mon Sep 17 00:00:00 2001 From: Justin Richer Date: Fri, 27 Feb 2015 08:47:39 -0500 Subject: [PATCH 4/5] made clients robust against deep links --- .../src/main/webapp/resources/js/admin.js | 71 ++++++------------- .../src/main/webapp/resources/js/client.js | 21 +++--- .../src/main/webapp/resources/js/whitelist.js | 2 +- 3 files changed, 32 insertions(+), 62 deletions(-) diff --git a/openid-connect-server-webapp/src/main/webapp/resources/js/admin.js b/openid-connect-server-webapp/src/main/webapp/resources/js/admin.js index cf710eead..0aa15e796 100644 --- a/openid-connect-server-webapp/src/main/webapp/resources/js/admin.js +++ b/openid-connect-server-webapp/src/main/webapp/resources/js/admin.js @@ -33,6 +33,7 @@ Backbone.Model.prototype.fetchIfNeeded = function(options) { return options.success(this, null); } }; + Backbone.Collection.prototype.fetchIfNeeded = function(options) { var _self = this; if (!options) { @@ -639,58 +640,26 @@ var AppRouter = Backbone.Router.extend({ this.updateSidebar('admin/clients'); var client = this.clientList.get(id); - - if (client == null) { - // it wasn't in the list, try loading the client directly - client = new ClientModel({id: id}); + if (!client) { + client = new ClientModel({id:id}); } - - $('#loadingbox').sheet('show'); - $('#loading').html( - '' + $.t('common.scopes') + ' ' - + '' + $.t('common.client') + ' '); - - // re-sync the client every time - client.fetch({ - success: function(client, response, options) { - $('#loading-client').addClass('label-success'); - - if ($.inArray("refresh_token", client.get("grantTypes")) != -1) { - client.set({ - allowRefresh: true - }, { silent: true }); - } - - client.set({ - generateClientSecret:false, - displayClientSecret:false - }, { silent: true }); - - var view = new ClientFormView({model:client, systemScopeList: app.systemScopeList}); - view.load(function() { - $('#content').html(view.render().el); - setPageTitle($.t('client.client-form.edit')); - }); - - - }, - error: function(model, response, options) { - - //Pull out the response text. - var responseJson = JSON.parse(response.responseText); - - //Display an alert with an error message - $('#modalAlert div.modal-header').html(responseJson.error); - $('#modalAlert div.modal-body').html(responseJson.error_description); - - $("#modalAlert").modal({ // wire up the actual modal functionality and show the dialog - "backdrop" : "static", - "keyboard" : true, - "show" : true // ensure the modal is shown immediately - }); - - } - }); + + var view = new ClientFormView({model:client, systemScopeList: app.systemScopeList}); + view.load(function() { + if ($.inArray("refresh_token", client.get("grantTypes")) != -1) { + client.set({ + allowRefresh: true + }, { silent: true }); + } + + client.set({ + generateClientSecret:false, + displayClientSecret:false + }, { silent: true }); + + $('#content').html(view.render().el); + setPageTitle($.t('client.client-form.edit')); + }); }, diff --git a/openid-connect-server-webapp/src/main/webapp/resources/js/client.js b/openid-connect-server-webapp/src/main/webapp/resources/js/client.js index 2a5f16d67..5cb704b5e 100644 --- a/openid-connect-server-webapp/src/main/webapp/resources/js/client.js +++ b/openid-connect-server-webapp/src/main/webapp/resources/js/client.js @@ -644,20 +644,21 @@ var ClientFormView = Backbone.View.extend({ }, load:function(callback) { - if (this.options.systemScopeList.isFetched) { - $('#loadingbox').sheet('hide'); + if (this.model.isFetched && + this.options.systemScopeList.isFetched) { callback(); return; } - if (this.model.get('id') == null) { - // only show the box if this is a new client, otherwise the box is already showing - $('#loadingbox').sheet('show'); - $('#loading').html('' + $.t("common.scopes") + ' '); - } - - $.when(this.options.systemScopeList.fetchIfNeeded({success:function(e) {$('#loading-scopes').addClass('label-success');}})) - .done(function() { + $('#loadingbox').sheet('show'); + $('#loading').html( + '' + $.t('common.clients') + ' ' + + '' + $.t("common.scopes") + ' ' + ); + + $.when(this.options.systemScopeList.fetchIfNeeded({success:function(e) {$('#loading-scopes').addClass('label-success');}}), + this.model.fetchIfNeeded({success:function(e) {$('#loading-clients').addClass('label-success');}})) + .done(function() { $('#loadingbox').sheet('hide'); callback(); }); diff --git a/openid-connect-server-webapp/src/main/webapp/resources/js/whitelist.js b/openid-connect-server-webapp/src/main/webapp/resources/js/whitelist.js index 524e64ebb..a7b169a1a 100644 --- a/openid-connect-server-webapp/src/main/webapp/resources/js/whitelist.js +++ b/openid-connect-server-webapp/src/main/webapp/resources/js/whitelist.js @@ -261,7 +261,7 @@ var WhiteListFormView = Backbone.View.extend({ if (this.options.client) { // we know what client we're dealing with already if (this.model.isFetched && - this.options.client.isFetched()) { + this.options.client.isFetched) { callback(); return; } From c8cf2abbd91c61150f564dbb301b76846e947564 Mon Sep 17 00:00:00 2001 From: Justin Richer Date: Fri, 27 Feb 2015 10:15:36 -0500 Subject: [PATCH 5/5] made scopes robust against deep links --- .../src/main/webapp/resources/js/admin.js | 19 +++++++++++++------ .../src/main/webapp/resources/js/scope.js | 19 +++++++++++++++++++ 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/openid-connect-server-webapp/src/main/webapp/resources/js/admin.js b/openid-connect-server-webapp/src/main/webapp/resources/js/admin.js index 0aa15e796..7bf63180a 100644 --- a/openid-connect-server-webapp/src/main/webapp/resources/js/admin.js +++ b/openid-connect-server-webapp/src/main/webapp/resources/js/admin.js @@ -882,9 +882,11 @@ var AppRouter = Backbone.Router.extend({ var scope = new SystemScopeModel(); - this.systemScopeFormView = new SystemScopeFormView({model:scope}); - $('#content').html(this.systemScopeFormView.render().el); - setPageTitle($.t('scope.system-scope-form.new')); + var view = new SystemScopeFormView({model:scope}); + view.load(function() { + $('#content').html(view.render().el); + setPageTitle($.t('scope.system-scope-form.new')); + }); }, @@ -905,10 +907,15 @@ var AppRouter = Backbone.Router.extend({ this.updateSidebar('admin/scope'); var scope = this.systemScopeList.get(sid); + if (!scope) { + scope = new SystemScopeModel({id: sid}); + } - this.systemScopeFormView = new SystemScopeFormView({model:scope}); - $('#content').html(this.systemScopeFormView.render().el); - setPageTitle($.t('scope.system-scope-form.edit')); + var view = new SystemScopeFormView({model:scope}); + view.load(function() { + $('#content').html(view.render().el); + setPageTitle($.t('scope.system-scope-form.new')); + }); }, diff --git a/openid-connect-server-webapp/src/main/webapp/resources/js/scope.js b/openid-connect-server-webapp/src/main/webapp/resources/js/scope.js index 732d44456..0c6793cb9 100644 --- a/openid-connect-server-webapp/src/main/webapp/resources/js/scope.js +++ b/openid-connect-server-webapp/src/main/webapp/resources/js/scope.js @@ -284,6 +284,25 @@ var SystemScopeFormView = Backbone.View.extend({ 'change #isStructured input':'toggleStructuredParamDescription' }, + load:function(callback) { + if (this.model.isFetched) { + callback(); + return; + } + + $('#loadingbox').sheet('show'); + $('#loading').html( + '' + $.t("common.scopes") + ' ' + ); + + $.when(this.model.fetchIfNeeded({success:function(e) {$('#loading-scopes').addClass('label-success');}})) + .done(function() { + $('#loadingbox').sheet('hide'); + callback(); + }); + + }, + toggleStructuredParamDescription:function(e) { if ($('#isStructured input', this.el).is(':checked')) { $('#structuredParamDescription', this.el).show();