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/09/21 04:11:27 UTC

[1/5] incubator-ranger git commit: RANGER-632 : Added validation error msg on Ranger UI in service/policy create page and also added pause option in bootstrap-notify plugin.

Repository: incubator-ranger
Updated Branches:
  refs/heads/tag-policy 9da461d27 -> 3852419c3


RANGER-632 : Added validation error msg on Ranger UI in service/policy create page and also added pause option in bootstrap-notify plugin.

Signed-off-by: Velmurugan Periasamy <ve...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/incubator-ranger/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ranger/commit/a350aa89
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ranger/tree/a350aa89
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ranger/diff/a350aa89

Branch: refs/heads/tag-policy
Commit: a350aa893d78d64e927bed55ee523e63063ccc50
Parents: be6bc40
Author: Gautam Borad <gb...@gmail.com>
Authored: Wed Sep 16 13:53:50 2015 +0530
Committer: Velmurugan Periasamy <ve...@apache.org>
Committed: Fri Sep 18 00:51:47 2015 -0400

----------------------------------------------------------------------
 .../bootstrap-notify/js/bootstrap-notify.js     | 44 ++++++++++++++++----
 .../src/main/webapp/scripts/utils/XAUtils.js    | 26 +++++++++++-
 .../views/policies/RangerPolicyCreate.js        | 12 ++++--
 .../scripts/views/service/ServiceCreate.js      | 23 +++-------
 security-admin/src/main/webapp/styles/xa.css    |  5 +++
 5 files changed, 80 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/a350aa89/security-admin/src/main/webapp/libs/bower/bootstrap-notify/js/bootstrap-notify.js
----------------------------------------------------------------------
diff --git a/security-admin/src/main/webapp/libs/bower/bootstrap-notify/js/bootstrap-notify.js b/security-admin/src/main/webapp/libs/bower/bootstrap-notify/js/bootstrap-notify.js
index e58c6c5..ba309e2 100644
--- a/security-admin/src/main/webapp/libs/bower/bootstrap-notify/js/bootstrap-notify.js
+++ b/security-admin/src/main/webapp/libs/bower/bootstrap-notify/js/bootstrap-notify.js
@@ -47,13 +47,21 @@
           this.$note.text(this.options.message.text);
       } else
         this.$note.html(this.options.message);
-
+    
+    var style = this.options.type == 'error' ? 'color:#a94442' : 'color:#3c763d';  
+    
     if(this.options.closable) {
-      var link = $('<a class="close pull-right" href="#">&times;</a>');
+      var link = $('<a class="close pull-right" style="'+style+';" href="#">&times;</a>');
       $(link).on('click', $.proxy(onClose, this));
       this.$note.prepend(link);
     }
 
+    if(this.options.pausable) {
+    	var pauseLink = $('<a class="pause pull-right pause-play-close" style="'+style+';" href="#"><i class="icon-pause"></i></a><a class="play pull-right pause-play-close" href="#" style="'+style+';display:none;"><i class="icon-play"></i></a>');
+    	$(pauseLink).on('click', $.proxy(onPause, this));
+    	this.$note.prepend(pauseLink);
+    	
+    }
     return this;
   };
 
@@ -64,10 +72,31 @@
     return false;
   };
 
+  var onPause = function() {
+	  if(this.$note.find('.pause').is(':visible')){
+		  clearInterval(this.clearNotifyInterval)
+		  this.$note.find('.pause').hide()
+		  this.$note.find('.play').show()
+	  }else{
+		  setFadeOut(this)
+		  this.$note.find('.pause').show()
+		  this.$note.find('.play').hide()
+	  }
+	  return false;
+  };
+  var setFadeOut = function(self){
+	  var that = self;
+	  self.clearNotifyInterval = setTimeout(function() {
+		  that.$note.fadeOut('slow', $.proxy(that.onClose, that));    
+	  }, self.options.fadeOut.delay || 7000);
+  };
+	  
   Notification.prototype.show = function () {
-    if(this.options.fadeOut.enabled)
-      this.$note.delay(this.options.fadeOut.delay || 3000).fadeOut('slow', $.proxy(onClose, this));
-
+	var that = this;  
+    if(this.options.fadeOut.enabled){
+    	setFadeOut(this)
+    }
+//  this.$note.delay(this.options.fadeOut.delay || 3000).fadeOut('slow', $.proxy(onClose, this));
     this.$element.append(this.$note);
     this.$note.alert();
   };
@@ -88,10 +117,11 @@
     transition: 'fade',
     fadeOut: {
       enabled: true,
-      delay: 3000
+      delay: 7000
     },
     message: null,
     onClose: function () {},
