You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ranger.apache.org by pr...@apache.org on 2019/05/22 03:31:08 UTC

[ranger] branch master updated: RANGER-2436 : Custom condition: Access from cluster

This is an automated email from the ASF dual-hosted git repository.

pradeep pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ranger.git


The following commit(s) were added to refs/heads/master by this push:
     new a727246  RANGER-2436 : Custom condition: Access from cluster
a727246 is described below

commit a72724663c7d52baa3bca048a18e9a89fad7b65b
Author: Nikhil P <ni...@gmail.com>
AuthorDate: Tue May 21 18:53:29 2019 +0530

    RANGER-2436 : Custom condition: Access from cluster
---
 .../RangerAccessedFromClusterCondition.java        | 68 ++++++++++++++++++++++
 .../RangerAccessedNotFromClusterCondition.java     | 68 ++++++++++++++++++++++
 2 files changed, 136 insertions(+)

diff --git a/agents-common/src/main/java/org/apache/ranger/plugin/conditionevaluator/RangerAccessedFromClusterCondition.java b/agents-common/src/main/java/org/apache/ranger/plugin/conditionevaluator/RangerAccessedFromClusterCondition.java
new file mode 100644
index 0000000..e5cc916
--- /dev/null
+++ b/agents-common/src/main/java/org/apache/ranger/plugin/conditionevaluator/RangerAccessedFromClusterCondition.java
@@ -0,0 +1,68 @@
+/*
+ * 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.
+ */
+
+package org.apache.ranger.plugin.conditionevaluator;
+
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.ranger.plugin.policyengine.RangerAccessRequest;
+
+
+public class RangerAccessedFromClusterCondition extends RangerAbstractConditionEvaluator {
+	private static final Log LOG = LogFactory.getLog(RangerAccessedFromClusterCondition.class);
+
+	private boolean isAlwaysTrue = false;
+
+	@Override
+	public void init() {
+		if (LOG.isDebugEnabled()) {
+			LOG.debug("==> RangerAccessedFromClusterCondition.init(" + condition + ")");
+		}
+
+		super.init();
+
+		isAlwaysTrue = CollectionUtils.isEmpty(condition.getValues());
+
+		if (LOG.isDebugEnabled()) {
+			LOG.debug("<== RangerAccessedFromClusterCondition.init(" + condition + ")");
+		}
+	}
+
+	@Override
+	public boolean isMatched(RangerAccessRequest request) {
+		if (LOG.isDebugEnabled()) {
+			LOG.debug("==> RangerAccessedFromClusterCondition.isMatched(" + condition + ")");
+		}
+
+		final boolean ret;
+
+		if (isAlwaysTrue || request.getClusterName() == null) {
+			ret = isAlwaysTrue;
+		} else {
+			ret = condition.getValues().contains(request.getClusterName());
+		}
+
+		if (LOG.isDebugEnabled()) {
+			LOG.debug("<== RangerAccessedFromClusterCondition.isMatched(" + condition + "): " + ret);
+		}
+
+		return ret;
+	}
+}
diff --git a/agents-common/src/main/java/org/apache/ranger/plugin/conditionevaluator/RangerAccessedNotFromClusterCondition.java b/agents-common/src/main/java/org/apache/ranger/plugin/conditionevaluator/RangerAccessedNotFromClusterCondition.java
new file mode 100644
index 0000000..d8e966c
--- /dev/null
+++ b/agents-common/src/main/java/org/apache/ranger/plugin/conditionevaluator/RangerAccessedNotFromClusterCondition.java
@@ -0,0 +1,68 @@
+/*
+ * 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.
+ */
+
+package org.apache.ranger.plugin.conditionevaluator;
+
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.ranger.plugin.policyengine.RangerAccessRequest;
+
+
+public class RangerAccessedNotFromClusterCondition extends RangerAbstractConditionEvaluator {
+	private static final Log LOG = LogFactory.getLog(RangerAccessedNotFromClusterCondition.class);
+
+	private boolean isAlwaysTrue = false;
+
+	@Override
+	public void init() {
+		if (LOG.isDebugEnabled()) {
+			LOG.debug("==> RangerAccessedNotFromClusterCondition.init(" + condition + ")");
+		}
+
+		super.init();
+
+		isAlwaysTrue = CollectionUtils.isEmpty(condition.getValues());
+
+		if (LOG.isDebugEnabled()) {
+			LOG.debug("<== RangerAccessedNotFromClusterCondition.init(" + condition + ")");
+		}
+	}
+
+	@Override
+	public boolean isMatched(RangerAccessRequest request) {
+		if (LOG.isDebugEnabled()) {
+			LOG.debug("==> RangerAccessedNotFromClusterCondition.isMatched(" + condition + ")");
+		}
+
+		final boolean ret;
+
+		if (isAlwaysTrue || request.getClusterName() == null) {
+			ret = true;
+		} else {
+			ret = !condition.getValues().contains(request.getClusterName());
+		}
+
+		if (LOG.isDebugEnabled()) {
+			LOG.debug("<== RangerAccessedNotFromClusterCondition.isMatched(" + condition + "): " + ret);
+		}
+
+		return ret;
+	}
+}