You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sentry.apache.org by co...@apache.org on 2017/10/27 10:28:31 UTC
sentry git commit: SENTRY-1992 Improve parameter handling for
SentryGenericProviderBackend
Repository: sentry
Updated Branches:
refs/heads/master 6fa02888f -> 54fbb9a94
SENTRY-1992 Improve parameter handling for SentryGenericProviderBackend
Signed-off-by: Colm O hEigeartaigh <co...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/sentry/repo
Commit: http://git-wip-us.apache.org/repos/asf/sentry/commit/54fbb9a9
Tree: http://git-wip-us.apache.org/repos/asf/sentry/tree/54fbb9a9
Diff: http://git-wip-us.apache.org/repos/asf/sentry/diff/54fbb9a9
Branch: refs/heads/master
Commit: 54fbb9a9449b87c4981f3d481cb25714eb217f49
Parents: 6fa0288
Author: Mano Kovacs <ma...@gmail.com>
Authored: Tue Oct 24 17:29:37 2017 +0200
Committer: Colm O hEigeartaigh <co...@apache.org>
Committed: Fri Oct 27 11:28:16 2017 +0100
----------------------------------------------------------------------
.../generic/SentryGenericProviderBackend.java | 7 +++
.../sentry/service/thrift/ServiceConstants.java | 3 ++
.../TestSentryGenericProviderBackend.java | 47 ++++++++++++++++++++
3 files changed, 57 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/sentry/blob/54fbb9a9/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/generic/SentryGenericProviderBackend.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/generic/SentryGenericProviderBackend.java b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/generic/SentryGenericProviderBackend.java
index 6c7d3ef..cf552b1 100644
--- a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/generic/SentryGenericProviderBackend.java
+++ b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/generic/SentryGenericProviderBackend.java
@@ -22,6 +22,7 @@ import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
import java.util.Set;
+import com.google.common.base.Preconditions;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.security.UserGroupInformation;
import org.apache.sentry.core.common.exception.SentryUserException;
@@ -61,6 +62,8 @@ public class SentryGenericProviderBackend extends CacheProvider implements Provi
this.conf = conf;
this.enableCaching = conf.getBoolean(ServiceConstants.ClientConfig.ENABLE_CACHING, ServiceConstants.ClientConfig.ENABLE_CACHING_DEFAULT);
this.privilegeConverter = conf.get(ServiceConstants.ClientConfig.PRIVILEGE_CONVERTER);
+ this.setServiceName(conf.get(ServiceConstants.ClientConfig.SERVICE_NAME));
+ this.setComponentType(conf.get(ServiceConstants.ClientConfig.COMPONENT_TYPE));
}
@Override
@@ -68,6 +71,10 @@ public class SentryGenericProviderBackend extends CacheProvider implements Provi
if (initialized) {
throw new IllegalStateException("SentryGenericProviderBackend has already been initialized, cannot be initialized twice");
}
+
+ Preconditions.checkNotNull(serviceName, "Service name is not defined. Use configuration parameter: " + conf.get(ServiceConstants.ClientConfig.SERVICE_NAME));
+ Preconditions.checkNotNull(componentType, "Component type is not defined. Use configuration parameter: " + conf.get(ServiceConstants.ClientConfig.COMPONENT_TYPE));
+
if (enableCaching) {
if (privilegeConverter == null) {
throw new SentryConfigurationException(ServiceConstants.ClientConfig.PRIVILEGE_CONVERTER + " not configured.");
http://git-wip-us.apache.org/repos/asf/sentry/blob/54fbb9a9/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/ServiceConstants.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/ServiceConstants.java b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/ServiceConstants.java
index 280aebc..8dd5497 100644
--- a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/ServiceConstants.java
+++ b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/ServiceConstants.java
@@ -289,6 +289,9 @@ public class ServiceConstants {
public static final String CACHE_UPDATE_FAILURES_BEFORE_PRIV_REVOKE = "sentry.provider.backend.generic.cache.update.failures.count";
public static final int CACHE_UPDATE_FAILURES_BEFORE_PRIV_REVOKE_DEFAULT = 3;
public static final String PRIVILEGE_CONVERTER = "sentry.provider.backend.generic.privilege.converter";
+
+ public static final String COMPONENT_TYPE = "sentry.provider.backend.generic.component-type";
+ public static final String SERVICE_NAME = "sentry.provider.backend.generic.service-name";
}
/**
http://git-wip-us.apache.org/repos/asf/sentry/blob/54fbb9a9/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/generic/TestSentryGenericProviderBackend.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/generic/TestSentryGenericProviderBackend.java b/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/generic/TestSentryGenericProviderBackend.java
new file mode 100644
index 0000000..83b0f42
--- /dev/null
+++ b/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/generic/TestSentryGenericProviderBackend.java
@@ -0,0 +1,47 @@
+/**
+ * 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.sentry.provider.db.generic;
+
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.sentry.provider.common.ProviderBackendContext;
+import org.junit.Test;
+
+import static org.apache.sentry.service.thrift.ServiceConstants.ClientConfig.COMPONENT_TYPE;
+import static org.apache.sentry.service.thrift.ServiceConstants.ClientConfig.SERVICE_NAME;
+import static org.junit.Assert.assertEquals;
+
+public class TestSentryGenericProviderBackend {
+ @Test
+ public void testScopeParamsGrabbedFromConf() throws Exception {
+ Configuration conf = new Configuration();
+ String sampleServiceName = "sampleServiceName123";
+ String sampleComponentType = "sampleComponentType123";
+ conf.set(SERVICE_NAME, sampleServiceName);
+ conf.set(COMPONENT_TYPE, sampleComponentType);
+ SentryGenericProviderBackend providerBackend = new SentryGenericProviderBackend(conf, "resource");
+ assertEquals(sampleComponentType, providerBackend.getComponentType());
+ assertEquals(sampleServiceName, providerBackend.getServiceName());
+ }
+ @Test(expected = NullPointerException.class)
+ public void testScopeParamsValidated() throws Exception {
+ Configuration conf = new Configuration();
+ SentryGenericProviderBackend providerBackend = new SentryGenericProviderBackend(conf, "resource");
+ providerBackend.initialize(new ProviderBackendContext());
+ }
+}