-    onClosed: function () {}
+    onClosed: function () {},
+    pausable: false
   }
 })(window.jQuery);

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/a350aa89/security-admin/src/main/webapp/scripts/utils/XAUtils.js
----------------------------------------------------------------------
diff --git a/security-admin/src/main/webapp/scripts/utils/XAUtils.js b/security-admin/src/main/webapp/scripts/utils/XAUtils.js
index 6d84d1c..b8a061f 100644
--- a/security-admin/src/main/webapp/scripts/utils/XAUtils.js
+++ b/security-admin/src/main/webapp/scripts/utils/XAUtils.js
@@ -194,7 +194,8 @@ define(function(require) {
 					html : html,
 					text : text
 				},
-				type : 'info'
+				type : 'info',
+				pausable: true
 			};
 		}
 		$('.top-right').notify(options).show();
@@ -220,7 +221,8 @@ define(function(require) {
 					html : html,
 					text : text
 				},
-				type : 'error'
+				type : 'error',
+				pausable: true
 			};
 		}
 		$('.top-right').notify(options).show();
@@ -246,6 +248,7 @@ define(function(require) {
 					html : html
 				},
 				type : 'success',
+				pausable: true
 			};
 		}
 		$('.top-right').notify(options).show();
@@ -1096,5 +1099,24 @@ define(function(require) {
 		})
 		return {'userRoleList' : userRoleList };
 	};
+	XAUtils.showErrorMsg = function(respMsg){
+		var respArr = respMsg.split(/\([0-9]*\)/);
+		respArr.shift();
+		_.each(respArr, function(str){
+			var validationMsg = str.split(','), erroCodeMsg = '';
+			//get code from string 
+			if(!_.isUndefined(validationMsg[0]) && validationMsg[0].indexOf("error code") != -1){
+				var tmp = validationMsg[0].split('error code');
+				var code = tmp[ tmp.length - 1 ];
+				
+				erroCodeMsg = 'Error Code : '+ code.match(/\d/g).join('');
+				}
+			var reason = str.lastIndexOf("reason") != -1 ? (str.substring(str.lastIndexOf("reason")+7, str.indexOf("field[")-3 ))
+					: str;
+			var erroMsg = erroCodeMsg +"<br/>"+XAUtils.capitaliseFirstLetter(reason);
+			return XAUtils.notifyError('Error', erroMsg);
+		});
+	};
+	
 	return XAUtils;
 });

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/a350aa89/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 7370ee8..b07f9a2 100644
--- a/security-admin/src/main/webapp/scripts/views/policies/RangerPolicyCreate.js
+++ b/security-admin/src/main/webapp/scripts/views/policies/RangerPolicyCreate.js
@@ -207,10 +207,14 @@ define(function(require){
 					App.appRouter.navigate("#!/service/"+that.rangerService.id+"/policies",{trigger: true});
 					console.log("success");
 				},
-				error: function (model, response, options) {
-					    XAUtil.blockUI('unblock');
-						XAUtil.notifyError('Error', 'Error creating Policy!');
-					    console.log("error");
+				error : function(model, response, options) {
+					XAUtil.blockUI('unblock');
+					var msg = that.editPolicy ? 'Error updating policy.': 'Error creating policy.';
+					if (response && response.responseJSON && response.responseJSON.msgDesc) {
+						XAUtil.showErrorMsg(response.responseJSON.msgDesc);
+					} else {
+						XAUtil.notifyError('Error', msg);
+					}
 				}
 			});
 		},

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/a350aa89/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 01141b6..239b61e 100644
--- a/security-admin/src/main/webapp/scripts/views/service/ServiceCreate.js
+++ b/security-admin/src/main/webapp/scripts/views/service/ServiceCreate.js
@@ -164,23 +164,12 @@ define(function(require){
 				},
 				error: function (model, response, options) {
 					XAUtil.blockUI('unblock');
-					if ( response && response.responseJSON && response.responseJSON.msgDesc){
-						if(response.responseJSON.msgDesc == "serverMsg.fsDefaultNameValidationError"){
-							that.form.fields.fsDefaultName.setError(localization.tt(response.responseJSON.msgDesc));
-							XAUtil.scrollToField(that.form.fields.fsDefaultName.$el);
-						}else if(response.responseJSON.msgDesc == "Repository Name already exists"){
-							response.responseJSON.msgDesc = "serverMsg.repositoryNameAlreadyExistsError";
-							that.form.fields.name.setError(localization.tt(response.responseJSON.msgDesc));
-							XAUtil.scrollToField(that.form.fields.name.$el);
-						}else if(response.responseJSON.msgDesc == "XUser already exists"){
-							response.responseJSON.msgDesc = "serverMsg.userAlreadyExistsError";
-							that.form.fields.userName.setError(localization.tt(response.responseJSON.msgDesc));
-							XAUtil.scrollToField(that.form.fields.userName.$el);
-						}else
-							XAUtil.notifyError('Error', response.responseJSON.msgDesc);
-					}else
-						XAUtil.notifyError('Error', 'Error creating Service!');
-					console.log("error");
+					var msg = that.editService ? 'Error updating Service.': 'Error creating Service.';
+					if (response && response.responseJSON && response.responseJSON.msgDesc) {
+						XAUtil.showErrorMsg(response.responseJSON.msgDesc);
+					} else {
+						XAUtil.notifyError('Error', msg);
+					}
 				}
 			});
 		},

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/a350aa89/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 ceb1f53..f0c7530 100644
--- a/security-admin/src/main/webapp/styles/xa.css
+++ b/security-admin/src/main/webapp/styles/xa.css
@@ -1838,4 +1838,9 @@ td.select-row-cell {
 
 #r_topNav .dropdown-menu {
 	margin:0;
+}
+.pause-play-close{
+	margin-left: -5px;
+    margin-top: -2px;
+    font-size: 11px;
 }
