Repository: ranger Updated Branches: refs/heads/master 3e1168ddb -> 4ef52b46b
RANGER-1929 The ranger should support the View policy. Signed-off-by: zhangqiang2 <zhangqia...@zte.com.cn> Project: http://git-wip-us.apache.org/repos/asf/ranger/repo Commit: http://git-wip-us.apache.org/repos/asf/ranger/commit/4ef52b46 Tree: http://git-wip-us.apache.org/repos/asf/ranger/tree/4ef52b46 Diff: http://git-wip-us.apache.org/repos/asf/ranger/diff/4ef52b46 Branch: refs/heads/master Commit: 4ef52b46b1e6dd7bc1991a05b8256984d30a6c58 Parents: 3e1168d Author: peng.jianhua <peng.jian...@zte.com.cn> Authored: Thu Dec 21 09:31:57 2017 +0800 Committer: zhangqiang2 <zhangqia...@zte.com.cn> Committed: Wed Dec 20 20:45:24 2017 -0500 ---------------------------------------------------------------------- .../scripts/modules/globalize/message/en.js | 19 +++ .../views/policies/RangerPolicyConditions.js | 54 ++++++ .../views/policies/RangerPolicyDetail.js | 166 +++++++++++++++++++ .../views/policies/RangerPolicyTableLayout.js | 30 +++- security-admin/src/main/webapp/styles/xa.css | 10 ++ .../policies/RangerPolicyConditions_tmpl.html | 79 +++++++++ .../policies/RangerPolicyDetail_tmpl.html | 79 +++++++++ 7 files changed, 436 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ranger/blob/4ef52b46/security-admin/src/main/webapp/scripts/modules/globalize/message/en.js ---------------------------------------------------------------------- diff --git a/security-admin/src/main/webapp/scripts/modules/globalize/message/en.js b/security-admin/src/main/webapp/scripts/modules/globalize/message/en.js index b8de5c3..2cd3345 100644 --- a/security-admin/src/main/webapp/scripts/modules/globalize/message/en.js +++ b/security-admin/src/main/webapp/scripts/modules/globalize/message/en.js @@ -330,6 +330,25 @@ define(function(require) { pluginStatus :'Plugin Status', clusterName :'Name of ambari cluster', url :'Hive url.', + enabled :'enabled', + disabled :'disabled', + Url :'Url', + recursive :'recursive', + nonRecursive :'non-recursive', + dataBase :'DataBase', + exclude :'exclude', + include :'include', + yes :'Yes', + no :'No', + conditions :'Conditions', + exAllowCondition :'Exclude from Allow Conditions', + denyCondition :'Deny Conditions', + exDenyCondition :'Exclude from Deny Conditions', + maskingOption :'Masking Option', + masking :'Masking', + custom :'CUSTOM', + mask :'Mask', + rowFilter :'Row Filter' }, msg : { deletePolicyValidationMsg : 'Policy does not have any settings for the specific resource. Policy will be deleted. Press [Ok] to continue. Press [Cancel] to edit the policy.', http://git-wip-us.apache.org/repos/asf/ranger/blob/4ef52b46/security-admin/src/main/webapp/scripts/views/policies/RangerPolicyConditions.js ---------------------------------------------------------------------- diff --git a/security-admin/src/main/webapp/scripts/views/policies/RangerPolicyConditions.js b/security-admin/src/main/webapp/scripts/views/policies/RangerPolicyConditions.js new file mode 100644 index 0000000..96d9c8b --- /dev/null +++ b/security-admin/src/main/webapp/scripts/views/policies/RangerPolicyConditions.js @@ -0,0 +1,54 @@ +/* + * 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. + */ + +/* + * Policy Conditions view + */ + +define(function(require) { + 'use strict'; + + var Backbone = require('backbone'); + var XAUtil = require('utils/XAUtils'); + var localization = require('utils/XALangSupport'); + + var RangerPolicyConditionsTmpl = require('hbs!tmpl/policies/RangerPolicyConditions_tmpl'); + + var RangerPolicyConditions = Backbone.Marionette.Layout.extend({ + _viewName: 'RangerPolicyConditions', + + template: RangerPolicyConditionsTmpl, + + templateHelpers: function() { + return { + policyItems: this.policyItems, + isMaskingPolicy: XAUtil.isMaskingPolicy(this.policyId), + isAccessPolicy: XAUtil.isAccessPolicy(this.policyId), + isRowFilterPolicy: XAUtil.isRowFilterPolicy(this.policyId) + }; + }, + + initialize: function(options) { + console.log("initialized a RangerPolicyConditions Layout"); + _.extend(this, _.pick(options, 'policyItems', 'policyId')); + } + + }); + return RangerPolicyConditions; +}); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ranger/blob/4ef52b46/security-admin/src/main/webapp/scripts/views/policies/RangerPolicyDetail.js ---------------------------------------------------------------------- diff --git a/security-admin/src/main/webapp/scripts/views/policies/RangerPolicyDetail.js b/security-admin/src/main/webapp/scripts/views/policies/RangerPolicyDetail.js new file mode 100644 index 0000000..5bf2296 --- /dev/null +++ b/security-admin/src/main/webapp/scripts/views/policies/RangerPolicyDetail.js @@ -0,0 +1,166 @@ +/* + * 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. + */ + +/* + * Policy Detail view + */ + +define(function(require) { + 'use strict'; + + var Backbone = require('backbone'); + var XAUtil = require('utils/XAUtils'); + var localization = require('utils/XALangSupport'); + var RangerServiceDef = require('models/RangerServiceDef'); + var RangerPolicyDetailTmpl = require('hbs!tmpl/policies/RangerPolicyDetail_tmpl'); + var RangerPolicyConditions = require('views/policies/RangerPolicyConditions'); + + var RangerPolicyDetail = Backbone.Marionette.Layout.extend({ + _viewName: 'RangerPolicyDetail', + + template: RangerPolicyDetailTmpl, + + regions: { + 'allowCondition': 'div[data-id="allowCondition"]', + 'exAllowCondition': 'div[data-id="exAllowCondition"]', + 'denyCondition': 'div[data-id="denyCondition"]', + 'exDenyCondition': 'div[data-id="exDenyCondition"]' + }, + + templateHelpers: function() { + var policyId = this.model.get("policyType"); + var policyType = localization.tt('h.access'); + var conditionType = localization.tt('lbl.allow'); + if(XAUtil.isMaskingPolicy(policyId)) { + policyType = localization.tt('h.masking'); + conditionType = localization.tt('h.mask'); + } else if(XAUtil.isRowFilterPolicy(policyId)) { + policyType = localization.tt('lbl.rowLevelFilter'); + conditionType = localization.tt('h.rowFilter'); + } + return { + policyType: policyType, + resources: this.initResource(), + conditionType: conditionType, + isMaskingPolicy: XAUtil.isMaskingPolicy(policyId), + isAccessPolicy: XAUtil.isAccessPolicy(policyId), + isRowFilterPolicy: XAUtil.isRowFilterPolicy(policyId) + }; + }, + + initialize: function(options) { + console.log("initialized a RangerPolicyDetail Layout"); + _.extend(this, _.pick(options, 'rangerService')); + this.initializeServiceDef(); + }, + + initializeServiceDef: function() { + this.rangerServiceDefModel = new RangerServiceDef(); + this.rangerServiceDefModel.url = XAUtil.getRangerServiceDef(this.rangerService.get('type')); + this.rangerServiceDefModel.fetch({ + cache: false, + async: false + }); + }, + + initResource: function() { + var resources = []; + var resourceObj = this.model.get("resources"); + var configs = this.rangerServiceDefModel.get("resources") + if(XAUtil.isMaskingPolicy(this.model.get('policyType'))) { + if(XAUtil.isRenderMasking(this.rangerServiceDefModel.get('dataMaskDef'))) { + configs = this.rangerServiceDefModel.get('dataMaskDef').resources; + } + } else if(XAUtil.isRowFilterPolicy(this.model.get('policyType'))) { + if(XAUtil.isRenderRowFilter(this.rangerServiceDefModel.get('rowFilterDef'))) { + configs = this.rangerServiceDefModel.get('rowFilterDef').resources; + } + } + _.each(configs, function(obj, index) { + var value = resourceObj[obj.name]; + if(_.isUndefined(value)){ + return; + } + var resource = {}; + resource.label = obj.label; + resource.values = value.values; + resource.isSupport = false; + if(obj.excludesSupported){ + resource.isSupport = true; + if(value.isExcludes){ + resource.exBool = false; + resource.exLabel = localization.tt('h.exclude') + }else{ + resource.exBool = true; + resource.exLabel = localization.tt('h.include') + } + }else if(obj.recursiveSupported){ + resource.isSupport = true; + if(value.isRecursive){ + resource.exBool = true; + resource.exLabel = localization.tt('h.recursive') + }else{ + resource.exBool = fasle; + resource.exLabel = localization.tt('h.nonRecursive') + } + } + resources.push(resource); + }); + return resources; + }, + + onRender: function() { + this.initializeConditions(); + }, + + initializeConditions: function() { + var policyId = this.model.get("policyType"); + if(XAUtil.isAccessPolicy(policyId)) { + this.allowCondition.show(new RangerPolicyConditions({ + policyItems: this.model.get("policyItems"), + policyId: policyId + })); + this.exAllowCondition.show(new RangerPolicyConditions({ + policyItems: this.model.get("allowExceptions"), + policyId: policyId + })); + this.denyCondition.show(new RangerPolicyConditions({ + policyItems: this.model.get("denyPolicyItems"), + policyId: policyId + })); + this.exDenyCondition.show(new RangerPolicyConditions({ + policyItems: this.model.get("denyExceptions"), + policyId: policyId + })); + } else if(XAUtil.isMaskingPolicy(policyId)) { + this.allowCondition.show(new RangerPolicyConditions({ + policyItems: this.model.get("dataMaskPolicyItems"), + policyId: policyId + })); + } else if(XAUtil.isRowFilterPolicy(policyId)) { + this.allowCondition.show(new RangerPolicyConditions({ + policyItems: this.model.get("rowFilterPolicyItems"), + policyId: policyId + })); + } + } + + }); + return RangerPolicyDetail; +}); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ranger/blob/4ef52b46/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 09e2e16..ce295ff 100644 --- a/security-admin/src/main/webapp/scripts/views/policies/RangerPolicyTableLayout.js +++ b/security-admin/src/main/webapp/scripts/views/policies/RangerPolicyTableLayout.js @@ -36,6 +36,7 @@ define(function(require){ var RangerServiceDef = require('models/RangerServiceDef'); var RangerPolicy = require('models/RangerPolicy'); var RangerPolicyTableLayoutTmpl = require('hbs!tmpl/policies/RangerPolicyTableLayout_tmpl'); + var RangerPolicyDetail = require('views/policies/RangerPolicyDetail'); require('backgrid-filter'); require('backgrid-paginator'); @@ -79,6 +80,7 @@ define(function(require){ 'policyTypeTab' : 'div[data-id="policyTypeTab"]', 'addNewPolicy' : '[data-js="addNewPolicy"]', 'iconSearchInfo' : '[data-id="searchInfo"]', + 'btnViewPolicy' : '[data-name ="viewPolicy"]', }, /** ui events hash */ @@ -88,6 +90,7 @@ define(function(require){ events['click ' + this.ui.btnShowMore] = 'onShowMore'; events['click ' + this.ui.btnShowLess] = 'onShowLess'; events['click ' + this.ui.policyTypeTab + ' ul li a'] = 'onTabChange'; + events['click ' + this.ui.btnViewPolicy] = 'onView'; return events; }, @@ -172,6 +175,30 @@ define(function(require){ })); }, + onView : function(e){ + var that = this; + var policyId = $(e.currentTarget).data('id'); + var rangerPolicy = new RangerPolicy({ id : policyId}); + rangerPolicy.fetch({ + cache : false, + }).done(function(){ + var view = new RangerPolicyDetail({ + model : rangerPolicy, + rangerService: that.rangerService + }); + var modal = new Backbone.BootstrapModal({ + animate : true, + content : view, + title : localization.tt("h.policyDetails"), + okText : localization.tt("lbl.ok"), + allowCancel : true, + escape : true + }).open(); + modal.$el.addClass('modal-diff').attr('tabindex',-1); + modal.$el.find('.cancel').hide(); + }); + }, + getColumns : function(){ var that = this; var cols = { @@ -251,7 +278,8 @@ define(function(require){ label : localization.tt("lbl.action"), formatter: _.extend({}, Backgrid.CellFormatter.prototype, { fromRaw: function (rawValue,model) { - return '<a href="#!/service/'+that.rangerService.id+'/policies/'+model.id+'/edit" class="btn btn-mini" title="Edit"><i class="icon-edit icon-large" /></a>\ + return '<a href="javascript:void(0);" data-name ="viewPolicy" data-id="'+model.id+'" class="btn btn-mini" title="View"><i class="icon-eye-open icon-large" /></a>\ + <a href="#!/service/'+that.rangerService.id+'/policies/'+model.id+'/edit" class="btn btn-mini" title="Edit"><i class="icon-edit icon-large" /></a>\ <a href="javascript:void(0);" data-name ="deletePolicy" data-id="'+model.id+'" class="btn btn-mini btn-danger" title="Delete"><i class="icon-trash icon-large" /></a>'; //You can use rawValue to custom your html, you can change this value using the name parameter. } http://git-wip-us.apache.org/repos/asf/ranger/blob/4ef52b46/security-admin/src/main/webapp/styles/xa.css ---------------------------------------------------------------------- diff --git a/security-admin/src/main/webapp/styles/xa.css b/security-admin/src/main/webapp/styles/xa.css index 4fb0d6e..ee13655 100644 --- a/security-admin/src/main/webapp/styles/xa.css +++ b/security-admin/src/main/webapp/styles/xa.css @@ -1576,6 +1576,7 @@ background-color: #dc6343; } .modal-diff .modal-header { background-color: #eff3f8; + border-radius: 6px 6px 0px 0px; } .no-margin { margin: 0; @@ -2229,3 +2230,12 @@ td.subgrid-custom-cell{ .control-group.error .select2-choices{ border-color: #b85355; } +textarea:read-only{ + cursor: default; +} +#policyDetail>label{ + margin-bottom: 6px; +} +.label-margin{ + margin-left: 10px; +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ranger/blob/4ef52b46/security-admin/src/main/webapp/templates/policies/RangerPolicyConditions_tmpl.html ---------------------------------------------------------------------- diff --git a/security-admin/src/main/webapp/templates/policies/RangerPolicyConditions_tmpl.html b/security-admin/src/main/webapp/templates/policies/RangerPolicyConditions_tmpl.html new file mode 100644 index 0000000..6a46bbd --- /dev/null +++ b/security-admin/src/main/webapp/templates/policies/RangerPolicyConditions_tmpl.html @@ -0,0 +1,79 @@ +{{!-- + 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. +--}} +<div> + <table class="table table-bordered backgrid"> + <thead> + <tr> + <th width="20%">{{tt 'lbl.groups'}}</th> + <th width="35%">{{tt 'lbl.users'}}</th> + {{#if isAccessPolicy}} + <th width="35%">{{tt 'lbl.permissions'}}</th> + <th width="10%">{{tt 'lbl.delegatedAdmin'}}</th> + {{/if}} + {{#if isMaskingPolicy}} + <th width="25%">{{tt 'lbl.accessTypes'}}</th> + <th width="20%">{{tt 'h.maskingOption'}}</th> + {{/if}} + {{#if isRowFilterPolicy}} + <th width="25%">{{tt 'lbl.accessTypes'}}</th> + <th width="20%">{{tt 'lbl.rowLevelFilter'}}</th> + {{/if}} + </tr> + </thead> + <tbody> + {{#each policyItems}} + <tr> + <td> + {{#each ./this.groups}} + <span class="label label-info float-left-margin-2">{{./this}}</span> {{/each}} + </td> + <td> + {{#each ./this.users}} + <span class="label label-info float-left-margin-2">{{./this}}</span> {{/each}} + </td> + <td> + {{#each ./this.accesses}} + <span class="label label-info float-left-margin-2">{{./this.type}}</span> {{/each}} + </td> + {{#if ../isAccessPolicy}} + <td style="text-align: center;vertical-align: middle;"> + <div> + {{#if ./this.delegateAdmin}} + <label class="label label-ranger">{{tt 'h.yes'}}</label> {{else}} + <label class="label label-important">{{tt 'h.no'}}</label> {{/if}} + </div> + </td> + {{/if}} + {{#if ../isMaskingPolicy}} + <td> + {{#compare dataMaskInfo.dataMaskType 'eq' 'CUSTOM'}} + <span class="label label-info float-left-margin-2">{{tt 'h.custom'}}: {{dataMaskInfo.valueExpr}}</span> + {{else}} + <span class="label label-info float-left-margin-2">{{dataMaskInfo.dataMaskType}}</span> + {{/compare}} + </td> + {{/if}} + {{#if ../isRowFilterPolicy}} + <td> + <span class="label label-info float-left-margin-2">{{rowFilterInfo.filterExpr}}</span> + </td> + {{/if}} + </tr> + {{/each}} + </tbody> + </table> +</div> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ranger/blob/4ef52b46/security-admin/src/main/webapp/templates/policies/RangerPolicyDetail_tmpl.html ---------------------------------------------------------------------- diff --git a/security-admin/src/main/webapp/templates/policies/RangerPolicyDetail_tmpl.html b/security-admin/src/main/webapp/templates/policies/RangerPolicyDetail_tmpl.html new file mode 100644 index 0000000..f8d1791 --- /dev/null +++ b/security-admin/src/main/webapp/templates/policies/RangerPolicyDetail_tmpl.html @@ -0,0 +1,79 @@ +{{!-- + 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. +--}} + +<div id="policyDetail"> + <label class="no-margin label-size13-weightbold">{{tt 'lbl.policyType'}} : <label class="label label-ranger"> {{policyType}} </label></label> + <label class="no-margin label-size13-weightbold">{{tt 'lbl.policyId'}} : <label class="label label-ranger"> {{id}} </label></label> + <label class="no-margin label-size13-weightbold">{{tt 'lbl.policyName'}} : {{name}} + {{#if isEnabled}} + <label class="label label-ranger label-margin">{{tt 'h.enabled'}}</label> + {{else}} + <label class="label label-important label-margin">{{tt 'h.disabled'}}</label> + {{/if}} + </label> + {{#each resources}} + <label class="no-margin label-size13-weightbold">{{./this.label}} : {{./this.values}} + {{#if ./this.isSupport}} + {{#if ./this.exBool}} + <label class="label label-ranger label-margin">{{./this.exLabel}}</label> + {{else}} + <label class="label label-important label-margin">{{./this.exLabel}}</label> + {{/if}} + {{/if}} + </label> + {{/each}} + <label class="no-margin label-size13-weightbold">{{tt 'lbl.auditLogging'}} : + {{#if isAuditEnabled}} + <label class="label label-ranger">{{tt 'h.yes'}}</label> + {{else}} + <label class="label label-important">{{tt 'h.no'}}</label> + {{/if}} + </label> + <label class="no-margin label-size13-weightbold" style="vertical-align:top;float:left;">{{tt 'lbl.description'}} : </label><textarea style="width: 400px;height: 80px;" readonly="readonly">{{description}}</textarea> +</div> +<div> + <div> + <p class="wrap-header formHeader"> + {{conditionType}} {{tt 'h.conditions'}} : + </p> + <div data-id="allowCondition" style="margin-top: 15px;"> + </div> + </div> + {{#if isAccessPolicy}} + <div> + <p class="wrap-header reportSearchHeader"> + {{tt 'h.exAllowCondition'}} : + </p> + <div data-id="exAllowCondition"> + </div> + </div> + <div> + <p class="wrap-header formHeader"> + {{tt 'h.denyCondition'}} : + </p> + <div data-id="denyCondition" style="margin-top: 15px;"> + </div> + </div> + <div> + <p class="wrap-header reportSearchHeader"> + {{tt 'h.exDenyCondition'}} : + </p> + <div data-id="exDenyCondition"> + </div> + </div> + {{/if}} +</div> \ No newline at end of file