Repository: incubator-sentry Updated Branches: refs/heads/SENTRY-999 48c021a00 -> 048c9d672
SENTRY-1091: Create Model for specific components (Colin Ma, Reviewed by Dapeng Sun) Project: http://git-wip-us.apache.org/repos/asf/incubator-sentry/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-sentry/commit/048c9d67 Tree: http://git-wip-us.apache.org/repos/asf/incubator-sentry/tree/048c9d67 Diff: http://git-wip-us.apache.org/repos/asf/incubator-sentry/diff/048c9d67 Branch: refs/heads/SENTRY-999 Commit: 048c9d672eccb8be646a43d1361698c1fdc4b99e Parents: 48c021a Author: Colin Ma <co...@apache.org> Authored: Wed Feb 24 10:23:40 2016 +0800 Committer: Colin Ma <co...@apache.org> Committed: Wed Feb 24 10:23:40 2016 +0800 ---------------------------------------------------------------------- .../sentry/core/model/db/HiveActionFactory.java | 73 ++++++++++++++++++++ .../core/model/db/HivePrivilegeModel.java | 57 +++++++++++++++ .../model/indexer/IndexerPrivilegeModel.java | 53 ++++++++++++++ .../core/model/search/SearchPrivilegeModel.java | 54 +++++++++++++++ .../core/model/sqoop/SqoopPrivilegeModel.java | 56 +++++++++++++++ 5 files changed, 293 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/048c9d67/sentry-core/sentry-core-model-db/src/main/java/org/apache/sentry/core/model/db/HiveActionFactory.java ---------------------------------------------------------------------- diff --git a/sentry-core/sentry-core-model-db/src/main/java/org/apache/sentry/core/model/db/HiveActionFactory.java b/sentry-core/sentry-core-model-db/src/main/java/org/apache/sentry/core/model/db/HiveActionFactory.java new file mode 100644 index 0000000..ad7e1c9 --- /dev/null +++ b/sentry-core/sentry-core-model-db/src/main/java/org/apache/sentry/core/model/db/HiveActionFactory.java @@ -0,0 +1,73 @@ +/* + * 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.core.model.db; + +import org.apache.sentry.core.common.BitFieldAction; +import org.apache.sentry.core.common.BitFieldActionFactory; + +import java.util.List; + +// The class is used to define the privilege code for Hive +public class HiveActionFactory extends BitFieldActionFactory { + + enum ActionType { + SELECT(AccessConstants.SELECT, 1), // binary: 00000001 + INSERT(AccessConstants.INSERT, 2), // binary: 00000010 + ALTER(AccessConstants.ALTER, 4), // binary: 00000100 + CREATE(AccessConstants.CREATE, 8), // binary: 00001000 + DROP(AccessConstants.DROP, 16), // binary: 00010000 + INDEX(AccessConstants.INDEX, 32), // binary: 00100000 + LOCK(AccessConstants.LOCK, 64), // binary: 01000000 + + // For the compatibility, ALL, ALL_STAR, SOME have the same binary value: 01111111 + // They have the different names which are "ALL", "*", "+" + ALL(AccessConstants.ACTION_ALL, SELECT.getCode() | INSERT.getCode() | ALTER.getCode() | CREATE.getCode() | + DROP.getCode() | INDEX.getCode() | LOCK.getCode()), // binary: 01111111 + ALL_STAR(AccessConstants.ALL, ALL.getCode()), // binary: 01111111 + SOME(AccessConstants.SOME, ALL.getCode()); // binary: 01111111 + + private String name; + private int code; + + ActionType(String name, int code) { + this.name = name; + this.code = code; + } + + public int getCode() { + return code; + } + + public String getName() { + return name; + } + } + + public List<? extends BitFieldAction> getActionsByCode(int actionCode) { + return null; + } + + public BitFieldAction getActionByName(String name) { + for (ActionType action : ActionType.values()) { + if (action.name.equalsIgnoreCase(name)) { + return new BitFieldAction(action.getName(), action.getCode()); + } + } + return null; + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/048c9d67/sentry-core/sentry-core-model-db/src/main/java/org/apache/sentry/core/model/db/HivePrivilegeModel.java ---------------------------------------------------------------------- diff --git a/sentry-core/sentry-core-model-db/src/main/java/org/apache/sentry/core/model/db/HivePrivilegeModel.java b/sentry-core/sentry-core-model-db/src/main/java/org/apache/sentry/core/model/db/HivePrivilegeModel.java new file mode 100644 index 0000000..f2cc77f --- /dev/null +++ b/sentry-core/sentry-core-model-db/src/main/java/org/apache/sentry/core/model/db/HivePrivilegeModel.java @@ -0,0 +1,57 @@ +/* + * 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.core.model.db; + +import org.apache.sentry.core.common.BitFieldActionFactory; +import org.apache.sentry.core.common.ImplyMethodType; +import org.apache.sentry.core.common.Model; + +import java.util.HashMap; +import java.util.Map; + +import static org.apache.sentry.core.model.db.DBModelAuthorizable.AuthorizableType; + +public class HivePrivilegeModel implements Model { + private Map<String, ImplyMethodType> implyMethodMap; + private BitFieldActionFactory bitFieldActionFactory; + private static HivePrivilegeModel hivePrivilegeModel = new HivePrivilegeModel(); + + private HivePrivilegeModel() { + implyMethodMap = new HashMap<String, ImplyMethodType>(); + bitFieldActionFactory = new HiveActionFactory(); + + implyMethodMap.put(AuthorizableType.Server.name().toLowerCase(), ImplyMethodType.STRING); + implyMethodMap.put(AuthorizableType.Db.name().toLowerCase(), ImplyMethodType.STRING); + implyMethodMap.put(AuthorizableType.Table.name().toLowerCase(), ImplyMethodType.STRING); + implyMethodMap.put(AuthorizableType.Column.name().toLowerCase(), ImplyMethodType.STRING); + implyMethodMap.put(AuthorizableType.URI.name().toLowerCase(), ImplyMethodType.URL); + } + + @Override + public Map<String, ImplyMethodType> getImplyMethodMap() { + return implyMethodMap; + } + + @Override + public BitFieldActionFactory getBitFieldActionFactory() { + return bitFieldActionFactory; + } + + public static Model getInstance() { + return hivePrivilegeModel; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/048c9d67/sentry-core/sentry-core-model-indexer/src/main/java/org/apache/sentry/core/model/indexer/IndexerPrivilegeModel.java ---------------------------------------------------------------------- diff --git a/sentry-core/sentry-core-model-indexer/src/main/java/org/apache/sentry/core/model/indexer/IndexerPrivilegeModel.java b/sentry-core/sentry-core-model-indexer/src/main/java/org/apache/sentry/core/model/indexer/IndexerPrivilegeModel.java new file mode 100644 index 0000000..be15dec --- /dev/null +++ b/sentry-core/sentry-core-model-indexer/src/main/java/org/apache/sentry/core/model/indexer/IndexerPrivilegeModel.java @@ -0,0 +1,53 @@ +/* + * 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.core.model.indexer; + +import org.apache.sentry.core.common.BitFieldActionFactory; +import org.apache.sentry.core.common.ImplyMethodType; +import org.apache.sentry.core.common.Model; + +import java.util.HashMap; +import java.util.Map; + +public class IndexerPrivilegeModel implements Model { + + private Map<String, ImplyMethodType> implyMethodMap; + private BitFieldActionFactory bitFieldActionFactory; + private static IndexerPrivilegeModel indexerPrivilegeModel = new IndexerPrivilegeModel();; + + private IndexerPrivilegeModel() { + implyMethodMap = new HashMap<String, ImplyMethodType>(); + bitFieldActionFactory = new IndexerActionFactory(); + + implyMethodMap.put(IndexerModelAuthorizable.AuthorizableType.Indexer.name().toLowerCase(), ImplyMethodType.STRING); + } + + @Override + public Map<String, ImplyMethodType> getImplyMethodMap() { + return implyMethodMap; + } + + @Override + public BitFieldActionFactory getBitFieldActionFactory() { + return bitFieldActionFactory; + } + + public static Model getInstance() { + return indexerPrivilegeModel; + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/048c9d67/sentry-core/sentry-core-model-search/src/main/java/org/apache/sentry/core/model/search/SearchPrivilegeModel.java ---------------------------------------------------------------------- diff --git a/sentry-core/sentry-core-model-search/src/main/java/org/apache/sentry/core/model/search/SearchPrivilegeModel.java b/sentry-core/sentry-core-model-search/src/main/java/org/apache/sentry/core/model/search/SearchPrivilegeModel.java new file mode 100644 index 0000000..8231f12 --- /dev/null +++ b/sentry-core/sentry-core-model-search/src/main/java/org/apache/sentry/core/model/search/SearchPrivilegeModel.java @@ -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. + */ +package org.apache.sentry.core.model.search; + +import org.apache.sentry.core.common.BitFieldActionFactory; +import org.apache.sentry.core.common.ImplyMethodType; +import org.apache.sentry.core.common.Model; + +import java.util.HashMap; +import java.util.Map; + +public class SearchPrivilegeModel implements Model { + + private Map<String, ImplyMethodType> implyMethodMap; + private BitFieldActionFactory bitFieldActionFactory; + private static SearchPrivilegeModel searchPrivilegeModel = new SearchPrivilegeModel(); + + private SearchPrivilegeModel() { + implyMethodMap = new HashMap<String, ImplyMethodType>(); + bitFieldActionFactory = new SearchActionFactory(); + + implyMethodMap.put(SearchModelAuthorizable.AuthorizableType.Collection.name().toLowerCase(), ImplyMethodType.STRING); + implyMethodMap.put(SearchModelAuthorizable.AuthorizableType.Field.name().toLowerCase(), ImplyMethodType.STRING); + } + + @Override + public Map<String, ImplyMethodType> getImplyMethodMap() { + return implyMethodMap; + } + + @Override + public BitFieldActionFactory getBitFieldActionFactory() { + return bitFieldActionFactory; + } + + public static Model getInstance() { + return searchPrivilegeModel; + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/048c9d67/sentry-core/sentry-core-model-sqoop/src/main/java/org/apache/sentry/core/model/sqoop/SqoopPrivilegeModel.java ---------------------------------------------------------------------- diff --git a/sentry-core/sentry-core-model-sqoop/src/main/java/org/apache/sentry/core/model/sqoop/SqoopPrivilegeModel.java b/sentry-core/sentry-core-model-sqoop/src/main/java/org/apache/sentry/core/model/sqoop/SqoopPrivilegeModel.java new file mode 100644 index 0000000..8c4307c --- /dev/null +++ b/sentry-core/sentry-core-model-sqoop/src/main/java/org/apache/sentry/core/model/sqoop/SqoopPrivilegeModel.java @@ -0,0 +1,56 @@ +/* + * 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.core.model.sqoop; + +import org.apache.sentry.core.common.BitFieldActionFactory; +import org.apache.sentry.core.common.ImplyMethodType; +import org.apache.sentry.core.common.Model; + +import java.util.HashMap; +import java.util.Map; + +public class SqoopPrivilegeModel implements Model { + + private Map<String, ImplyMethodType> implyMethodMap; + private BitFieldActionFactory bitFieldActionFactory; + private static SqoopPrivilegeModel sqoopPrivilegeModel = new SqoopPrivilegeModel(); + + private SqoopPrivilegeModel() { + implyMethodMap = new HashMap<String, ImplyMethodType>(); + bitFieldActionFactory = new SqoopActionFactory(); + + implyMethodMap.put(SqoopAuthorizable.AuthorizableType.SERVER.name().toLowerCase(), ImplyMethodType.STRING); + implyMethodMap.put(SqoopAuthorizable.AuthorizableType.CONNECTOR.name().toLowerCase(), ImplyMethodType.STRING); + implyMethodMap.put(SqoopAuthorizable.AuthorizableType.LINK.name().toLowerCase(), ImplyMethodType.STRING); + implyMethodMap.put(SqoopAuthorizable.AuthorizableType.JOB.name().toLowerCase(), ImplyMethodType.STRING); + } + + @Override + public Map<String, ImplyMethodType> getImplyMethodMap() { + return implyMethodMap; + } + + @Override + public BitFieldActionFactory getBitFieldActionFactory() { + return bitFieldActionFactory; + } + + public static Model getInstance() { + return sqoopPrivilegeModel; + } + +} \ No newline at end of file