From 3e931c68b46b8b40b5dcfa67fbf008e9ad2f8244 Mon Sep 17 00:00:00 2001 From: Justin Richer Date: Fri, 20 Mar 2015 17:27:10 -0400 Subject: [PATCH] added policy editing overview page --- .../main/webapp/WEB-INF/tags/actionmenu.tag | 1 + .../src/main/webapp/WEB-INF/tags/footer.tag | 1 + .../src/main/webapp/resources/js/admin.js | 27 ++- .../resources/js/locale/en/messages.json | 13 +- .../src/main/webapp/resources/js/policy.js | 188 ++++++++++++++++++ .../src/main/webapp/resources/js/whitelist.js | 6 +- .../webapp/resources/template/policy.html | 59 ++++++ .../ResourceSetEntityAbbreviatedView.java | 2 +- .../web/ResourceSetRegistrationEndpoint.java | 4 +- 9 files changed, 290 insertions(+), 11 deletions(-) create mode 100644 openid-connect-server-webapp/src/main/webapp/resources/js/policy.js create mode 100644 openid-connect-server-webapp/src/main/webapp/resources/template/policy.html diff --git a/openid-connect-server-webapp/src/main/webapp/WEB-INF/tags/actionmenu.tag b/openid-connect-server-webapp/src/main/webapp/WEB-INF/tags/actionmenu.tag index d391a30ad..47df4a361 100644 --- a/openid-connect-server-webapp/src/main/webapp/WEB-INF/tags/actionmenu.tag +++ b/openid-connect-server-webapp/src/main/webapp/WEB-INF/tags/actionmenu.tag @@ -14,6 +14,7 @@
  • +
  • diff --git a/openid-connect-server-webapp/src/main/webapp/WEB-INF/tags/footer.tag b/openid-connect-server-webapp/src/main/webapp/WEB-INF/tags/footer.tag index a089cc2bb..d5888ef7c 100644 --- a/openid-connect-server-webapp/src/main/webapp/WEB-INF/tags/footer.tag +++ b/openid-connect-server-webapp/src/main/webapp/WEB-INF/tags/footer.tag @@ -30,6 +30,7 @@ + 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 7bf63180a..e7d074214 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 @@ -503,6 +503,7 @@ var AppRouter = Backbone.Router.extend({ "user/approved":"approvedSites", "user/tokens":"tokens", "user/profile":"profile", + "user/policy":"policy", "dev/dynreg":"dynReg", "dev/dynreg/new":"newDynReg", @@ -534,6 +535,7 @@ var AppRouter = Backbone.Router.extend({ this.clientStats = new StatsModel(); this.accessTokensList = new AccessTokenCollection(); this.refreshTokensList = new RefreshTokenCollection(); + this.resourceSetList = new ResourceSetCollection(); this.breadCrumbView = new BreadCrumbView({ collection:new Backbone.Collection() @@ -1068,13 +1070,31 @@ var AppRouter = Backbone.Router.extend({ this.updateSidebar('user/profile'); - this.userProfileView = new UserProfileView({model: getUserInfo()}); - $('#content').html(this.userProfileView.render().el); + var view = new UserProfileView({model: getUserInfo()}); + $('#content').html(view.render().el); setPageTitle($.t('admin.user-profile.show')); }, + policy:function() { + this.breadCrumbView.collection.reset(); + this.breadCrumbView.collection.add([ + {text:$.t('admin.home'), href:""}, + {text:$.t('policy.resource-sets'), href:"manage/#user/profile"} + ]); + + this.updateSidebar('user/policy'); + + var view = new ResourceSetListView({model: this.resourceSetList, clientList: this.clientList, systemScopeList: this.systemScopeList}); + + view.load(function() { + $('#content').html(view.render().el); + setPageTitle($.t('policy.resource-sets')); + }); + + }, + updateSidebar:function(item) { $('.sidebar-nav li.active').removeClass('active'); @@ -1102,7 +1122,8 @@ $(function () { $.get('resources/template/whitelist.html', _load), $.get('resources/template/dynreg.html', _load), $.get('resources/template/rsreg.html', _load), - $.get('resources/template/token.html', _load) + $.get('resources/template/token.html', _load), + $.get('resources/template/policy.html', _load) ).done(function() { $.ajaxSetup({cache:false}); app = new AppRouter(); diff --git a/openid-connect-server-webapp/src/main/webapp/resources/js/locale/en/messages.json b/openid-connect-server-webapp/src/main/webapp/resources/js/locale/en/messages.json index f6be64552..8b921d949 100644 --- a/openid-connect-server-webapp/src/main/webapp/resources/js/locale/en/messages.json +++ b/openid-connect-server-webapp/src/main/webapp/resources/js/locale/en/messages.json @@ -17,7 +17,8 @@ "show": "View User Profile", "text": "Your user profile has the following information:", "value": "Claim value:" - } + }, + "policies": "Manage Protected Resource Policies" }, "client": { "client-form": { @@ -337,6 +338,13 @@ "whitelist-table": { "no-sites": "There are no whitelisted sites. Use the whitelist button on the client management page to create one." } + }, + "policy" : { + "resource-sets": "Resource sets", + "policy-table": { + "edit": "Edit Policies", + "no-resource-sets": "There are no resource sets registered. Introduce a protected to this authorization server to let it register some." + } }, "copyright": "Powered by MITREid Connect {0} © 2015 The MITRE Corporation and MIT KIT..", "about": { @@ -396,7 +404,8 @@ "title": "Personal", "approved_sites": "Manage Approved Sites", "active_tokens": "Manage Active Tokens", - "profile_information": "View Profile Information" + "profile_information": "View Profile Information", + "resource_policies": "Manage Protected Resource Policies" }, "developer": { "title": "Developer", diff --git a/openid-connect-server-webapp/src/main/webapp/resources/js/policy.js b/openid-connect-server-webapp/src/main/webapp/resources/js/policy.js new file mode 100644 index 000000000..719a27225 --- /dev/null +++ b/openid-connect-server-webapp/src/main/webapp/resources/js/policy.js @@ -0,0 +1,188 @@ +/******************************************************************************* + * Copyright 2015 The MITRE Corporation + * and the MIT Kerberos and Internet Trust Consortium + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *******************************************************************************/ + +var ResourceSetModel = Backbone.Model.extend({ + +}); + +var ResourceSetCollection = Backbone.Collection.extend({ + model: ResourceSetModel, + url: 'api/claims' +}); + +var ClaimModel = Backbone.Model.extend({ + +}); + +var ClaimCollection = Backbone.Collection.extend({ + model: ClaimModel +}); + +var ResourceSetListView = Backbone.View.extend({ + tagName: 'span', + + initialize:function (options) { + this.options = options; + }, + + load:function(callback) { + if (this.model.isFetched && + this.options.clientList.isFetched && + this.options.systemScopeList.isFetched) { + callback(); + return; + } + + $('#loadingbox').sheet('show'); + $('#loading').html( + '' + $.t('policy.resource-sets') + ' ' + + '' + $.t('common.clients') + ' ' + + '' + $.t('common.scopes') + ' ' + ); + + $.when(this.model.fetchIfNeeded({success:function(e) {$('#loading-resourcesets').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() { + $('#loadingbox').sheet('hide'); + callback(); + }); + }, + + events: { + "click .refresh-table":"refreshTable" + }, + + render:function (eventName) { + $(this.el).html($('#tmpl-resource-set-table').html()); + + var _self = this; + + _.each(this.model.models, function (resourceSet) { + + // look up client + var client = this.options.clientList.getByClientId(resourceSet.get('clientId')); + + // if there's no client ID, this is an error! + if (client != null) { + var view = new ResourceSetView({model: resourceSet, client: client, systemScopeList: _self.options.systemScopeList}); + view.parentView = _self; + $('#resource-set-table', this.el).append(view.render().el); + } + + }, this); + + this.togglePlaceholder(); + $(this.el).i18n(); + return this; + }, + + togglePlaceholder:function() { + if (this.model.length > 0) { + $('#resource-set-table', this.el).show(); + $('#resource-set-table-empty', this.el).hide(); + } else { + $('#resource-set-table', this.el).hide(); + $('#resource-set-table-empty', this.el).show(); + } + }, + + refreshTable:function(e) { + e.preventDefault(); + var _self = this; + $('#loadingbox').sheet('show'); + $('#loading').html( + '' + $.t('policy.resource-sets') + ' ' + + '' + $.t('common.clients') + ' ' + + '' + $.t('common.scopes') + ' ' + ); + + $.when(this.model.fetch({success:function(e) {$('#loading-resourcesets').addClass('label-success');}}), + this.options.clientList.fetch({success:function(e) {$('#loading-clients').addClass('label-success');}}), + this.options.systemScopeList.fetch({success:function(e) {$('#loading-scopes').addClass('label-success');}})) + .done(function() { + $('#loadingbox').sheet('hide'); + _self.render(); + }); + } + + +}); + + +var ResourceSetView = Backbone.View.extend({ + tagName: 'tr', + + initialize:function(options) { + this.options = options; + if (!this.template) { + this.template = _.template($('#tmpl-resource-set').html()); + } + + if (!this.scopeTemplate) { + this.scopeTemplate = _.template($('#tmpl-scope-list').html()); + } + + if (!this.moreInfoTemplate) { + this.moreInfoTemplate = _.template($('#tmpl-client-more-info-block').html()); + } + + this.model.bind('change', this.render, this); + }, + + render:function(eventName) { + + var json = {rs: this.model.toJSON(), client: this.options.client.toJSON()}; + + this.$el.html(this.template(json)); + + $('.scope-list', this.el).html(this.scopeTemplate({scopes: this.model.get('scopes'), systemScopes: this.options.systemScopeList})); + + $('.client-more-info-block', this.el).html(this.moreInfoTemplate({client: this.options.client.toJSON()})); + + $(this.el).i18n(); + return this; + }, + + events:{ + 'click .btn-edit': 'editPolicies', + 'click .toggleMoreInformation': 'toggleMoreInformation' + }, + + editPolicies:function(e) { + e.preventDefault(); + app.navigate('user/policy/' + this.model.get('id'), {trigger: true}); + }, + + toggleMoreInformation:function(e) { + e.preventDefault(); + if ($('.moreInformation', this.el).is(':visible')) { + // hide it + $('.moreInformation', this.el).hide('fast'); + $('.toggleMoreInformation i', this.el).attr('class', 'icon-chevron-right'); + $('.moreInformationContainer', this.el).removeClass('alert').removeClass('alert-info').addClass('muted'); + + } else { + // show it + $('.moreInformation', this.el).show('fast'); + $('.toggleMoreInformation i', this.el).attr('class', 'icon-chevron-down'); + $('.moreInformationContainer', this.el).addClass('alert').addClass('alert-info').removeClass('muted'); + } + }, + + +}); \ No newline at end of file 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 a7b169a1a..965da262e 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 @@ -86,13 +86,13 @@ var WhiteListListView = Backbone.View.extend({ _.each(this.model.models, function (whiteList) { // look up client - var client = this.options.clientList.getByClientId(whiteList.get('clientId')); + var client = _self.options.clientList.getByClientId(whiteList.get('clientId')); // if there's no client ID, this is an error! if (client != null) { - var view = new WhiteListView({model: whiteList, client: client, systemScopeList: this.options.systemScopeList}); + var view = new WhiteListView({model: whiteList, client: client, systemScopeList: _self.options.systemScopeList}); view.parentView = _self; - $('#whitelist-table', this.el).append(view.render().el); + $('#whitelist-table', _self.el).append(view.render().el); } }, this); diff --git a/openid-connect-server-webapp/src/main/webapp/resources/template/policy.html b/openid-connect-server-webapp/src/main/webapp/resources/template/policy.html new file mode 100644 index 000000000..0b58f12b8 --- /dev/null +++ b/openid-connect-server-webapp/src/main/webapp/resources/template/policy.html @@ -0,0 +1,59 @@ + + + + + + + diff --git a/openid-connect-server/src/main/java/org/mitre/uma/view/ResourceSetEntityAbbreviatedView.java b/openid-connect-server/src/main/java/org/mitre/uma/view/ResourceSetEntityAbbreviatedView.java index 780ae2481..c95096afb 100644 --- a/openid-connect-server/src/main/java/org/mitre/uma/view/ResourceSetEntityAbbreviatedView.java +++ b/openid-connect-server/src/main/java/org/mitre/uma/view/ResourceSetEntityAbbreviatedView.java @@ -86,7 +86,7 @@ public class ResourceSetEntityAbbreviatedView extends AbstractView { JsonObject o = new JsonObject(); o.addProperty("_id", rs.getId().toString()); // set the ID to a string - o.addProperty("user_access_policy_uri", config.getIssuer() + "manage/policy/" + rs.getId()); + o.addProperty("user_access_policy_uri", config.getIssuer() + "manage/user/policy/" + rs.getId()); gson.toJson(o, out); diff --git a/openid-connect-server/src/main/java/org/mitre/uma/web/ResourceSetRegistrationEndpoint.java b/openid-connect-server/src/main/java/org/mitre/uma/web/ResourceSetRegistrationEndpoint.java index 0b624ac56..b7270f697 100644 --- a/openid-connect-server/src/main/java/org/mitre/uma/web/ResourceSetRegistrationEndpoint.java +++ b/openid-connect-server/src/main/java/org/mitre/uma/web/ResourceSetRegistrationEndpoint.java @@ -127,14 +127,14 @@ public class ResourceSetRegistrationEndpoint { /////// // TODO: REMOVE /////// - /* + Claim c = new Claim(); c.setName("email"); c.setValue("bob@bob.com"); c.setIssuer(Sets.newHashSet("https://bob.com/")); saved.setClaimsRequired(Sets.newHashSet(c)); saved = resourceSetService.update(saved, saved); - */ + /////// /// END: REMOVE ///////