system scope service applied to client creation UI

pull/306/merge
Justin Richer 2013-01-31 13:58:49 -05:00
parent cab36a2b80
commit a3037a18a7
3 changed files with 50 additions and 9 deletions

View File

@ -7,6 +7,7 @@ import java.util.HashSet;
import java.util.Set;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceUnit;
import javax.persistence.TypedQuery;
@ -25,7 +26,7 @@ import static org.mitre.util.jpa.JpaUtil.saveOrUpdate;
@Repository("jpaSystemScopeRepository")
public class JpaSystemScopeRepository implements SystemScopeRepository {
@PersistenceUnit
@PersistenceContext
private EntityManager em;
/* (non-Javadoc)

View File

@ -160,7 +160,7 @@ CREATE TABLE IF NOT EXISTS token_scope (
scope VARCHAR(2048)
);
CREATE TABLE IF NOT EXISTS site_scope (
CREATE TABLE IF NOT EXISTS system_scope (
id BIGINT GENERATED BY DEFAULT AS IDENTITY(START WITH 1) PRIMARY KEY,
scope VARCHAR(1024),
description VARCHAR(4096),

View File

@ -190,6 +190,40 @@
url: 'api/approved'
});
var SystemScopeModel = Backbone.Model.extend({
idAttribute: 'id',
/*
// fake the 'item' portion
get: function (attr) {
if (attr == 'item') {
attr = 'value';
}
return Backbone.Model.prototype.get.call(this, attr);
},
*/
urlRoot: 'api/scopes'
});
var SystemScopeCollection = Backbone.Collection.extend({
idAttribute: 'id',
model: SystemScopeModel,
url: 'api/scopes',
defaultScopes: function() {
filtered = this.filter(function(scope) {
return scope.get("defaultScope") === true;
});
return new SystemScopeCollection(filtered);
},
});
var ClientModel = Backbone.Model.extend({
idAttribute: "id",
@ -214,7 +248,7 @@
clientSecret:"",
registeredRedirectUri:[],
authorizedGrantTypes:["authorization_code"],
scope:["openid"],
scope:[],
authorities:[],
clientDescription:"",
logoUrl:"",
@ -633,7 +667,7 @@
});
$("#scope .controls",this.el).html(new ListWidgetView({placeholder: 'new scope here'
, autocomplete: _.uniq(_.flatten(app.clientList.pluck("scope")))
, autocomplete: _.uniq(_.flatten(app.systemScopes.defaultScopes.pluck("value"))) // TODO: load from default scopes
, collection: this.scopeCollection}).render().el);
if (!this.model.get("allowRefresh")) {
@ -1030,6 +1064,7 @@
this.whiteListList = new WhiteListCollection();
this.blackListList = new BlackListCollection();
this.approvedSiteList = new ApprovedSiteCollection();
this.systemScopes = new SystemScopeCollection();
this.clientListView = new ClientListView({model:this.clientList});
this.whiteListListView = new WhiteListListView({model:this.whiteListList});
@ -1048,12 +1083,16 @@
//
// load things in the right order:
this.clientList.fetch({
this.systemScopes.fetch({
success: function(collection, response) {
app.whiteListList.fetch({
this.clientList.fetch({
success: function(collection, response) {
var baseUrl = $.url($('base').attr('href'));
Backbone.history.start({pushState: true, root: baseUrl.attr('relative') + 'manage/'});
app.whiteListList.fetch({
success: function(collection, response) {
var baseUrl = $.url($('base').attr('href'));
Backbone.history.start({pushState: true, root: baseUrl.attr('relative') + 'manage/'});
}
});
}
});
}
@ -1089,7 +1128,8 @@
client.set({
requireClientSecret:true,
generateClientSecret:true,
displayClientSecret:false
displayClientSecret:false,
scope: _.uniq(_.flatten(this.systemScopes.defaultScopes.pluck("value"))),
}, { silent: true });
this.clientFormView = new ClientFormView({model:client});