\ No newline at end of file


[5/5] incubator-ranger git commit: Merge branch 'master' into tag-policy

Posted by ma...@apache.org.
Merge branch 'master' into tag-policy


Project: http://git-wip-us.apache.org/repos/asf/incubator-ranger/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ranger/commit/3852419c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ranger/tree/3852419c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ranger/diff/3852419c

Branch: refs/heads/tag-policy
Commit: 3852419c32e5f42452f7a83f495f04b9c7c48817
Parents: 9da461d d3c8b3a
Author: Madhan Neethiraj <ma...@apache.org>
Authored: Sun Sep 20 19:11:18 2015 -0700
Committer: Madhan Neethiraj <ma...@apache.org>
Committed: Sun Sep 20 19:11:18 2015 -0700

----------------------------------------------------------------------
 .../ranger/audit/queue/AuditBatchQueue.java     |   2 +-
 .../ranger/audit/queue/AuditFileSpool.java      |  12 ++-
 .../apache/ranger/audit/queue/AuditQueue.java   |   2 +-
 .../java/org/apache/ranger/biz/XUserMgr.java    | 106 +++++++++++++++++++
 .../apache/ranger/service/XAuditMapService.java |  43 +-------
 .../apache/ranger/service/XPermMapService.java  |  47 +-------
 .../bootstrap-notify/js/bootstrap-notify.js     |  44 ++++++--
 .../src/main/webapp/scripts/utils/XAUtils.js    |  26 ++++-
 .../views/policies/RangerPolicyCreate.js        |  12 ++-
 .../scripts/views/service/ServiceCreate.js      |  23 ++--
 security-admin/src/main/webapp/styles/xa.css    |   8 +-
 .../org/apache/ranger/audit/TestAuditQueue.java |   2 +-
 12 files changed, 203 insertions(+), 124 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/3852419c/security-admin/src/main/webapp/scripts/utils/XAUtils.js
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/3852419c/security-admin/src/main/webapp/scripts/views/policies/RangerPolicyCreate.js
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/3852419c/security-admin/src/main/webapp/scripts/views/service/ServiceCreate.js
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/3852419c/security-admin/src/main/webapp/styles/xa.css
----------------------------------------------------------------------
diff --cc security-admin/src/main/webapp/styles/xa.css
index 6b3d3a8,f0c7530..d17f947
--- a/security-admin/src/main/webapp/styles/xa.css
+++ b/security-admin/src/main/webapp/styles/xa.css
@@@ -1839,67 -1839,8 +1839,73 @@@ td.select-row-cell 
  #r_topNav .dropdown-menu {
  	margin:0;
  }
 +
 +.table-policy-condition th,
 +.table-policy-condition td {
 +  border: none !important;
 +  white-space: nowrap;
 +  color: #444444 !important;
 +}
 +
 +.table-policy-condition tr:nth-child(even) td, .table-policy-condition tr:nth-child(even) th  {background-color: #FFFFFF;}
 +.table-policy-condition tr:nth-child(odd) td, .table-policy-condition tr:nth-child(odd) th  {background-color: #EEEEEE;}
 +
 +.table-policy-condition label {
 +  float: left;
 +  margin-right: 10px;
 +}
 +.label-lightblue, .label-lightgreen {text-shadow:none; display: block; margin-bottom: 2px;}
 +.label-lightblue {background-color: #DEEEF9; color: #000;}
 +.label-lightgreen {background-color: #E4F4D8; color: #000;}
 +
 +input[type="radio"], input[type="checkbox"] {margin-top: 0;}
 +
 +.table-policy-condition td:nth-child(3) {
 +  border-left: 2px solid #fff !important;
 +}
 +.table-policy-condition td:nth-child(3) label {
 +  float: none;
 +  text-align: center;
 +  margin-left: 10px;
 +}
 +.white-space-normal{
 +  white-space: normal;
 +  word-break: break-all;
 +}
 +.margin-top-6{
 +  margin-top: 6px;
 +}
 +.tag-fixed-popover {
 +	top: 50px !important;
 +	left: 55% !important;
 +	margin-left: -350px !important;
 +	max-width: 700px !important;
 +	max-height: 500px;
 +	overflow-y: auto;
 +}
 +.tag-fixed-popover-wrapper {
 +	position: fixed !important;
 +    top: 0 !important;
 +    bottom: 0 !important;
 +    right: 0 !important;
 +    left: 0 !important;
 +    z-index: 99 !important;
 +    background-color: rgba(0,0,0,0.5);
 +}
 +.table-policy-condition label {
 +	font-size: 12px;
 +	text-align: left;
 +}
 +.table-policy-condition tr[data-id=storm] td label {
 +    min-width: 170px;
 +}
 +/* align all component 
 +.table-policy-condition td label {
 +    min-width: 170px;
- } */
++} */
++=======
+ .pause-play-close{
+ 	margin-left: -5px;
+     margin-top: -2px;
+     font-size: 11px;
 -}
++}


[3/5] incubator-ranger git commit: RANGER-654: Component process goes in a tight loop if audit destination is down

Posted by ma...@apache.org.
RANGER-654: Component process goes in a tight loop if audit destination
is down

Project: http://git-wip-us.apache.org/repos/asf/incubator-ranger/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ranger/commit/d84e17f9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ranger/tree/d84e17f9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ranger/diff/d84e17f9

Branch: refs/heads/tag-policy
Commit: d84e17f96ec040713989688fa7c5440c112201e5
Parents: 2aa6a89
Author: Don Bosco Durai <bo...@apache.org>
Authored: Fri Sep 18 21:26:54 2015 -0400
Committer: Don Bosco Durai <bo...@apache.org>
Committed: Fri Sep 18 21:26:54 2015 -0400

----------------------------------------------------------------------
 .../org/apache/ranger/audit/queue/AuditBatchQueue.java  |  2 +-
 .../org/apache/ranger/audit/queue/AuditFileSpool.java   | 12 ++++++++++--
 .../java/org/apache/ranger/audit/queue/AuditQueue.java  |  2 +-
 3 files changed, 12 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/d84e17f9/agents-audit/src/main/java/org/apache/ranger/audit/queue/AuditBatchQueue.java
----------------------------------------------------------------------
diff --git a/agents-audit/src/main/java/org/apache/ranger/audit/queue/AuditBatchQueue.java b/agents-audit/src/main/java/org/apache/ranger/audit/queue/AuditBatchQueue.java
index e625d16..f3a38dc 100644
--- a/agents-audit/src/main/java/org/apache/ranger/audit/queue/AuditBatchQueue.java
+++ b/agents-audit/src/main/java/org/apache/ranger/audit/queue/AuditBatchQueue.java
@@ -241,7 +241,7 @@ public class AuditBatchQueue extends AuditQueue implements Runnable {
 			boolean fileSpoolDrain = false;
 			try {
 				if (fileSpoolerEnabled && fileSpooler.isPending()) {
-					int percentUsed = (getMaxQueueSize() - queue.size()) * 100
+					int percentUsed = queue.size() * 100
 							/ getMaxQueueSize();
 					long lastAttemptDelta = fileSpooler
 							.getLastAttemptTimeDelta();

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/d84e17f9/agents-audit/src/main/java/org/apache/ranger/audit/queue/AuditFileSpool.java
----------------------------------------------------------------------
diff --git a/agents-audit/src/main/java/org/apache/ranger/audit/queue/AuditFileSpool.java b/agents-audit/src/main/java/org/apache/ranger/audit/queue/AuditFileSpool.java
index b83329a..bab496c 100644
--- a/agents-audit/src/main/java/org/apache/ranger/audit/queue/AuditFileSpool.java
+++ b/agents-audit/src/main/java/org/apache/ranger/audit/queue/AuditFileSpool.java
@@ -306,8 +306,8 @@ public class AuditFileSpool implements Runnable {
 				+ consumerProvider.getName());
 
 		// Let's start the thread to read
-		destinationThread = new Thread(this, queueProvider.getName()
-				+ "_destWriter");
+		destinationThread = new Thread(this, queueProvider.getName() + "_"
+				+ consumerProvider.getName() + "_destWriter");
 		destinationThread.setDaemon(true);
 		destinationThread.start();
 	}
@@ -776,6 +776,14 @@ public class AuditFileSpool implements Runnable {
 		// boolean isResumed = false;
 		while (true) {
 			try {
+				if (isDestDown) {
+					logger.info("Destination is down. sleeping for "
+							+ retryDestinationMS
+							+ " milli seconds. indexQueue=" + indexQueue.size()
+							+ ", queueName=" + queueProvider.getName()
+							+ ", consumer=" + consumerProvider.getName());
+					Thread.sleep(retryDestinationMS);
+				}
 
 				// Let's pause between each iteration
 				if (currentConsumerIndexRecord == null) {

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/d84e17f9/agents-audit/src/main/java/org/apache/ranger/audit/queue/AuditQueue.java
----------------------------------------------------------------------
diff --git a/agents-audit/src/main/java/org/apache/ranger/audit/queue/AuditQueue.java b/agents-audit/src/main/java/org/apache/ranger/audit/queue/AuditQueue.java
index 88c9831..c5eb3da 100644
--- a/agents-audit/src/main/java/org/apache/ranger/audit/queue/AuditQueue.java
+++ b/agents-audit/src/main/java/org/apache/ranger/audit/queue/AuditQueue.java
@@ -32,7 +32,7 @@ public abstract class AuditQueue extends BaseAuditHandler {
 	private static final Log LOG = LogFactory.getLog(AuditQueue.class);
 
 	public static final int AUDIT_MAX_QUEUE_SIZE_DEFAULT = 1024 * 1024;
-	public static final int AUDIT_BATCH_INTERVAL_DEFAULT_MS = 1000;
+	public static final int AUDIT_BATCH_INTERVAL_DEFAULT_MS = 3000;
 	public static final int AUDIT_BATCH_SIZE_DEFAULT = 1000;
 
 	// This is the max time the consumer thread will wait before exiting the


[4/5] incubator-ranger git commit: RANGER-654: Increasing interval time to fix junit error

Posted by ma...@apache.org.
RANGER-654: Increasing interval time to fix junit error

Project: http://git-wip-us.apache.org/repos/asf/incubator-ranger/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ranger/commit/d3c8b3a3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ranger/tree/d3c8b3a3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ranger/diff/d3c8b3a3

Branch: refs/heads/tag-policy
Commit: d3c8b3a33d1441f0b2d354419e6126b8873c8e3a
Parents: d84e17f
Author: Don Bosco Durai <bo...@apache.org>
Authored: Sat Sep 19 20:08:43 2015 -0400
Committer: Don Bosco Durai <bo...@apache.org>
Committed: Sat Sep 19 20:08:43 2015 -0400

----------------------------------------------------------------------
 .../src/test/java/org/apache/ranger/audit/TestAuditQueue.java      | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/d3c8b3a3/security-admin/src/test/java/org/apache/ranger/audit/TestAuditQueue.java
----------------------------------------------------------------------
diff --git a/security-admin/src/test/java/org/apache/ranger/audit/TestAuditQueue.java b/security-admin/src/test/java/org/apache/ranger/audit/TestAuditQueue.java
index f09da53..3fe6246 100644
--- a/security-admin/src/test/java/org/apache/ranger/audit/TestAuditQueue.java
+++ b/security-admin/src/test/java/org/apache/ranger/audit/TestAuditQueue.java
@@ -409,7 +409,7 @@ public class TestAuditQueue {
 				+ MiscUtil.generateUniqueId();
 		int batchSize = messageToSend / 3;
 		int queueSize = messageToSend * 2;
-		int intervalMS = 3000; // Deliberately big interval
+		int intervalMS = 5000; // Deliberately big interval
 		Properties props = new Properties();
 		props.put(
 				basePropName + "." + BaseAuditHandler.PROP_NAME,


[2/5] incubator-ranger git commit: RANGER-653 : Delegated Admin check has been moved to Mgr level

Posted by ma...@apache.org.
RANGER-653 : Delegated Admin check has been moved to Mgr level

Signed-off-by: Velmurugan Periasamy <ve...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/incubator-ranger/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ranger/commit/2aa6a89b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ranger/tree/2aa6a89b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ranger/diff/2aa6a89b

Branch: refs/heads/tag-policy
Commit: 2aa6a89b6b2f7f0263d0af2ae00f0bc821179101
Parents: a350aa8
Author: Gautam Borad <gb...@gmail.com>
Authored: Fri Sep 18 11:54:26 2015 +0530
Committer: Velmurugan Periasamy <ve...@apache.org>
Committed: Fri Sep 18 12:40:57 2015 -0400

----------------------------------------------------------------------
 .../java/org/apache/ranger/biz/XUserMgr.java    | 106 +++++++++++++++++++
 .../apache/ranger/service/XAuditMapService.java |  43 +-------
 .../apache/ranger/service/XPermMapService.java  |  47 +-------
 3 files changed, 108 insertions(+), 88 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/2aa6a89b/security-admin/src/main/java/org/apache/ranger/biz/XUserMgr.java
----------------------------------------------------------------------
diff --git a/security-admin/src/main/java/org/apache/ranger/biz/XUserMgr.java b/security-admin/src/main/java/org/apache/ranger/biz/XUserMgr.java
index 2413afb..41bc6f8 100644
--- a/security-admin/src/main/java/org/apache/ranger/biz/XUserMgr.java
+++ b/security-admin/src/main/java/org/apache/ranger/biz/XUserMgr.java
@@ -42,6 +42,7 @@ import org.apache.ranger.view.VXGroupPermission;
 import org.apache.ranger.view.VXModuleDef;
 import org.apache.ranger.view.VXUserPermission;
 import org.apache.log4j.Logger;
+import org.apache.ranger.common.AppConstants;
 import org.apache.ranger.common.MessageEnums;
 import org.apache.ranger.common.PropertiesUtil;
 import org.apache.ranger.common.RangerConstants;
@@ -53,10 +54,12 @@ import org.apache.ranger.entity.XXAuditMap;
 import org.apache.ranger.entity.XXGroup;
 import org.apache.ranger.entity.XXPermMap;
 import org.apache.ranger.entity.XXPortalUser;
+import org.apache.ranger.entity.XXResource;
 import org.apache.ranger.entity.XXTrxLog;
 import org.apache.ranger.entity.XXUser;
 import org.apache.ranger.service.XGroupService;
 import org.apache.ranger.service.XUserService;
+import org.apache.ranger.view.VXAuditMap;
 import org.apache.ranger.view.VXAuditMapList;
 import org.apache.ranger.view.VXGroup;
 import org.apache.ranger.view.VXGroupGroup;
@@ -64,6 +67,7 @@ import org.apache.ranger.view.VXGroupList;
 import org.apache.ranger.view.VXGroupUser;
 import org.apache.ranger.view.VXGroupUserList;
 import org.apache.ranger.view.VXLong;
+import org.apache.ranger.view.VXPermMap;
 import org.apache.ranger.view.VXPermMapList;
 import org.apache.ranger.view.VXPortalUser;
 import org.apache.ranger.view.VXUser;
@@ -1036,4 +1040,106 @@ public class XUserMgr extends XUserMgrBase {
 		}
 	}
 
+	public VXPermMapList searchXPermMaps(SearchCriteria searchCriteria) {
+		VXPermMapList vXPermMapList = super.searchXPermMaps(searchCriteria);
+		return applyDelegatedAdminAccess(vXPermMapList, searchCriteria);
+	}
+
+	private VXPermMapList applyDelegatedAdminAccess(VXPermMapList vXPermMapList, SearchCriteria searchCriteria) {
+
+		VXPermMapList returnList;
+		UserSessionBase currentUserSession = ContextUtil.getCurrentUserSession();
+		// If user is system admin
+		if (currentUserSession != null && currentUserSession.isUserAdmin()) {
+			returnList = super.searchXPermMaps(searchCriteria);
+		} else {
+			returnList = new VXPermMapList();
+			int startIndex = searchCriteria.getStartIndex();
+			int pageSize = searchCriteria.getMaxRows();
+			searchCriteria.setStartIndex(0);
+			searchCriteria.setMaxRows(Integer.MAX_VALUE);
+			List<VXPermMap> resultList = xPermMapService.searchXPermMaps(searchCriteria).getVXPermMaps();
+
+			List<VXPermMap> adminPermResourceList = new ArrayList<VXPermMap>();
+			for (VXPermMap xXPermMap : resultList) {
+				XXResource xRes = daoManager.getXXResource().getById(xXPermMap.getResourceId());
+				VXResponse vXResponse = msBizUtil.hasPermission(xResourceService.populateViewBean(xRes),
+						AppConstants.XA_PERM_TYPE_ADMIN);
+				if (vXResponse.getStatusCode() == VXResponse.STATUS_SUCCESS) {
+					adminPermResourceList.add(xXPermMap);
+				}
+			}
+
+			if (adminPermResourceList.size() > 0) {
+				populatePageList(adminPermResourceList, startIndex, pageSize, returnList);
+			}
+		}
+		return returnList;
+	}
+
+	private void populatePageList(List<VXPermMap> permMapList, int startIndex, int pageSize, VXPermMapList vxPermMapList) {
+		List<VXPermMap> onePageList = new ArrayList<VXPermMap>();
+		for (int i = startIndex; i < pageSize + startIndex && i < permMapList.size(); i++) {
+			VXPermMap vXPermMap = permMapList.get(i);
+			onePageList.add(vXPermMap);
+		}
+		vxPermMapList.setVXPermMaps(onePageList);
+		vxPermMapList.setStartIndex(startIndex);
+		vxPermMapList.setPageSize(pageSize);
+		vxPermMapList.setResultSize(onePageList.size());
+		vxPermMapList.setTotalCount(permMapList.size());
+	}
+
+	public VXAuditMapList searchXAuditMaps(SearchCriteria searchCriteria) {
+		VXAuditMapList vXAuditMapList = xAuditMapService.searchXAuditMaps(searchCriteria);
+		return applyDelegatedAdminAccess(vXAuditMapList, searchCriteria);
+	}
+
+	private VXAuditMapList applyDelegatedAdminAccess(VXAuditMapList vXAuditMapList, SearchCriteria searchCriteria) {
+
+		VXAuditMapList returnList;
+		UserSessionBase currentUserSession = ContextUtil.getCurrentUserSession();
+		// If user is system admin
+		if (currentUserSession != null && currentUserSession.isUserAdmin()) {
+			returnList = super.searchXAuditMaps(searchCriteria);
+		} else {
+			returnList = new VXAuditMapList();
+			int startIndex = searchCriteria.getStartIndex();
+			int pageSize = searchCriteria.getMaxRows();
+			searchCriteria.setStartIndex(0);
+			searchCriteria.setMaxRows(Integer.MAX_VALUE);
+			List<VXAuditMap> resultList = xAuditMapService.searchXAuditMaps(searchCriteria).getVXAuditMaps();
+
+			List<VXAuditMap> adminAuditResourceList = new ArrayList<VXAuditMap>();
+			for (VXAuditMap xXAuditMap : resultList) {
+				XXResource xRes = daoManager.getXXResource().getById(xXAuditMap.getResourceId());
+				VXResponse vXResponse = msBizUtil.hasPermission(xResourceService.populateViewBean(xRes),
+						AppConstants.XA_PERM_TYPE_ADMIN);
+				if (vXResponse.getStatusCode() == VXResponse.STATUS_SUCCESS) {
+					adminAuditResourceList.add(xXAuditMap);
+				}
+			}
+
+			if (adminAuditResourceList.size() > 0) {
+				populatePageList(adminAuditResourceList, startIndex, pageSize, returnList);
+			}
+		}
+
+		return returnList;
+	}
+
+	private void populatePageList(List<VXAuditMap> auditMapList, int startIndex, int pageSize,
+			VXAuditMapList vxAuditMapList) {
+		List<VXAuditMap> onePageList = new ArrayList<VXAuditMap>();
+		for (int i = startIndex; i < pageSize + startIndex && i < auditMapList.size(); i++) {
+			VXAuditMap vXAuditMap = auditMapList.get(i);
+			onePageList.add(vXAuditMap);
+		}
+		vxAuditMapList.setVXAuditMaps(onePageList);
+		vxAuditMapList.setStartIndex(startIndex);
+		vxAuditMapList.setPageSize(pageSize);
+		vxAuditMapList.setResultSize(onePageList.size());
+		vxAuditMapList.setTotalCount(auditMapList.size());
+	}
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/2aa6a89b/security-admin/src/main/java/org/apache/ranger/service/XAuditMapService.java
----------------------------------------------------------------------
diff --git a/security-admin/src/main/java/org/apache/ranger/service/XAuditMapService.java b/security-admin/src/main/java/org/apache/ranger/service/XAuditMapService.java
index 349ddbd..462b81a 100644
--- a/security-admin/src/main/java/org/apache/ranger/service/XAuditMapService.java
+++ b/security-admin/src/main/java/org/apache/ranger/service/XAuditMapService.java
@@ -202,48 +202,7 @@ public class XAuditMapService extends
 
 	@Override
 	public VXAuditMapList searchXAuditMaps(SearchCriteria searchCriteria) {
-
-		VXAuditMapList returnList;
-		UserSessionBase currentUserSession = ContextUtil.getCurrentUserSession();
-		// If user is system admin
-		if (currentUserSession.isUserAdmin()) {
-			returnList = super.searchXAuditMaps(searchCriteria);
-		} else {
-			returnList = new VXAuditMapList();
-			int startIndex = searchCriteria.getStartIndex();
-			int pageSize = searchCriteria.getMaxRows();
-			searchCriteria.setStartIndex(0);
-			searchCriteria.setMaxRows(Integer.MAX_VALUE);
-			List<XXAuditMap> resultList = (List<XXAuditMap>) searchResources(searchCriteria, searchFields, sortFields, returnList);
-
-			List<XXAuditMap> adminAuditResourceList = new ArrayList<XXAuditMap>();
-			for (XXAuditMap xXAuditMap : resultList) {
-				XXResource xRes = daoManager.getXXResource().getById(xXAuditMap.getResourceId());
-				VXResponse vXResponse = rangerBizUtil.hasPermission(xResourceService.populateViewBean(xRes), AppConstants.XA_PERM_TYPE_ADMIN);
-				if (vXResponse.getStatusCode() == VXResponse.STATUS_SUCCESS) {
-					adminAuditResourceList.add(xXAuditMap);
-				}
-			}
-
-			if (adminAuditResourceList.size() > 0) {
-				populatePageList(adminAuditResourceList, startIndex, pageSize, returnList);
-			}
-		}
-
-		return returnList;
-	}
-
-	private void populatePageList(List<XXAuditMap> auditMapList, int startIndex, int pageSize, VXAuditMapList vxAuditMapList) {
-		List<VXAuditMap> onePageList = new ArrayList<VXAuditMap>();
-		for (int i = startIndex; i < pageSize + startIndex && i < auditMapList.size(); i++) {
-			VXAuditMap vXAuditMap = populateViewBean(auditMapList.get(i));
-			onePageList.add(vXAuditMap);
-		}
-		vxAuditMapList.setVXAuditMaps(onePageList);
-		vxAuditMapList.setStartIndex(startIndex);
-		vxAuditMapList.setPageSize(pageSize);
-		vxAuditMapList.setResultSize(onePageList.size());
-		vxAuditMapList.setTotalCount(auditMapList.size());
+		return super.searchXAuditMaps(searchCriteria);
 	}
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/2aa6a89b/security-admin/src/main/java/org/apache/ranger/service/XPermMapService.java
----------------------------------------------------------------------
diff --git a/security-admin/src/main/java/org/apache/ranger/service/XPermMapService.java b/security-admin/src/main/java/org/apache/ranger/service/XPermMapService.java
index 6d96107..c20373d 100644
--- a/security-admin/src/main/java/org/apache/ranger/service/XPermMapService.java
+++ b/security-admin/src/main/java/org/apache/ranger/service/XPermMapService.java
@@ -26,23 +26,19 @@ import java.util.List;
 
 import org.apache.ranger.biz.RangerBizUtil;
 import org.apache.ranger.common.AppConstants;
-import org.apache.ranger.common.ContextUtil;
 import org.apache.ranger.common.SearchCriteria;
 import org.apache.ranger.common.SearchField;
-import org.apache.ranger.common.UserSessionBase;
 import org.apache.ranger.common.view.VTrxLogAttr;
 import org.apache.ranger.db.RangerDaoManager;
 import org.apache.ranger.entity.XXGroup;
 import org.apache.ranger.entity.XXPermMap;
 import org.apache.ranger.entity.XXPortalUser;
-import org.apache.ranger.entity.XXResource;
 import org.apache.ranger.entity.XXTrxLog;
 import org.apache.ranger.entity.XXUser;
 import org.apache.ranger.util.RangerEnumUtil;
 import org.apache.ranger.view.VXGroup;
 import org.apache.ranger.view.VXPermMap;
 import org.apache.ranger.view.VXPermMapList;
-import org.apache.ranger.view.VXResponse;
 import org.apache.ranger.view.VXUser;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Scope;
@@ -123,48 +119,7 @@ public class XPermMapService extends XPermMapServiceBase<XXPermMap, VXPermMap> {
 	
 	@Override
 	public VXPermMapList searchXPermMaps(SearchCriteria searchCriteria) {
-
-
-		VXPermMapList returnList;
-		UserSessionBase currentUserSession = ContextUtil.getCurrentUserSession();
-		// If user is system admin
-		if (currentUserSession.isUserAdmin()) {
-			returnList = super.searchXPermMaps(searchCriteria);
-		} else {
-			returnList = new VXPermMapList();
-			int startIndex = searchCriteria.getStartIndex();
-			int pageSize = searchCriteria.getMaxRows();
-			searchCriteria.setStartIndex(0);
-			searchCriteria.setMaxRows(Integer.MAX_VALUE);
-			List<XXPermMap> resultList = (List<XXPermMap>) searchResources(searchCriteria, searchFields, sortFields, returnList);
-
-			List<XXPermMap> adminPermResourceList = new ArrayList<XXPermMap>();
-			for (XXPermMap xXPermMap : resultList) {
-				XXResource xRes = daoManager.getXXResource().getById(xXPermMap.getResourceId());
-				VXResponse vXResponse = rangerBizUtil.hasPermission(xResourceService.populateViewBean(xRes), AppConstants.XA_PERM_TYPE_ADMIN);
-				if (vXResponse.getStatusCode() == VXResponse.STATUS_SUCCESS) {
-					adminPermResourceList.add(xXPermMap);
-				}
-			}
-
-			if (adminPermResourceList.size() > 0) {
-				populatePageList(adminPermResourceList, startIndex, pageSize, returnList);
-			}
-		}
-		return returnList;
-	}
-	
-	private void populatePageList(List<XXPermMap> permMapList, int startIndex, int pageSize, VXPermMapList vxPermMapList) {
-		List<VXPermMap> onePageList = new ArrayList<VXPermMap>();
-		for (int i = startIndex; i < pageSize + startIndex && i < permMapList.size(); i++) {
-			VXPermMap vXPermMap = populateViewBean(permMapList.get(i));
-			onePageList.add(vXPermMap);
-		}
-		vxPermMapList.setVXPermMaps(onePageList);
-		vxPermMapList.setStartIndex(startIndex);
-		vxPermMapList.setPageSize(pageSize);
-		vxPermMapList.setResultSize(onePageList.size());
-		vxPermMapList.setTotalCount(permMapList.size());
+		return super.searchXPermMaps(searchCriteria);
 	}
 	
 	public String getGroupName(Long groupId){