You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ranger.apache.org by ma...@apache.org on 2015/01/08 09:50:51 UTC
incubator-ranger git commit: Ranger-203: Implemented Service edit,
and Policy create/update
Repository: incubator-ranger
Updated Branches:
refs/heads/stack 23da1956e -> 1f458f00f
Ranger-203: Implemented Service edit, and Policy create/update
Project: http://git-wip-us.apache.org/repos/asf/incubator-ranger/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ranger/commit/1f458f00
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ranger/tree/1f458f00
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ranger/diff/1f458f00
Branch: refs/heads/stack
Commit: 1f458f00f57c0e118a5822353795b2ef874a210d
Parents: 23da195
Author: Gautam Borad <gb...@gmail.com>
Authored: Thu Jan 8 00:50:15 2015 -0800
Committer: Madhan Neethiraj <ma...@apache.org>
Committed: Thu Jan 8 00:50:15 2015 -0800
----------------------------------------------------------------------
.gitignore | 1 +
.../service-defs/ranger-servicedef-hbase.json | 4 +-
.../service-defs/ranger-servicedef-hdfs.json | 2 +-
.../scripts/models/BackboneFormDataType.js | 78 ++++++++
.../scripts/views/policies/GroupPermList.js | 29 +--
.../views/policies/RangerPolicyCreate.js | 11 +-
.../scripts/views/policies/RangerPolicyForm.js | 179 +++----------------
.../views/policies/RangerPolicyTableLayout.js | 56 +++++-
.../scripts/views/policies/UserPermList.js | 34 ++--
.../scripts/views/service/ServiceCreate.js | 2 +-
.../webapp/scripts/views/service/ServiceForm.js | 39 +---
.../templates/policies/GroupPermItem.html | 2 +-
.../webapp/templates/policies/UserPermItem.html | 2 +-
13 files changed, 206 insertions(+), 233 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/1f458f00/.gitignore
----------------------------------------------------------------------
diff --git a/.gitignore b/.gitignore
index f665a6d..83beeef 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
*.class
+*.iml
.settings
.metadata
.classpath
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/1f458f00/plugin-common/src/main/resources/service-defs/ranger-servicedef-hbase.json
----------------------------------------------------------------------
diff --git a/plugin-common/src/main/resources/service-defs/ranger-servicedef-hbase.json b/plugin-common/src/main/resources/service-defs/ranger-servicedef-hbase.json
index 04127bb..2cecf44 100644
--- a/plugin-common/src/main/resources/service-defs/ranger-servicedef-hbase.json
+++ b/plugin-common/src/main/resources/service-defs/ranger-servicedef-hbase.json
@@ -24,9 +24,9 @@
[
{"name":"username","type":"string","mandatory":true,"label":"Username"},
{"name":"password","type":"password","mandatory":true,"label":"Password"},
- {"name":"hadoop.security.authentication","type":"enum","subtype":"authnType","mandatory":true,"defaultValue":"simple"},
+ {"name":"hadoop.security.authentication","type":"enum","subType":"authnType","mandatory":true,"defaultValue":"simple"},
{"name":"hbase.master.kerberos.principal","type":"string","mandatory":false,"defaultValue":""},
- {"name":"hbase.security.authentication","type":"enum","subtype":"authnType","mandatory":true,"defaultValue":"simple"},
+ {"name":"hbase.security.authentication","type":"enum","subType":"authnType","mandatory":true,"defaultValue":"simple"},
{"name":"hbase.zookeeper.property.clientPort","type":"int","mandatory":true,"defaultValue":"2181"},
{"name":"hbase.zookeeper.quorum","type":"string","mandatory":true,"defaultValue":""},
{"name":"zookeeper.znode.parent","type":"string","mandatory":true,"defaultValue":"/hbase"}
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/1f458f00/plugin-common/src/main/resources/service-defs/ranger-servicedef-hdfs.json
----------------------------------------------------------------------
diff --git a/plugin-common/src/main/resources/service-defs/ranger-servicedef-hdfs.json b/plugin-common/src/main/resources/service-defs/ranger-servicedef-hdfs.json
index 20ae6b9..b2431c7 100644
--- a/plugin-common/src/main/resources/service-defs/ranger-servicedef-hdfs.json
+++ b/plugin-common/src/main/resources/service-defs/ranger-servicedef-hdfs.json
@@ -35,7 +35,7 @@
{"name":"username","type":"string","mandatory":true,"label":"Username"},
{"name":"password","type":"password","mandatory":true,"label":"Password"},
{"name":"hadoop.security.authorization","type":"bool","mandatory":true,"defaultValue":"false"},
- {"name":"hadoop.security.authentication","type":"enum","subtype":"authnType","mandatory":true,"defaultValue":"simple"},
+ {"name":"hadoop.security.authentication","type":"enum","subType":"authnType","mandatory":true,"defaultValue":"simple"},
{"name":"hadoop.security.auth_to_local","type":"string","mandatory":false},
{"name":"dfs.datanode.kerberos.principal","type":"string","mandatory":false},
{"name":"dfs.namenode.kerberos.principal","type":"string","mandatory":false},
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/1f458f00/security-admin/src/main/webapp/scripts/models/BackboneFormDataType.js
----------------------------------------------------------------------
diff --git a/security-admin/src/main/webapp/scripts/models/BackboneFormDataType.js b/security-admin/src/main/webapp/scripts/models/BackboneFormDataType.js
new file mode 100644
index 0000000..6a040af
--- /dev/null
+++ b/security-admin/src/main/webapp/scripts/models/BackboneFormDataType.js
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+define(function(require) {
+ 'use strict';
+
+ var Backbone = require('backbone');
+
+ var FormDataType = Backbone.Model.extend({
+ type : [ 'string', 'boolean', 'int' ],
+ getFormElements : function(configs, enums, attrs, form) {
+// var attrs = [];
+ _.each(configs, function(v, k) {
+ if (v != null) {
+ var formObj = {};
+ switch (v.type) {
+ case 'string':formObj.type = 'Text';break;
+ case 'bool':
+ formObj.type = 'Checkbox';
+ formObj.options = { y : 'Yes',n : 'No'};
+ break;
+ case 'int':formObj.type = 'Number';break;
+ case 'enum':
+ var enumObj = _.find(enums, function(e) {return e && e.name == v.subType;});
+ formObj.type = 'Select';
+ formObj.options = _.pluck(_.compact(enumObj.elements),'label');
+ break;
+ case 'select2' :
+ formObj.type = 'Select2Remote';
+ formObj.pluginAttr = form.getPlugginAttr(false),
+ formObj.editorAttrs = {'data-placeholder': v.label },
+ formObj.options = function(callback, editor){
+ callback();
+ },
+ formObj.onFocusOpen = true
+ break;
+ case 'path' :
+ formObj.type = 'Text';
+ form.initilializePathPlugin = true;
+ form.pathFieldName = v.name;
+ break;
+ default:formObj.type = 'Text';break;
+ }
+
+ formObj.title = v.label || v.name;
+ formObj.validators = [];
+ if (_.has(v, 'mandatory') && v.mandatory) {
+ formObj.validators.push('required');
+ formObj.title = formObj.title + " *"
+ }
+ formObj['class'] = 'serviceConfig';
+ var name = v.name;
+ attrs[name] = formObj;
+ }
+ });
+ return attrs;
+
+ }
+ });
+ return FormDataType;
+
+});
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/1f458f00/security-admin/src/main/webapp/scripts/views/policies/GroupPermList.js
----------------------------------------------------------------------
diff --git a/security-admin/src/main/webapp/scripts/views/policies/GroupPermList.js b/security-admin/src/main/webapp/scripts/views/policies/GroupPermList.js
index dfc9c4a..2f15b58 100644
--- a/security-admin/src/main/webapp/scripts/views/policies/GroupPermList.js
+++ b/security-admin/src/main/webapp/scripts/views/policies/GroupPermList.js
@@ -39,7 +39,7 @@ define(function(require) {
return {
- permissions : this.getPerms(),
+ permissions : this.accessTypes,//this.getPerms(),
policyKnox : this.policyType == XAEnums.ServiceType.Service_KNOX.value ? true :false,
// policyStorm : this.policyType == XAEnums.ServiceType.Service_STORM.value ? true :false,
isModelNew : !this.model.has('editMode'),
@@ -71,10 +71,16 @@ define(function(require) {
});
}
}
+
},
onRender : function() {
var that = this;
+ this.accessItems = _.map(this.accessTypes, function(perm){
+ if(!_.isUndefined(perm))
+ return {'type':perm.label,isAllowed : false}
+ });
+
if(!_.isUndefined(this.model.get('groupName'))){
this.ui.selectGroups.val(this.model.get('groupName').split(','));
}
@@ -83,8 +89,10 @@ define(function(require) {
}
if(this.model.has('editMode') && this.model.get('editMode')){
_.each(this.model.get('accesses'), function(p){
- if(p.value)
+ if(p.isAllowed){
this.$el.find('input[data-name="' + p.type + '"]').attr('checked', 'checked');
+ _.each(this.accessItems,function(obj){ if(obj.type == p.type) obj.isAllowed=true;})
+ }
},this);
}
this.createGroupDropDown();
@@ -92,9 +100,6 @@ define(function(require) {
if(this.policyType == XAEnums.AssetType.ASSET_STORM.value){
this.renderStormPerms();
}
-
-
- this.accessItems = _.map(this.getPerms(), function(perm){ if(!_.isUndefined(perm)) return {'type':perm.label,value : false}});
},
groupDropDownChange : function(){
var that = this;
@@ -232,7 +237,7 @@ define(function(require) {
}
var curPerm = $el.find('input').data('id');
var curPermName = $el.find('input').data('name');
- if(!_.isUndefined(curPerm)){
+ if(!_.isUndefined(curPermName)){
var perms = [];
if(this.model.has('accesses')){
if(_.isArray(this.model.get('accesses')))
@@ -241,16 +246,16 @@ define(function(require) {
perms.push(this.model.get('accesses'));
}
if($el.find('input[type="checkbox"]').is(':checked')){
- _.each(that.accessItems, function(obj){ if(obj.type == curPermName) obj.value = true });
+ _.each(that.accessItems, function(obj){ if(obj.type == curPermName) obj.isAllowed = true });
- if(curPerm == XAEnums.XAPermType.XA_PERM_TYPE_ADMIN.value){
- $el.parent().find('input[type="checkbox"]:not(:checked)[data-id!="'+curPerm+'"]').map(function(){
- _.each(that.accessItems, function(obj){ if(obj.type == $(this).data('name')) obj.value = true }, this);
+ /*if(curPermName == XAEnums.XAPermType.XA_PERM_TYPE_ADMIN.value){
+ $el.parent().find('input[type="checkbox"]:not(:checked)[data-name!="'+curPermName+'"]').map(function(){
+ _.each(that.accessItems, function(obj){ if(obj.type == $(this).data('name')) obj.isAllowed = true }, this);
});
$el.parent().find('input[type="checkbox"]').prop('checked',true);
- }
+ }*/
} else {
- _.each(that.accessItems, function(obj){ if(obj.type == curPermName ) obj.value = false }, this);
+ _.each(that.accessItems, function(obj){ if(obj.type == curPermName ) obj.isAllowed = false }, this);
}
// this.checkDirtyFieldForCheckBox(perms);
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/1f458f00/security-admin/src/main/webapp/scripts/views/policies/RangerPolicyCreate.js
----------------------------------------------------------------------
diff --git a/security-admin/src/main/webapp/scripts/views/policies/RangerPolicyCreate.js b/security-admin/src/main/webapp/scripts/views/policies/RangerPolicyCreate.js
index bd2b71e..fa11698 100644
--- a/security-admin/src/main/webapp/scripts/views/policies/RangerPolicyCreate.js
+++ b/security-admin/src/main/webapp/scripts/views/policies/RangerPolicyCreate.js
@@ -102,9 +102,6 @@ define(function(require){
},
initializeServiceDef : function(){
- var service = _.find(XAEnums.ServiceType,function(service){
- return service.label.toUpperCase() == this.rangerService.get('type').toUpperCase();
- },this);
this.rangerServiceDefModel = new RangerServiceDef();
this.rangerServiceDefModel.url = "service/plugins/definitions/name/"+this.rangerService.get('type');
this.rangerServiceDefModel.fetch({
@@ -129,7 +126,7 @@ define(function(require){
},
/** all post render plugin initialization */
- initializePlugins: function(){
+ /* initializePlugins: function(){
},
popupCallBack : function(msg,validateObj){
var that = this;
@@ -140,7 +137,7 @@ define(function(require){
// that.savePolicy();
}
});
- },
+ },*/
onSave: function(){
var that = this, valid = false;
var errors = this.form.commit({validate : false});
@@ -281,7 +278,7 @@ define(function(require){
}
});
},
- onDelete :function(){
+ /*onDelete :function(){
var that = this;
XAUtil.confirmPopup({
//msg :localize.tt('msg.confirmDelete'),
@@ -307,7 +304,7 @@ define(function(require){
}
});
- },
+ },*/
onCancel : function(){
XAUtil.allowNavigation();
App.appRouter.navigate("#!/service/"+this.rangerService.id+"/policies",{trigger: true});
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/1f458f00/security-admin/src/main/webapp/scripts/views/policies/RangerPolicyForm.js
----------------------------------------------------------------------
diff --git a/security-admin/src/main/webapp/scripts/views/policies/RangerPolicyForm.js b/security-admin/src/main/webapp/scripts/views/policies/RangerPolicyForm.js
index 8bb5061..f0cb86b 100644
--- a/security-admin/src/main/webapp/scripts/views/policies/RangerPolicyForm.js
+++ b/security-admin/src/main/webapp/scripts/views/policies/RangerPolicyForm.js
@@ -36,7 +36,7 @@ define(function(require){
var GroupPermList = require('views/policies/GroupPermList');
var UserPermList = require('views/policies/UserPermList');
var RangerPolicyResource = require('models/RangerPolicyResource');
- var RangerPolicyResourceList = require('collections/RangerPolicyResourceList');
+ var BackboneFormDataType = require('models/BackboneFormDataType');
require('backbone-forms.list');
require('backbone-forms.templates');
@@ -109,40 +109,9 @@ define(function(require){
schema :function(){
var attrs = {};
var that = this;
- _.each(this.rangerServiceDefModel.get('resources'),function(v,k){
- if (v != null) {
+ var formDataType = new BackboneFormDataType();
+ attrs = formDataType.getFormElements(this.rangerServiceDefModel.get('resources'),this.rangerServiceDefModel.get('enums'), attrs, this);
- var formObj = {};
- switch(v.type){
- case 'string' : formObj.type = 'Text'; break;
- case 'select2' :
- formObj.type = 'Select2Remote';
- formObj.pluginAttr = that.getPlugginAttr(false),
- formObj.editorAttrs = {'data-placeholder': v.label },
- formObj.options = function(callback, editor){
- callback();
- },
- formObj.onFocusOpen = true
- break;
- case 'path' :
- formObj.type = 'Text';
- that.initilializePathPlugin = true;
- that.pathFieldName = v.name;
- break;
- default : formObj.type = 'Text'; break;
- }
-
- formObj.title = v.label || v.name;
- formObj.validators = [];
- if (_.has(v,'mandatory') && v.mandatory){
- formObj.validators.push('required');
- formObj.title = formObj.title +" *"
- }
- formObj['class'] = 'serviceConfig';
- var name = v.name;
- attrs[name] = formObj;
- }
- });
var attr1 = _.pick(_.result(this.model,'schemaBase'), 'name','isEnabled');
var attr2 = _.pick(_.result(this.model,'schemaBase'),'description', 'isRecursive', 'isAuditEnabled');
return _.extend(attr1,_.extend(attrs,attr2));
@@ -178,86 +147,10 @@ define(function(require){
evResourceStatusChange : function(form, fieldEditor){
XAUtil.checkDirtyFieldForToggle(fieldEditor);
},
- formValidation : function(){
- var groupSet = false,permSet = false,auditStatus= false,encryptStatus= false,groupPermSet = false,
- userSet=false,userPerm = false,isUsers =false;
- console.log('validation called..');
- var breakFlag =false;
- this.formInputList.each(function(m){
- if(m.has('groupId') || m.has('_vPermList')){
- if(! breakFlag){
- groupSet = m.has('groupId') ? true : false ;
- if(!m.has('_vPermList')){
- permSet = false;
- }else
- permSet = true;
- if(groupSet && permSet)
- groupPermSet = true;
- else
- breakFlag=true;
- }
- }
- });
- breakFlag = false;
-
- this.userPermInputList.each(function(m){
- if(! breakFlag){
- userSet = m.has('userId') || m.has('userName') ? true : false ;
- if(!m.has('_vPermList')){
- userPerm = false;
- }else
- userPerm = true;
- if(userSet && userPerm)
- isUsers = true;
- else
- breakFlag=true;
- }
- });
- var auditLoggin = this.fields.isAuditEnabled.editor.getValue();
-
- return {groupPermSet: groupPermSet , groupSet : groupSet,permSet : permSet,auditLoggin :auditLoggin,
- userSet : userSet,userPerm:userPerm,isUsers:isUsers};
- },
setupForm : function() {
- var resourcePath = _.map(this.model.get('resources'), function(obj,i){
- if( i == 0 ) this.model.set('isRecursive', obj.isRecursive)
- return obj.value;
- }, this);
- if(this.rangerService.get('type').toUpperCase() == XAEnums.ServiceType.Service_HDFS.label.toUpperCase()){
- this.model.set('path', resourcePath.toString());
- }else if(this.rangerService.get('type').toUpperCase() == XAEnums.ServiceType.Service_HIVE.label.toUpperCase()){
- _.each(resourcePath, function(path) {
- var temp = path.split("/");
- if(!_.isUndefined(temp[1])) this.model.set('database', temp[1])
- if(!_.isUndefined(temp[2])) this.model.set('table', temp[2])
- if(!_.isUndefined(temp[3])) this.model.set('column', temp[3])
-
- },this);
- }else if(this.rangerService.get('type').toUpperCase() == XAEnums.ServiceType.Service_HBASE.label.toUpperCase()){
- _.each(resourcePath, function(path) {
- var temp = path.split("/");
- if(!_.isUndefined(temp[1])) this.model.set('table', temp[1])
- if(!_.isUndefined(temp[2])) this.model.set('column-family', temp[2])
- if(!_.isUndefined(temp[3])) this.model.set('column', temp[3])
-
- },this);
- }else if(this.rangerService.get('type').toUpperCase() == XAEnums.ServiceType.Service_KNOX.label.toUpperCase()){
- _.each(resourcePath, function(path) {
- var temp = path.split("/");
- if(!_.isUndefined(temp[1])) this.model.set('topology', temp[1])
- if(!_.isUndefined(temp[2])) this.model.set('service', temp[2])
-
- },this);
- }else if(this.rangerService.get('type').toUpperCase() == XAEnums.ServiceType.Service_STORM.label.toUpperCase()){
- var resourcePath = _.map(this.model.get('resources'), function(obj,i){
- if( i == 0 ) this.model.set('isRecursive', obj.isRecursive)
- return obj.value;
- }, this);
- _.each(resourcePath, function(path) {
- var temp = path.split("/");
- if(!_.isUndefined(temp[1])) this.model.set('topology', temp[1])
- },this);
- }
+ _.each(this.model.attributes.resources,function(obj,key){
+ this.model.set(key, obj.values.toString())
+ },this)
},
setUpSwitches :function(){
var that = this;
@@ -280,11 +173,6 @@ define(function(require){
renderCustomFields: function(){
var that = this;
var accessType = this.rangerServiceDefModel.get('accessTypes').filter(function(val) { return val !== null; });
- var policyType = this.rangerService.get('type')
- _.each(XAEnums.ServiceType, function(obj){
- if(that.rangerService.get('type').toUpperCase() == obj.label.toUpperCase())
- policyType = obj.value;
- });
this.groupList = new VXGroupList();
var params = {sortBy : 'name'};
this.groupList.setPageSize(100,{fetch:false});
@@ -296,7 +184,7 @@ define(function(require){
collection : that.formInputList,
groupList : that.groupList,
model : that.model,
- policyType : policyType,
+// policyType : policyType,
accessTypes : accessType,
rangerServiceDefModel : that.rangerServiceDefModel
}).render().el);
@@ -313,7 +201,7 @@ define(function(require){
collection : that.userPermInputList,
model : that.model,
userList : that.userList,
- policyType : policyType,
+// policyType : policyType,
accessTypes : accessType,
rangerServiceDefModel : that.rangerServiceDefModel
}).render().el);
@@ -321,43 +209,19 @@ define(function(require){
},
beforeSave : function(){
- var that = this, resources = '';
+ var that = this, resources = [];
this.model.set('service',this.rangerService.get('name'));
- if(that.rangerService.get('type').toUpperCase() == XAEnums.ServiceType.Service_HDFS.label.toUpperCase())
- resources = this.model.get('path').split(',');
- else if(that.rangerService.get('type').toUpperCase() == XAEnums.ServiceType.Service_HIVE.label.toUpperCase()){
- resources = "/"+this.model.get('database');
- resources += !_.isEmpty(this.model.get('table')) ? "/"+this.model.get('table') : '';
- resources += !_.isEmpty(this.model.get('column')) ? "/"+this.model.get('column') : '';
- resources = resources.split(',');
- }else if(that.rangerService.get('type').toUpperCase() == XAEnums.ServiceType.Service_HBASE.label.toUpperCase()){
- resources = "/"+this.model.get('table');
- resources += !_.isEmpty(this.model.get('column-family')) ? "/"+this.model.get('column-family') : '';
- resources += !_.isEmpty(this.model.get('column')) ? "/"+this.model.get('column') : '';
- resources = resources.split(',');
- }else if(that.rangerService.get('type').toUpperCase() == XAEnums.ServiceType.Service_KNOX.label.toUpperCase()){
- resources = "/"+this.model.get('topology')+"/"+this.model.get('service');
- resources = resources.split(',');
- }else if(that.rangerService.get('type').toUpperCase() == XAEnums.ServiceType.Service_STORM.label.toUpperCase()){
- resources = "/"+this.model.get('topology')
- resources = resources.split(',');
- }
- var rPolicyResourceList = new RangerPolicyResourceList();
- _.each(resources, function(val){
- var rPolicyResource = new RangerPolicyResource();
- rPolicyResource.set('type',that.rangerService.get('type'));
- rPolicyResource.set('value',val);
- rPolicyResource.set('isRecursive',that.model.get('isRecursive'))
- rPolicyResource.set('isExcludes',null)
- rPolicyResourceList.add(rPolicyResource);
+ var resources = {};
+ _.each(this.rangerServiceDefModel.get('resources'),function(obj){
+ if(!_.isNull(obj)){
+ var rPolicyResource = new RangerPolicyResource();
+ rPolicyResource.set('values',that.model.get(obj.name).split(','));
+ rPolicyResource.set('isRecursive',that.model.get('isRecursive'))
+ resources[obj.name] = rPolicyResource;
+ that.model.unset(obj.name);
+ }
});
-
-
-
-
-// this.model.set('isEnabled',this.model.get('isEnabled')+"");
-// this.model.set('isAuditEnabled',this.model.get('isAuditEnabled')+"");
- this.model.set('resources',rPolicyResourceList);
+ this.model.set('resources',resources);
this.model.unset('isRecursive');
this.model.unset('path');
@@ -393,6 +257,11 @@ define(function(require){
}, this);
this.model.set('policyItems', policyItemList)
+ //Unset attrs which are not needed
+ _.each(this.model.attributes.resources,function(obj,key){
+ this.model.unset(key, obj.values.toString())
+ },this)
+
},
/** all post render plugin initialization */
initializePathPlugins: function(){
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/1f458f00/security-admin/src/main/webapp/scripts/views/policies/RangerPolicyTableLayout.js
----------------------------------------------------------------------
diff --git a/security-admin/src/main/webapp/scripts/views/policies/RangerPolicyTableLayout.js b/security-admin/src/main/webapp/scripts/views/policies/RangerPolicyTableLayout.js
index b0f3809..2f4ab67 100644
--- a/security-admin/src/main/webapp/scripts/views/policies/RangerPolicyTableLayout.js
+++ b/security-admin/src/main/webapp/scripts/views/policies/RangerPolicyTableLayout.js
@@ -32,6 +32,7 @@ define(function(require){
var XATableLayout = require('views/common/XATableLayout');
var localization = require('utils/XALangSupport');
var vFolderInfo = require('views/folders/FolderInfo');
+ var RangerServiceDef = require('models/RangerServiceDef');
var RangerPolicyTableLayoutTmpl = require('hbs!tmpl/policies/RangerPolicyTableLayout_tmpl');
require('backgrid-filter');
@@ -99,6 +100,7 @@ define(function(require){
assetId : this.assetModel.id
};*/
this.bindEvents();
+ this.initializeServiceDef();
// this.isSysAdmin = SessionMgr.isSystemAdmin();
},
@@ -110,7 +112,14 @@ define(function(require){
//this.listenTo(this.collection, "sync", this.render, this);
//
},
-
+ initializeServiceDef : function(){
+ this.rangerServiceDefModel = new RangerServiceDef();
+ this.rangerServiceDefModel.url = "service/plugins/definitions/name/"+this.rangerService.get('type');
+ this.rangerServiceDefModel.fetch({
+ cache : false,
+ async : false
+ })
+ },
/** on render callback */
onRender: function() {
// this.initializePlugins();
@@ -148,17 +157,40 @@ define(function(require){
editable: false,
sortable : false
},
- resources : {
+ /* database : {
+ cell : "html",
+ label : localization.tt("lbl.database"),
+ editable: false,
+ sortable : false,
+ formatter: _.extend({}, Backgrid.CellFormatter.prototype, {
+ fromRaw: function (rawValue,model) {
+ rawValue = model.get('resources')
+ var name=''
+ _.each(rawValue, function(obj){
+ if(!_.isUndefined(obj.values))
+ name += obj.values.toString();
+ });
+ return name;
+ }
+ })
+ },*/
+ /* resources : {
cell : "html",
label : localization.tt("lbl.resourcePath"),
editable: false,
sortable : false,
formatter: _.extend({}, Backgrid.CellFormatter.prototype, {
fromRaw: function (rawValue) {
- return _.map(rawValue, function(resource){ return resource.value;}).toString();
+ console.log(rawValue)
+ var name=''
+ _.each(rawValue, function(obj){
+ if(!_.isUndefined(obj.values))
+ name += obj.values.toString();
+ });
+ return name;
}
})
- },
+ },*/
isEnabled:{
label:localization.tt('lbl.status'),
cell :"html",
@@ -292,6 +324,22 @@ define(function(require){
}
*/
};
+ _.each(this.rangerServiceDefModel.get('resources'), function(obj){
+ if(!_.isUndefined(obj) && !_.isNull(obj))
+ cols[obj.name]={
+ cell : "html",
+ label : localization.tt("lbl."+obj.name),
+ editable: false,
+ sortable : false,
+ formatter: _.extend({}, Backgrid.CellFormatter.prototype, {
+ fromRaw: function (rawValue,model) {
+ rawValue = model.get('resources')
+ return rawValue[obj.name].values.toString();
+ }
+ })
+ };
+
+ });
return this.collection.constructor.getTableCols(cols, this.collection);
},
onDelete :function(e){
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/1f458f00/security-admin/src/main/webapp/scripts/views/policies/UserPermList.js
----------------------------------------------------------------------
diff --git a/security-admin/src/main/webapp/scripts/views/policies/UserPermList.js b/security-admin/src/main/webapp/scripts/views/policies/UserPermList.js
index f7879ad..fe51116 100644
--- a/security-admin/src/main/webapp/scripts/views/policies/UserPermList.js
+++ b/security-admin/src/main/webapp/scripts/views/policies/UserPermList.js
@@ -33,12 +33,12 @@ define(function(require) {
var UserPermissionItem = Backbone.Marionette.ItemView.extend({
_msvName : 'UserPermissionItem',
- template : require('hbs!tmpl/common/UserPermissionItem'),
+ template : require('hbs!tmpl/policies/UserPermItem'),
tagName : 'tr',
templateHelpers : function(){
return {
- permissions : this.getPerms(),
+ permissions : this.accessTypes,
policyKnox : this.policyType == XAEnums.ServiceType.Service_KNOX.value ? true :false,
// policyStorm : this.policyType == XAEnums.ServiceType.Service_STORM.value ? true :false,
isModelNew : !this.model.has('editMode'),
@@ -74,6 +74,11 @@ define(function(require) {
onRender : function() {
var that = this;
+ this.accessItems = _.map(this.accessTypes, function(perm){
+ if(!_.isUndefined(perm))
+ return {'type':perm.label,isAllowed : false}
+ });
+
if(this.model.get('userName') != undefined){
this.ui.selectUsers.val(this.model.get('userName').split(','));
}
@@ -83,8 +88,10 @@ define(function(require) {
if(this.model.has('editMode') && this.model.get('editMode')){
_.each(this.model.get('accesses'), function(p){
- if(p.value)
+ if(p.isAllowed){
this.$el.find('input[data-name="' + p.type + '"]').attr('checked', 'checked');
+ _.each(this.accessItems,function(obj){ if(obj.type == p.type) obj.isAllowed=true;})
+ }
},this);
}
if(this.policyType == XAEnums.AssetType.ASSET_STORM.value)
@@ -93,7 +100,6 @@ define(function(require) {
this.createSelectUserDropDown();
this.userDropDownChange();
- this.accessItems = _.map(this.getPerms(), function(perm){ if(!_.isUndefined(perm)) return {'type':perm.label,'value': false}});
},
checkDirtyFieldForDropDown : function(e){
//that.model.has('groupId')
@@ -131,9 +137,9 @@ define(function(require) {
var $checkbox = $el.find('input');
$checkbox.is(':checked') ? $checkbox.prop('checked',false) : $checkbox.prop('checked',true);
}
- var curPerm = $el.find('input').data('id');
+// var curPerm = $el.find('input').data('id');
var curPermName = $el.find('input').data('name');
- if(!_.isUndefined(curPerm)){
+ if(!_.isUndefined(curPermName)){
var perms = [];
if(this.model.has('accesses')){
if(_.isArray(this.model.get('accesses')))
@@ -144,16 +150,16 @@ define(function(require) {
if($el.find('input[type="checkbox"]').is(':checked')){
- _.each(that.accessItems, function(obj){ if(obj.type == curPermName) obj.value = true });
- if(curPerm == XAEnums.XAPermType.XA_PERM_TYPE_ADMIN.value){
- $el.parent().find('input[type="checkbox"]:not(:checked)[data-id!="'+curPerm+'"]').map(function(){
- _.each(that.accessItems, function(obj){ if(obj.type == $(this).data('name')) obj.value = true }, this);
+ _.each(that.accessItems, function(obj){ if(obj.type == curPermName) obj.isAllowed = true });
+ /*if(curPermName == XAEnums.XAPermType.XA_PERM_TYPE_ADMIN.label){
+ $el.parent().find('input[type="checkbox"]:not(:checked)[data-name!="'+curPermName+'"]').map(function(){
+ _.each(that.accessItems, function(obj){ if(obj.type == $(this).data('name')) obj.isAllowed = true }, this);
});
// this.model.set('_vPermList', perms);
$el.parent().find('input[type="checkbox"]').prop('checked',true);
- }
+ }*/
} else {
- _.each(that.accessItems, function(obj){ if(obj.type == curPermName ) obj.value = false }, this);
+ _.each(that.accessItems, function(obj){ if(obj.type == curPermName ) obj.isAllowed = false }, this);
}
// this.checkDirtyFieldForCheckBox(perms);
if(!_.isEmpty(that.accessItems)){
@@ -345,10 +351,6 @@ define(function(require) {
});
});
},
- getPerms : function(){
- var permList = _.map(this.accessTypes,function(type){ return type.label});
- return _.map(permList, function(perm){ return _.findWhere(XAEnums.XAPermType,{label:perm})})
- }
});
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/1f458f00/security-admin/src/main/webapp/scripts/views/service/ServiceCreate.js
----------------------------------------------------------------------
diff --git a/security-admin/src/main/webapp/scripts/views/service/ServiceCreate.js b/security-admin/src/main/webapp/scripts/views/service/ServiceCreate.js
index e86d6ab..6b7f3ea 100644
--- a/security-admin/src/main/webapp/scripts/views/service/ServiceCreate.js
+++ b/security-admin/src/main/webapp/scripts/views/service/ServiceCreate.js
@@ -89,7 +89,7 @@ define(function(require){
this.setupModel();
}*/
if(!this.model.isNew()){
- _.each(JSON.parse(this.model.attributes.configs),function(name, value){
+ _.each(this.model.attributes.configs,function(name, value){
this.model.set(value,name)
},this);
}
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/1f458f00/security-admin/src/main/webapp/scripts/views/service/ServiceForm.js
----------------------------------------------------------------------
diff --git a/security-admin/src/main/webapp/scripts/views/service/ServiceForm.js b/security-admin/src/main/webapp/scripts/views/service/ServiceForm.js
index 6027b1e..24b174c 100644
--- a/security-admin/src/main/webapp/scripts/views/service/ServiceForm.js
+++ b/security-admin/src/main/webapp/scripts/views/service/ServiceForm.js
@@ -25,6 +25,7 @@ define(function(require){
var XAEnums = require('utils/XAEnums');
var localization = require('utils/XALangSupport');
+ var BackboneFormDataType = require('models/BackboneFormDataType');
require('backbone-forms');
require('backbone-forms.list');
@@ -78,36 +79,8 @@ define(function(require){
var attrs = _.pick(_.result(this.rangerServiceDefModel,'schemaBase'), 'name', 'description', 'isEnabled', 'type');
var that = this;
- _.each(this.rangerServiceDefModel.get('configs'),function(v,k){
- if (v != null) {
-
- var formObj = {};
- var enumObj = _.find(that.rangerServiceDefModel.get('enums'), function(e){ return e && e.name == v.type;});
- if (enumObj !== undefined ){
- formObj.type = 'Select';
- formObj.options = _.pluck(_.compact(enumObj.elements),'label');
- } else {
- switch(v.type){
- case 'string' : formObj.type = 'Text'; break;
- case 'bool' : formObj.type = 'Checkbox'; formObj.options = { y: 'Yes', n: 'No' }; break;
- case 'int' : formObj.type = 'Number'; break;
- default : formObj.type = 'Text'; break;
- }
-
-
- }
- formObj.title = v.label || v.name;
- formObj.validators = [];
- if (_.has(v,'mandatory') && v.mandatory){
- formObj.validators.push('required');
- formObj.title = formObj.title +" *"
- }
- formObj['class'] = 'serviceConfig';
- var name = v.name;
- attrs[name] = formObj;
- }
- });
- return attrs;
+ var formDataType = new BackboneFormDataType();
+ return formDataType.getFormElements(this.rangerServiceDefModel.get('configs'),this.rangerServiceDefModel.get('enums'), attrs, this);
},
/** on render callback */
@@ -156,9 +129,9 @@ define(function(require){
that.model.unset(obj.name);
}
});
- //this.model.set('configs',JSON.stringify(config));
+// this.model.set('configs',JSON.stringify(config));
this.model.set('configs',config);
-
+
//Set service type
this.model.set('type',this.rangerServiceDefModel.get('name'))
/*_.each(XAEnums.AssetType, function(asset){
@@ -174,7 +147,7 @@ define(function(require){
//Remove unwanted attributes from model
if(!this.model.isNew()){
- _.each(JSON.parse(this.model.attributes.configs),function(value, name){
+ _.each(this.model.attributes.configs, function(value, name){
this.model.unset(name)
},this);
}
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/1f458f00/security-admin/src/main/webapp/templates/policies/GroupPermItem.html
----------------------------------------------------------------------
diff --git a/security-admin/src/main/webapp/templates/policies/GroupPermItem.html b/security-admin/src/main/webapp/templates/policies/GroupPermItem.html
index 08155e1..a53f7b6 100644
--- a/security-admin/src/main/webapp/templates/policies/GroupPermItem.html
+++ b/security-admin/src/main/webapp/templates/policies/GroupPermItem.html
@@ -40,7 +40,7 @@
{{/if}}
{{#each permissions}}
<td style="cursor:pointer;">
- <input data-id="{{./this.value}}" data-name="{{./this.label}}" type="checkbox">
+ <input data-name="{{./this.label}}" type="checkbox">
</td>
{{/each}}
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/1f458f00/security-admin/src/main/webapp/templates/policies/UserPermItem.html
----------------------------------------------------------------------
diff --git a/security-admin/src/main/webapp/templates/policies/UserPermItem.html b/security-admin/src/main/webapp/templates/policies/UserPermItem.html
index 481ee61..b7bbad4 100644
--- a/security-admin/src/main/webapp/templates/policies/UserPermItem.html
+++ b/security-admin/src/main/webapp/templates/policies/UserPermItem.html
@@ -39,7 +39,7 @@
{{/if}}
{{#each permissions}}
<td style="cursor:pointer;">
- <input data-id="{{./this.value}}" type="checkbox">
+ <input data-name="{{./this.label}}" type="checkbox">
</td>
{{/each}}