You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by na...@apache.org on 2011/01/12 07:58:10 UTC
svn commit: r1057999 [14/22] - in /hive/trunk: ./
common/src/java/org/apache/hadoop/hive/conf/ conf/ metastore/if/
metastore/src/gen/thrift/gen-cpp/
metastore/src/gen/thrift/gen-javabean/org/apache/hadoop/hive/metastore/api/
metastore/src/gen/thrift/ge...
Added: hive/trunk/metastore/src/model/org/apache/hadoop/hive/metastore/model/MGlobalPrivilege.java
URL: http://svn.apache.org/viewvc/hive/trunk/metastore/src/model/org/apache/hadoop/hive/metastore/model/MGlobalPrivilege.java?rev=1057999&view=auto
==============================================================================
--- hive/trunk/metastore/src/model/org/apache/hadoop/hive/metastore/model/MGlobalPrivilege.java (added)
+++ hive/trunk/metastore/src/model/org/apache/hadoop/hive/metastore/model/MGlobalPrivilege.java Wed Jan 12 06:58:04 2011
@@ -0,0 +1,120 @@
+/**
+ * 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.hadoop.hive.metastore.model;
+
+/**
+ * User global level privileges
+ */
+public class MGlobalPrivilege {
+
+ //principal name, can be a user, group, or role
+ private String principalName;
+
+ private String principalType;
+
+ private String privilege;
+
+ private int createTime;
+
+ private String grantor;
+
+ private String grantorType;
+
+ private boolean grantOption;
+
+ public MGlobalPrivilege() {
+ super();
+ }
+
+ public MGlobalPrivilege(String userName, String principalType,
+ String dbPrivilege, int createTime, String grantor, String grantorType,
+ boolean grantOption) {
+ super();
+ this.principalName = userName;
+ this.principalType = principalType;
+ this.privilege = dbPrivilege;
+ this.createTime = createTime;
+ this.grantor = grantor;
+ this.grantorType = grantorType;
+ this.grantOption = grantOption;
+ }
+
+ /**
+ * @return a set of global privileges granted to this user
+ */
+ public String getPrivilege() {
+ return privilege;
+ }
+
+ /**
+ * @param dbPrivileges set of global privileges to user
+ */
+ public void setPrivilege(String dbPrivilege) {
+ this.privilege = dbPrivilege;
+ }
+
+ public String getPrincipalName() {
+ return principalName;
+ }
+
+ public void setPrincipalName(String principalName) {
+ this.principalName = principalName;
+ }
+
+ public int getCreateTime() {
+ return createTime;
+ }
+
+ public void setCreateTime(int createTime) {
+ this.createTime = createTime;
+ }
+
+ public String getGrantor() {
+ return grantor;
+ }
+
+ public void setGrantor(String grantor) {
+ this.grantor = grantor;
+ }
+
+ public boolean getGrantOption() {
+ return grantOption;
+ }
+
+ public void setGrantOption(boolean grantOption) {
+ this.grantOption = grantOption;
+ }
+
+ public String getPrincipalType() {
+ return principalType;
+ }
+
+ public void setPrincipalType(String principalType) {
+ this.principalType = principalType;
+ }
+
+ public String getGrantorType() {
+ return grantorType;
+ }
+
+ public void setGrantorType(String grantorType) {
+ this.grantorType = grantorType;
+ }
+
+}
Added: hive/trunk/metastore/src/model/org/apache/hadoop/hive/metastore/model/MPartitionColumnPrivilege.java
URL: http://svn.apache.org/viewvc/hive/trunk/metastore/src/model/org/apache/hadoop/hive/metastore/model/MPartitionColumnPrivilege.java?rev=1057999&view=auto
==============================================================================
--- hive/trunk/metastore/src/model/org/apache/hadoop/hive/metastore/model/MPartitionColumnPrivilege.java (added)
+++ hive/trunk/metastore/src/model/org/apache/hadoop/hive/metastore/model/MPartitionColumnPrivilege.java Wed Jan 12 06:58:04 2011
@@ -0,0 +1,160 @@
+/**
+ * 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.hadoop.hive.metastore.model;
+
+
+public class MPartitionColumnPrivilege {
+
+ private String principalName;
+
+ private String principalType;
+
+ private MPartition partition;
+
+ private String columnName;
+
+ private String privilege;
+
+ private int createTime;
+
+ private String grantor;
+
+ private String grantorType;
+
+ private boolean grantOption;
+
+ public MPartitionColumnPrivilege() {
+ }
+
+ /**
+ * @param principalName
+ * @param isRole
+ * @param isGroup
+ * @param partition
+ * @param columnName
+ * @param privileges
+ * @param createTime
+ * @param grantor
+ */
+ public MPartitionColumnPrivilege(String principalName, String principalType,
+ MPartition partition, String columnName, String privileges, int createTime,
+ String grantor, String grantorType, boolean grantOption) {
+ super();
+ this.principalName = principalName;
+ this.principalType = principalType;
+ this.partition = partition;
+ this.columnName = columnName;
+ this.privilege = privileges;
+ this.createTime = createTime;
+ this.grantor = grantor;
+ this.grantorType = grantorType;
+ this.grantOption = grantOption;
+ }
+
+ /**
+ * @return column name
+ */
+ public String getColumnName() {
+ return columnName;
+ }
+
+ /**
+ * @param columnName column name
+ */
+ public void setColumnName(String columnName) {
+ this.columnName = columnName;
+ }
+
+ /**
+ * @return a set of privileges this user/role/group has
+ */
+ public String getPrivilege() {
+ return privilege;
+ }
+
+ /**
+ * @param dbPrivileges a set of privileges this user/role/group has
+ */
+ public void setPrivilege(String dbPrivileges) {
+ this.privilege = dbPrivileges;
+ }
+
+ /**
+ * @return create time
+ */
+ public int getCreateTime() {
+ return createTime;
+ }
+
+ /**
+ * @param createTime create time
+ */
+ public void setCreateTime(int createTime) {
+ this.createTime = createTime;
+ }
+
+ public String getPrincipalName() {
+ return principalName;
+ }
+
+ public void setPrincipalName(String principalName) {
+ this.principalName = principalName;
+ }
+
+ public MPartition getPartition() {
+ return partition;
+ }
+
+ public void setPartition(MPartition partition) {
+ this.partition = partition;
+ }
+
+ public String getGrantor() {
+ return grantor;
+ }
+
+ public void setGrantor(String grantor) {
+ this.grantor = grantor;
+ }
+
+ public String getGrantorType() {
+ return grantorType;
+ }
+
+ public void setGrantorType(String grantorType) {
+ this.grantorType = grantorType;
+ }
+
+ public boolean getGrantOption() {
+ return grantOption;
+ }
+
+ public void setGrantOption(boolean grantOption) {
+ this.grantOption = grantOption;
+ }
+
+ public String getPrincipalType() {
+ return principalType;
+ }
+
+ public void setPrincipalType(String principalType) {
+ this.principalType = principalType;
+ }
+
+}
Added: hive/trunk/metastore/src/model/org/apache/hadoop/hive/metastore/model/MPartitionPrivilege.java
URL: http://svn.apache.org/viewvc/hive/trunk/metastore/src/model/org/apache/hadoop/hive/metastore/model/MPartitionPrivilege.java?rev=1057999&view=auto
==============================================================================
--- hive/trunk/metastore/src/model/org/apache/hadoop/hive/metastore/model/MPartitionPrivilege.java (added)
+++ hive/trunk/metastore/src/model/org/apache/hadoop/hive/metastore/model/MPartitionPrivilege.java Wed Jan 12 06:58:04 2011
@@ -0,0 +1,139 @@
+/**
+ * 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.hadoop.hive.metastore.model;
+
+public class MPartitionPrivilege {
+
+ private String principalName;
+
+ private String principalType;
+
+ private MPartition partition;
+
+ private String privilege;
+
+ private int createTime;
+
+ private String grantor;
+
+ private String grantorType;
+
+ private boolean grantOption;
+
+ public MPartitionPrivilege() {
+ }
+
+ public MPartitionPrivilege(String principalName, String principalType,
+ MPartition partition, String privilege, int createTime,
+ String grantor, String grantorType, boolean grantOption) {
+ super();
+ this.principalName = principalName;
+ this.principalType = principalType;
+ this.partition = partition;
+ this.privilege = privilege;
+ this.createTime = createTime;
+ this.grantor = grantor;
+ this.grantorType = grantorType;
+ this.grantOption = grantOption;
+ }
+
+ public String getPrincipalName() {
+ return principalName;
+ }
+
+ public void setPrincipalName(String principalName) {
+ this.principalName = principalName;
+ }
+
+
+ /**
+ * @return a set of privileges this user/role/group has
+ */
+ public String getPrivilege() {
+ return privilege;
+ }
+
+ /**
+ * @param dbPrivilege a set of privileges this user/role/group has
+ */
+ public void setPrivilege(String dbPrivilege) {
+ this.privilege = dbPrivilege;
+ }
+
+ /**
+ * @return create time
+ */
+ public int getCreateTime() {
+ return createTime;
+ }
+
+ /**
+ * @param createTime create time
+ */
+ public void setCreateTime(int createTime) {
+ this.createTime = createTime;
+ }
+
+ /**
+ * @return
+ */
+ public String getGrantor() {
+ return grantor;
+ }
+
+ /**
+ * @param grantor
+ */
+ public void setGrantor(String grantor) {
+ this.grantor = grantor;
+ }
+
+ public String getPrincipalType() {
+ return principalType;
+ }
+
+ public void setPrincipalType(String principalType) {
+ this.principalType = principalType;
+ }
+
+ public MPartition getPartition() {
+ return partition;
+ }
+
+ public void setPartition(MPartition partition) {
+ this.partition = partition;
+ }
+
+ public boolean getGrantOption() {
+ return grantOption;
+ }
+
+ public void setGrantOption(boolean grantOption) {
+ this.grantOption = grantOption;
+ }
+
+ public String getGrantorType() {
+ return grantorType;
+ }
+
+ public void setGrantorType(String grantorType) {
+ this.grantorType = grantorType;
+ }
+
+}
Added: hive/trunk/metastore/src/model/org/apache/hadoop/hive/metastore/model/MRole.java
URL: http://svn.apache.org/viewvc/hive/trunk/metastore/src/model/org/apache/hadoop/hive/metastore/model/MRole.java?rev=1057999&view=auto
==============================================================================
--- hive/trunk/metastore/src/model/org/apache/hadoop/hive/metastore/model/MRole.java (added)
+++ hive/trunk/metastore/src/model/org/apache/hadoop/hive/metastore/model/MRole.java Wed Jan 12 06:58:04 2011
@@ -0,0 +1,80 @@
+/**
+ * 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.hadoop.hive.metastore.model;
+
+public class MRole {
+
+ private String roleName;
+
+ private int createTime;
+
+ private String ownerName;
+
+ public MRole() {
+ }
+
+ public MRole(String roleName, int createTime, String ownerName) {
+ super();
+ this.roleName = roleName;
+ this.createTime = createTime;
+ this.ownerName = ownerName;
+ }
+
+ /**
+ * @return role name
+ */
+ public String getRoleName() {
+ return roleName;
+ }
+
+ /**
+ * @param roleName
+ */
+ public void setRoleName(String roleName) {
+ this.roleName = roleName;
+ }
+
+ /**
+ * @return create time
+ */
+ public int getCreateTime() {
+ return createTime;
+ }
+
+ /**
+ * @param createTime
+ * role create time
+ */
+ public void setCreateTime(int createTime) {
+ this.createTime = createTime;
+ }
+
+ /**
+ * @return the principal name who created this role
+ */
+ public String getOwnerName() {
+ return ownerName;
+ }
+
+ public void setOwnerName(String ownerName) {
+ this.ownerName = ownerName;
+ }
+
+}
+
Added: hive/trunk/metastore/src/model/org/apache/hadoop/hive/metastore/model/MRoleMap.java
URL: http://svn.apache.org/viewvc/hive/trunk/metastore/src/model/org/apache/hadoop/hive/metastore/model/MRoleMap.java?rev=1057999&view=auto
==============================================================================
--- hive/trunk/metastore/src/model/org/apache/hadoop/hive/metastore/model/MRoleMap.java (added)
+++ hive/trunk/metastore/src/model/org/apache/hadoop/hive/metastore/model/MRoleMap.java Wed Jan 12 06:58:04 2011
@@ -0,0 +1,120 @@
+/**
+ * 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.hadoop.hive.metastore.model;
+
+public class MRoleMap {
+
+ private String principalName;
+
+ private String principalType;
+
+ private MRole role;
+
+ private int addTime;
+
+ private String grantor;
+
+ private String grantorType;
+
+ private boolean grantOption;
+
+ public MRoleMap() {
+ }
+
+ public MRoleMap(String principalName, String principalType, MRole role,
+ int addTime, String grantor, String grantorType, boolean grantOption) {
+ super();
+ this.principalName = principalName;
+ this.principalType = principalType;
+ this.role = role;
+ this.addTime = addTime;
+ this.grantor = grantor;
+ this.grantorType = grantorType;
+ this.grantOption = grantOption;
+ }
+
+ /**
+ * @return principal name
+ */
+ public String getPrincipalName() {
+ return principalName;
+ }
+
+ /**
+ * @param userName principal name
+ */
+ public void setPrincipalName(String userName) {
+ this.principalName = userName;
+ }
+
+ public String getPrincipalType() {
+ return principalType;
+ }
+
+ public void setPrincipalType(String principalType) {
+ this.principalType = principalType;
+ }
+
+ /**
+ * @return add time
+ */
+ public int getAddTime() {
+ return addTime;
+ }
+
+ /**
+ * @param addTime
+ */
+ public void setAddTime(int addTime) {
+ this.addTime = addTime;
+ }
+
+ public MRole getRole() {
+ return role;
+ }
+
+ public void setRole(MRole role) {
+ this.role = role;
+ }
+
+ public boolean getGrantOption() {
+ return grantOption;
+ }
+
+ public void setGrantOption(boolean grantOption) {
+ this.grantOption = grantOption;
+ }
+
+ public String getGrantor() {
+ return grantor;
+ }
+
+ public void setGrantor(String grantor) {
+ this.grantor = grantor;
+ }
+
+ public String getGrantorType() {
+ return grantorType;
+ }
+
+ public void setGrantorType(String grantorType) {
+ this.grantorType = grantorType;
+ }
+
+}
Added: hive/trunk/metastore/src/model/org/apache/hadoop/hive/metastore/model/MTableColumnPrivilege.java
URL: http://svn.apache.org/viewvc/hive/trunk/metastore/src/model/org/apache/hadoop/hive/metastore/model/MTableColumnPrivilege.java?rev=1057999&view=auto
==============================================================================
--- hive/trunk/metastore/src/model/org/apache/hadoop/hive/metastore/model/MTableColumnPrivilege.java (added)
+++ hive/trunk/metastore/src/model/org/apache/hadoop/hive/metastore/model/MTableColumnPrivilege.java Wed Jan 12 06:58:04 2011
@@ -0,0 +1,159 @@
+/**
+ * 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.hadoop.hive.metastore.model;
+
+public class MTableColumnPrivilege {
+
+ private String principalName;
+
+ private String principalType;
+
+ private MTable table;
+
+ private String columnName;
+
+ private String privilege;
+
+ private int createTime;
+
+ private String grantor;
+
+ private String grantorType;
+
+ private boolean grantOption;
+
+ public MTableColumnPrivilege() {
+ }
+
+ /**
+ * @param principalName
+ * @param isRole
+ * @param isGroup
+ * @param table
+ * @param columnName
+ * @param privileges
+ * @param createTime
+ * @param grantor
+ */
+ public MTableColumnPrivilege(String principalName, String principalType,
+ MTable table, String columnName, String privileges, int createTime,
+ String grantor, String grantorType, boolean grantOption) {
+ super();
+ this.principalName = principalName;
+ this.principalType = principalType;
+ this.table = table;
+ this.columnName = columnName;
+ this.privilege = privileges;
+ this.createTime = createTime;
+ this.grantor = grantor;
+ this.grantorType = grantorType;
+ this.grantOption = grantOption;
+ }
+
+ /**
+ * @return column name
+ */
+ public String getColumnName() {
+ return columnName;
+ }
+
+ /**
+ * @param columnName column name
+ */
+ public void setColumnName(String columnName) {
+ this.columnName = columnName;
+ }
+
+ /**
+ * @return a set of privileges this user/role/group has
+ */
+ public String getPrivilege() {
+ return privilege;
+ }
+
+ /**
+ * @param dbPrivileges a set of privileges this user/role/group has
+ */
+ public void setPrivilege(String dbPrivileges) {
+ this.privilege = dbPrivileges;
+ }
+
+ /**
+ * @return create time
+ */
+ public int getCreateTime() {
+ return createTime;
+ }
+
+ /**
+ * @param createTime create time
+ */
+ public void setCreateTime(int createTime) {
+ this.createTime = createTime;
+ }
+
+ public String getPrincipalName() {
+ return principalName;
+ }
+
+ public void setPrincipalName(String principalName) {
+ this.principalName = principalName;
+ }
+
+ public MTable getTable() {
+ return table;
+ }
+
+ public void setTable(MTable table) {
+ this.table = table;
+ }
+
+ public String getGrantor() {
+ return grantor;
+ }
+
+ public void setGrantor(String grantor) {
+ this.grantor = grantor;
+ }
+
+ public String getGrantorType() {
+ return grantorType;
+ }
+
+ public void setGrantorType(String grantorType) {
+ this.grantorType = grantorType;
+ }
+
+ public boolean getGrantOption() {
+ return grantOption;
+ }
+
+ public void setGrantOption(boolean grantOption) {
+ this.grantOption = grantOption;
+ }
+
+ public String getPrincipalType() {
+ return principalType;
+ }
+
+ public void setPrincipalType(String principalType) {
+ this.principalType = principalType;
+ }
+
+}
Added: hive/trunk/metastore/src/model/org/apache/hadoop/hive/metastore/model/MTablePrivilege.java
URL: http://svn.apache.org/viewvc/hive/trunk/metastore/src/model/org/apache/hadoop/hive/metastore/model/MTablePrivilege.java?rev=1057999&view=auto
==============================================================================
--- hive/trunk/metastore/src/model/org/apache/hadoop/hive/metastore/model/MTablePrivilege.java (added)
+++ hive/trunk/metastore/src/model/org/apache/hadoop/hive/metastore/model/MTablePrivilege.java Wed Jan 12 06:58:04 2011
@@ -0,0 +1,139 @@
+/**
+ * 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.hadoop.hive.metastore.model;
+
+public class MTablePrivilege {
+
+ private String principalName;
+
+ private String principalType;
+
+ private MTable table;
+
+ private String privilege;
+
+ private int createTime;
+
+ private String grantor;
+
+ private String grantorType;
+
+ private boolean grantOption;
+
+ public MTablePrivilege() {
+ }
+
+ public MTablePrivilege(String principalName, String principalType,
+ MTable table, String privilege, int createTime,
+ String grantor, String grantorType, boolean grantOption) {
+ super();
+ this.principalName = principalName;
+ this.principalType = principalType;
+ this.table = table;
+ this.privilege = privilege;
+ this.createTime = createTime;
+ this.grantor = grantor;
+ this.grantorType = grantorType;
+ this.grantOption = grantOption;
+ }
+
+ public String getPrincipalName() {
+ return principalName;
+ }
+
+ public void setPrincipalName(String principalName) {
+ this.principalName = principalName;
+ }
+
+
+ /**
+ * @return a set of privileges this user/role/group has
+ */
+ public String getPrivilege() {
+ return privilege;
+ }
+
+ /**
+ * @param dbPrivilege a set of privileges this user/role/group has
+ */
+ public void setPrivilege(String dbPrivilege) {
+ this.privilege = dbPrivilege;
+ }
+
+ /**
+ * @return create time
+ */
+ public int getCreateTime() {
+ return createTime;
+ }
+
+ /**
+ * @param createTime create time
+ */
+ public void setCreateTime(int createTime) {
+ this.createTime = createTime;
+ }
+
+ /**
+ * @return
+ */
+ public String getGrantor() {
+ return grantor;
+ }
+
+ /**
+ * @param grantor
+ */
+ public void setGrantor(String grantor) {
+ this.grantor = grantor;
+ }
+
+ public String getPrincipalType() {
+ return principalType;
+ }
+
+ public void setPrincipalType(String principalType) {
+ this.principalType = principalType;
+ }
+
+ public MTable getTable() {
+ return table;
+ }
+
+ public void setTable(MTable table) {
+ this.table = table;
+ }
+
+ public boolean getGrantOption() {
+ return grantOption;
+ }
+
+ public void setGrantOption(boolean grantOption) {
+ this.grantOption = grantOption;
+ }
+
+ public String getGrantorType() {
+ return grantorType;
+ }
+
+ public void setGrantorType(String grantorType) {
+ this.grantorType = grantorType;
+ }
+
+}
Modified: hive/trunk/metastore/src/model/package.jdo
URL: http://svn.apache.org/viewvc/hive/trunk/metastore/src/model/package.jdo?rev=1057999&r1=1057998&r2=1057999&view=diff
==============================================================================
--- hive/trunk/metastore/src/model/package.jdo (original)
+++ hive/trunk/metastore/src/model/package.jdo Wed Jan 12 06:58:04 2011
@@ -357,5 +357,313 @@
</value>
</field>
</class>
+
+ <class name="MRole" table="ROLES" identity-type="datastore" detachable="true">
+
+ <index name="RoleEntityINDEX" unique="true">
+ <column name="ROLE_NAME"/>
+ </index>
+
+ <datastore-identity>
+ <column name="ROLE_ID"/>
+ </datastore-identity>
+
+ <field name="roleName">
+ <column name="ROLE_NAME" length="128" jdbc-type="VARCHAR"/>
+ </field>
+ <field name="createTime">
+ <column name="CREATE_TIME" jdbc-type="integer"/>
+ </field>
+ <field name="ownerName">
+ <column name="OWNER_NAME" length="128" jdbc-type="VARCHAR"/>
+ </field>
+
+ </class>
+
+ <class name="MRoleMap" table="ROLE_MAP" identity-type="datastore" detachable="true">
+ <index name="UserRoleMapINDEX" unique="true">
+ <column name="PRINCIPAL_NAME"/>
+ <column name="ROLE_ID"/>
+ <column name="GRANTOR"/>
+ <column name="GRANTOR_TYPE"/>
+ </index>
+
+ <datastore-identity>
+ <column name="ROLE_GRANT_ID"/>
+ </datastore-identity>
+
+ <field name="role">
+ <column name="ROLE_ID" />
+ </field>
+ <field name="principalName">
+ <column name="PRINCIPAL_NAME" length="128" jdbc-type="VARCHAR"/>
+ </field>
+ <field name="principalType">
+ <column name="PRINCIPAL_TYPE" length="128" jdbc-type="VARCHAR"/>
+ </field>
+ <field name="addTime">
+ <column name="ADD_TIME" jdbc-type="integer"/>
+ </field>
+ <field name="grantor">
+ <column name="GRANTOR" length="128" jdbc-type="VARCHAR"/>
+ </field>
+ <field name="grantorType">
+ <column name="GRANTOR_TYPE" length="128" jdbc-type="VARCHAR"/>
+ </field>
+ <field name="grantOption">
+ <column name="GRANT_OPTION" jdbc-type="SMALLINT"/>
+ </field>
+ </class>
+
+ <class name="MGlobalPrivilege" table="GLOBAL_PRIVS" identity-type="datastore" detachable="true">
+
+ <index name="GlobalPrivilegeIndex" unique="true">
+ <column name="PRINCIPAL_NAME"/>
+ <column name="PRINCIPAL_TYPE"/>
+ <column name="USER_PRIV"/>
+ <column name="GRANTOR"/>
+ <column name="GRANTOR_TYPE"/>
+ </index>
+
+ <datastore-identity>
+ <column name="USER_GRANT_ID"/>
+ </datastore-identity>
+
+ <field name="principalName">
+ <column name="PRINCIPAL_NAME" length="128" jdbc-type="VARCHAR"/>
+ </field>
+ <field name="principalType">
+ <column name="PRINCIPAL_TYPE" length="128" jdbc-type="VARCHAR"/>
+ </field>
+ <field name="privilege">
+ <column name="USER_PRIV" length="128" jdbc-type="VARCHAR"/>
+ </field>
+ <field name="createTime">
+ <column name="CREATE_TIME" jdbc-type="integer"/>
+ </field>
+ <field name="grantor">
+ <column name="GRANTOR" length="128" jdbc-type="VARCHAR"/>
+ </field>
+ <field name="grantorType">
+ <column name="GRANTOR_TYPE" length="128" jdbc-type="VARCHAR"/>
+ </field>
+ <field name="grantOption">
+ <column name="GRANT_OPTION" jdbc-type="SMALLINT"/>
+ </field>
+ </class>
+
+ <class name="MDBPrivilege" table="DB_PRIVS" identity-type="datastore" detachable="true">
+
+ <index name="DBPrivilegeIndex" unique="true">
+ <column name="DB_ID"/>
+ <column name="PRINCIPAL_NAME"/>
+ <column name="PRINCIPAL_TYPE"/>
+ <column name="DB_PRIV"/>
+ <column name="GRANTOR"/>
+ <column name="GRANTOR_TYPE"/>
+ </index>
+
+ <datastore-identity>
+ <column name="DB_GRANT_ID"/>
+ </datastore-identity>
+
+ <field name="principalName">
+ <column name="PRINCIPAL_NAME" length="128" jdbc-type="VARCHAR"/>
+ </field>
+ <field name="principalType">
+ <column name="PRINCIPAL_TYPE" length="128" jdbc-type="VARCHAR"/>
+ </field>
+ <field name="database">
+ <column name="DB_ID" />
+ </field>
+ <field name="privilege">
+ <column name="DB_PRIV" length="128" jdbc-type="VARCHAR"/>
+ </field>
+ <field name="createTime">
+ <column name="CREATE_TIME" jdbc-type="integer"/>
+ </field>
+ <field name="grantor">
+ <column name="GRANTOR" length="128" jdbc-type="VARCHAR"/>
+ </field>
+ <field name="grantorType">
+ <column name="GRANTOR_TYPE" length="128" jdbc-type="VARCHAR"/>
+ </field>
+ <field name="grantOption">
+ <column name="GRANT_OPTION" jdbc-type="SMALLINT"/>
+ </field>
+ </class>
+
+ <class name="MTablePrivilege" table="TBL_PRIVS" identity-type="datastore" detachable="true">
+
+ <index name="TablePrivilegeIndex" unique="false">
+ <column name="TBL_ID"/>
+ <column name="PRINCIPAL_NAME"/>
+ <column name="PRINCIPAL_TYPE"/>
+ <column name="TBL_PRIV"/>
+ <column name="GRANTOR"/>
+ <column name="GRANTOR_TYPE"/>
+ </index>
+
+ <datastore-identity>
+ <column name="TBL_GRANT_ID"/>
+ </datastore-identity>
+
+ <field name="principalName">
+ <column name="PRINCIPAL_NAME" length="128" jdbc-type="VARCHAR"/>
+ </field>
+ <field name="principalType">
+ <column name="PRINCIPAL_TYPE" length="128" jdbc-type="VARCHAR"/>
+ </field>
+ <field name="table">
+ <column name="TBL_ID"/>
+ </field>
+ <field name="privilege">
+ <column name="TBL_PRIV" length="128" jdbc-type="VARCHAR"/>
+ </field>
+ <field name="createTime">
+ <column name="CREATE_TIME" jdbc-type="integer"/>
+ </field>
+ <field name="grantor">
+ <column name="GRANTOR" length="128" jdbc-type="VARCHAR"/>
+ </field>
+ <field name="grantorType">
+ <column name="GRANTOR_TYPE" length="128" jdbc-type="VARCHAR"/>
+ </field>
+ <field name="grantOption">
+ <column name="GRANT_OPTION" jdbc-type="SMALLINT"/>
+ </field>
+ </class>
+
+ <class name="MPartitionPrivilege" table="PART_PRIVS" identity-type="datastore" detachable="true">
+
+ <index name="PartPrivilegeIndex" unique="false">
+ <column name="PART_ID"/>
+ <column name="PRINCIPAL_NAME"/>
+ <column name="PRINCIPAL_TYPE"/>
+ <column name="PART_PRIV"/>
+ <column name="GRANTOR"/>
+ <column name="GRANTOR_TYPE"/>
+ </index>
+
+ <datastore-identity>
+ <column name="PART_GRANT_ID"/>
+ </datastore-identity>
+
+ <field name="principalName">
+ <column name="PRINCIPAL_NAME" length="128" jdbc-type="VARCHAR"/>
+ </field>
+ <field name="principalType">
+ <column name="PRINCIPAL_TYPE" length="128" jdbc-type="VARCHAR"/>
+ </field>
+ <field name="partition">
+ <column name="PART_ID" />
+ </field>
+ <field name="privilege">
+ <column name="PART_PRIV" length="128" jdbc-type="VARCHAR"/>
+ </field>
+ <field name="createTime">
+ <column name="CREATE_TIME" jdbc-type="integer"/>
+ </field>
+ <field name="grantor">
+ <column name="GRANTOR" length="128" jdbc-type="VARCHAR"/>
+ </field>
+ <field name="grantorType">
+ <column name="GRANTOR_TYPE" length="128" jdbc-type="VARCHAR"/>
+ </field>
+ <field name="grantOption">
+ <column name="GRANT_OPTION" jdbc-type="SMALLINT"/>
+ </field>
+ </class>
+
+ <class name="MTableColumnPrivilege" table="TBL_COL_PRIVS" identity-type="datastore" detachable="true">
+
+ <index name="TableColumnPrivilegeIndex" unique="false">
+ <column name="TBL_ID"/>
+ <column name="COLUMN_NAME"/>
+ <column name="PRINCIPAL_NAME"/>
+ <column name="PRINCIPAL_TYPE"/>
+ <column name="TBL_COL_PRIV"/>
+ <column name="GRANTOR"/>
+ <column name="GRANTOR_TYPE"/>
+ </index>
+
+ <datastore-identity>
+ <column name="TBL_COLUMN_GRANT_ID"/>
+ </datastore-identity>
+
+ <field name="principalName">
+ <column name="PRINCIPAL_NAME" length="128" jdbc-type="VARCHAR"/>
+ </field>
+ <field name="principalType">
+ <column name="PRINCIPAL_TYPE" length="128" jdbc-type="VARCHAR"/>
+ </field>
+ <field name="table">
+ <column name="TBL_ID" />
+ </field>
+ <field name="columnName">
+ <column name="COLUMN_NAME" length="128" jdbc-type="VARCHAR"/>
+ </field>
+ <field name="privilege">
+ <column name="TBL_COL_PRIV" length="128" jdbc-type="VARCHAR"/>
+ </field>
+ <field name="createTime">
+ <column name="CREATE_TIME" jdbc-type="integer"/>
+ </field>
+ <field name="grantor">
+ <column name="GRANTOR" length="128" jdbc-type="VARCHAR"/>
+ </field>
+ <field name="grantorType">
+ <column name="GRANTOR_TYPE" length="128" jdbc-type="VARCHAR"/>
+ </field>
+ <field name="grantOption">
+ <column name="GRANT_OPTION" jdbc-type="SMALLINT"/>
+ </field>
+ </class>
+
+ <class name="MPartitionColumnPrivilege" table="PART_COL_PRIVS" identity-type="datastore" detachable="true">
+
+ <index name="PartitionColumnPrivilegeIndex" unique="false">
+ <column name="PART_ID"/>
+ <column name="COLUMN_NAME"/>
+ <column name="PRINCIPAL_NAME"/>
+ <column name="PRINCIPAL_TYPE"/>
+ <column name="PART_COL_PRIV"/>
+ <column name="GRANTOR"/>
+ <column name="GRANTOR_TYPE"/>
+ </index>
+
+ <datastore-identity>
+ <column name="PART_COLUMN_GRANT_ID"/>
+ </datastore-identity>
+
+ <field name="principalName">
+ <column name="PRINCIPAL_NAME" length="128" jdbc-type="VARCHAR"/>
+ </field>
+ <field name="principalType">
+ <column name="PRINCIPAL_TYPE" length="128" jdbc-type="VARCHAR"/>
+ </field>
+ <field name="partition">
+ <column name="PART_ID" />
+ </field>
+ <field name="columnName">
+ <column name="COLUMN_NAME" length="128" jdbc-type="VARCHAR"/>
+ </field>
+ <field name="privilege">
+ <column name="PART_COL_PRIV" length="128" jdbc-type="VARCHAR"/>
+ </field>
+ <field name="createTime">
+ <column name="CREATE_TIME" jdbc-type="integer"/>
+ </field>
+ <field name="grantor">
+ <column name="GRANTOR" length="128" jdbc-type="VARCHAR"/>
+ </field>
+ <field name="grantorType">
+ <column name="GRANTOR_TYPE" length="128" jdbc-type="VARCHAR"/>
+ </field>
+ <field name="grantOption">
+ <column name="GRANT_OPTION" jdbc-type="SMALLINT"/>
+ </field>
+ </class>
+
</package>
</jdo>
Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/Driver.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/Driver.java?rev=1057999&r1=1057998&r2=1057999&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/Driver.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/Driver.java Wed Jan 12 06:58:04 2011
@@ -49,6 +49,7 @@ import org.apache.hadoop.hive.ql.exec.Co
import org.apache.hadoop.hive.ql.exec.ExecDriver;
import org.apache.hadoop.hive.ql.exec.FetchTask;
import org.apache.hadoop.hive.ql.exec.Operator;
+import org.apache.hadoop.hive.ql.exec.TableScanOperator;
import org.apache.hadoop.hive.ql.exec.Task;
import org.apache.hadoop.hive.ql.exec.TaskFactory;
import org.apache.hadoop.hive.ql.exec.TaskResult;
@@ -69,22 +70,29 @@ import org.apache.hadoop.hive.ql.lockmgr
import org.apache.hadoop.hive.ql.lockmgr.HiveLockObject;
import org.apache.hadoop.hive.ql.lockmgr.HiveLockObject.HiveLockObjectData;
import org.apache.hadoop.hive.ql.lockmgr.LockException;
+import org.apache.hadoop.hive.ql.metadata.AuthorizationException;
import org.apache.hadoop.hive.ql.metadata.DummyPartition;
+import org.apache.hadoop.hive.ql.metadata.Hive;
import org.apache.hadoop.hive.ql.metadata.HiveException;
import org.apache.hadoop.hive.ql.metadata.HiveUtils;
import org.apache.hadoop.hive.ql.metadata.Partition;
import org.apache.hadoop.hive.ql.metadata.Table;
+import org.apache.hadoop.hive.ql.optimizer.ppr.PartitionPruner;
import org.apache.hadoop.hive.ql.parse.ASTNode;
import org.apache.hadoop.hive.ql.parse.AbstractSemanticAnalyzerHook;
import org.apache.hadoop.hive.ql.parse.BaseSemanticAnalyzer;
import org.apache.hadoop.hive.ql.parse.ErrorMsg;
import org.apache.hadoop.hive.ql.parse.HiveSemanticAnalyzerHookContext;
import org.apache.hadoop.hive.ql.parse.HiveSemanticAnalyzerHookContextImpl;
+import org.apache.hadoop.hive.ql.parse.ParseContext;
import org.apache.hadoop.hive.ql.parse.ParseDriver;
import org.apache.hadoop.hive.ql.parse.ParseException;
import org.apache.hadoop.hive.ql.parse.ParseUtils;
+import org.apache.hadoop.hive.ql.parse.PrunedPartitionList;
+import org.apache.hadoop.hive.ql.parse.SemanticAnalyzer;
import org.apache.hadoop.hive.ql.parse.SemanticAnalyzerFactory;
import org.apache.hadoop.hive.ql.parse.SemanticException;
+import org.apache.hadoop.hive.ql.plan.HiveOperation;
import org.apache.hadoop.hive.ql.parse.VariableSubstitution;
import org.apache.hadoop.hive.ql.plan.TableDesc;
import org.apache.hadoop.hive.ql.processors.CommandProcessor;
@@ -375,8 +383,20 @@ public class Driver implements CommandPr
if (plan.getFetchTask() != null) {
plan.getFetchTask().initialize(conf, plan, null);
}
+
+ //do the authorization check
+ if (HiveConf.getBoolVar(conf,
+ HiveConf.ConfVars.HIVE_AUTHORIZATION_ENABLED)) {
+ try {
+ doAuthorization(sem);
+ } catch (AuthorizationException authExp) {
+ console.printError("Authorization failed:" + authExp.getMessage()
+ + ". Use show grant to get more details.");
+ return 403;
+ }
+ }
- return (0);
+ return 0;
} catch (SemanticException e) {
errorMessage = "FAILED: Error in semantic analysis: " + e.getMessage();
SQLState = ErrorMsg.findSQLState(e.getMessage());
@@ -398,6 +418,126 @@ public class Driver implements CommandPr
}
}
+ private void doAuthorization(BaseSemanticAnalyzer sem)
+ throws HiveException, AuthorizationException {
+ HashSet<ReadEntity> inputs = sem.getInputs();
+ HashSet<WriteEntity> outputs = sem.getOutputs();
+ SessionState ss = SessionState.get();
+ HiveOperation op = ss.getHiveOperation();
+ Hive db = sem.getDb();
+ if (op != null) {
+ if (op.equals(HiveOperation.CREATETABLE_AS_SELECT)
+ || op.equals(HiveOperation.CREATETABLE)) {
+ ss.getAuthorizer().authorize(
+ db.getDatabase(db.getCurrentDatabase()), null,
+ HiveOperation.CREATETABLE_AS_SELECT.getOutputRequiredPrivileges());
+ }
+ if (outputs != null && outputs.size() > 0) {
+ for (WriteEntity write : outputs) {
+
+ if (write.getType() == WriteEntity.Type.PARTITION) {
+ Partition part = db.getPartition(write.getTable(), write
+ .getPartition().getSpec(), false);
+ if (part != null) {
+ ss.getAuthorizer().authorize(write.getPartition(), null,
+ op.getOutputRequiredPrivileges());
+ continue;
+ }
+ }
+
+ if (write.getTable() != null) {
+ ss.getAuthorizer().authorize(write.getTable(), null,
+ op.getOutputRequiredPrivileges());
+ }
+ }
+
+ }
+ }
+
+ if (inputs != null && inputs.size() > 0) {
+
+ Map<Table, List<String>> tab2Cols = new HashMap<Table, List<String>>();
+ Map<Partition, List<String>> part2Cols = new HashMap<Partition, List<String>>();
+
+ for (ReadEntity read : inputs) {
+ boolean part = read.getPartition() != null;
+ if (part) {
+ part2Cols.put(read.getPartition(), new ArrayList<String>());
+ } else {
+ tab2Cols.put(read.getTable(), new ArrayList<String>());
+ }
+ }
+
+ if (op.equals(HiveOperation.CREATETABLE_AS_SELECT)
+ || op.equals(HiveOperation.QUERY)) {
+ SemanticAnalyzer querySem = (SemanticAnalyzer) sem;
+ ParseContext parseCtx = querySem.getParseContext();
+ Map<TableScanOperator, Table> tsoTopMap = parseCtx.getTopToTable();
+
+ for (Map.Entry<String, Operator<? extends Serializable>> topOpMap : querySem
+ .getParseContext().getTopOps().entrySet()) {
+ Operator<? extends Serializable> topOp = topOpMap.getValue();
+ if (topOp instanceof TableScanOperator
+ && tsoTopMap.containsKey(topOp)) {
+ TableScanOperator tableScanOp = (TableScanOperator) topOp;
+ Table tbl = tsoTopMap.get(tableScanOp);
+ List<Integer> neededColumnIds = tableScanOp.getNeededColumnIDs();
+ List<FieldSchema> columns = tbl.getCols();
+ List<String> cols = new ArrayList<String>();
+ if (neededColumnIds != null && neededColumnIds.size() > 0) {
+ for (int i = 0; i < neededColumnIds.size(); i++) {
+ cols.add(columns.get(neededColumnIds.get(i)).getName());
+ }
+ } else {
+ for (int i = 0; i < columns.size(); i++) {
+ cols.add(columns.get(i).getName());
+ }
+ }
+ if (tbl.isPartitioned()) {
+ String alias_id = topOpMap.getKey();
+ PrunedPartitionList partsList = PartitionPruner.prune(parseCtx
+ .getTopToTable().get(topOp), parseCtx.getOpToPartPruner()
+ .get(topOp), parseCtx.getConf(), alias_id, parseCtx
+ .getPrunedPartitions());
+ Set<Partition> parts = new HashSet<Partition>();
+ parts.addAll(partsList.getConfirmedPartns());
+ parts.addAll(partsList.getUnknownPartns());
+ for (Partition part : parts) {
+ part2Cols.put(part, cols);
+ }
+ } else {
+ tab2Cols.put(tbl, cols);
+ }
+ }
+ }
+ }
+
+ for (ReadEntity read : inputs) {
+ if (read.getPartition() != null) {
+ List<String> cols = part2Cols.get(read.getPartition());
+ if (cols != null && cols.size() > 0) {
+ ss.getAuthorizer().authorize(read.getPartition().getTable(),
+ read.getPartition(), cols, op.getInputRequiredPrivileges(),
+ null);
+ } else {
+ ss.getAuthorizer().authorize(read.getPartition(),
+ op.getInputRequiredPrivileges(), null);
+ }
+ } else if (read.getTable() != null) {
+ List<String> cols = tab2Cols.get(read.getTable());
+ if (cols != null && cols.size() > 0) {
+ ss.getAuthorizer().authorize(read.getTable(), null, cols,
+ op.getInputRequiredPrivileges(), null);
+ } else {
+ ss.getAuthorizer().authorize(read.getTable(),
+ op.getInputRequiredPrivileges(), null);
+ }
+ }
+ }
+
+ }
+ }
+
/**
* @return The current query plan associated with this Driver, if any.
*/
@@ -755,8 +895,6 @@ public class Driver implements CommandPr
boolean noName = StringUtils.isEmpty(conf.getVar(HiveConf.ConfVars.HADOOPJOBNAME));
int maxlen = conf.getIntVar(HiveConf.ConfVars.HIVEJOBNAMELENGTH);
- int curJobNo = 0;
-
String queryId = plan.getQueryId();
String queryStr = plan.getQueryStr();
Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/DDLTask.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/DDLTask.java?rev=1057999&r1=1057998&r2=1057999&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/DDLTask.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/DDLTask.java Wed Jan 12 06:58:04 2011
@@ -58,11 +58,18 @@ import org.apache.hadoop.hive.metastore.
import org.apache.hadoop.hive.metastore.api.AlreadyExistsException;
import org.apache.hadoop.hive.metastore.api.Database;
import org.apache.hadoop.hive.metastore.api.FieldSchema;
+import org.apache.hadoop.hive.metastore.api.HiveObjectPrivilege;
+import org.apache.hadoop.hive.metastore.api.HiveObjectRef;
+import org.apache.hadoop.hive.metastore.api.HiveObjectType;
import org.apache.hadoop.hive.metastore.api.Index;
import org.apache.hadoop.hive.metastore.api.InvalidOperationException;
import org.apache.hadoop.hive.metastore.api.MetaException;
import org.apache.hadoop.hive.metastore.api.NoSuchObjectException;
import org.apache.hadoop.hive.metastore.api.Order;
+import org.apache.hadoop.hive.metastore.api.PrincipalType;
+import org.apache.hadoop.hive.metastore.api.PrivilegeBag;
+import org.apache.hadoop.hive.metastore.api.PrivilegeGrantInfo;
+import org.apache.hadoop.hive.metastore.api.Role;
import org.apache.hadoop.hive.ql.Context;
import org.apache.hadoop.hive.ql.DriverContext;
import org.apache.hadoop.hive.ql.QueryPlan;
@@ -100,10 +107,18 @@ import org.apache.hadoop.hive.ql.plan.De
import org.apache.hadoop.hive.ql.plan.DropDatabaseDesc;
import org.apache.hadoop.hive.ql.plan.DropIndexDesc;
import org.apache.hadoop.hive.ql.plan.DropTableDesc;
+import org.apache.hadoop.hive.ql.plan.GrantDesc;
+import org.apache.hadoop.hive.ql.plan.GrantRevokeRoleDDL;
import org.apache.hadoop.hive.ql.plan.LockTableDesc;
import org.apache.hadoop.hive.ql.plan.MsckDesc;
+import org.apache.hadoop.hive.ql.plan.PrincipalDesc;
+import org.apache.hadoop.hive.ql.plan.PrivilegeDesc;
+import org.apache.hadoop.hive.ql.plan.PrivilegeObjectDesc;
+import org.apache.hadoop.hive.ql.plan.RevokeDesc;
+import org.apache.hadoop.hive.ql.plan.RoleDDLDesc;
import org.apache.hadoop.hive.ql.plan.ShowDatabasesDesc;
import org.apache.hadoop.hive.ql.plan.ShowFunctionsDesc;
+import org.apache.hadoop.hive.ql.plan.ShowGrantDesc;
import org.apache.hadoop.hive.ql.plan.ShowIndexesDesc;
import org.apache.hadoop.hive.ql.plan.ShowLocksDesc;
import org.apache.hadoop.hive.ql.plan.ShowPartitionsDesc;
@@ -112,6 +127,8 @@ import org.apache.hadoop.hive.ql.plan.Sh
import org.apache.hadoop.hive.ql.plan.SwitchDatabaseDesc;
import org.apache.hadoop.hive.ql.plan.UnlockTableDesc;
import org.apache.hadoop.hive.ql.plan.api.StageType;
+import org.apache.hadoop.hive.ql.security.authorization.Privilege;
+import org.apache.hadoop.hive.ql.session.SessionState;
import org.apache.hadoop.hive.serde.Constants;
import org.apache.hadoop.hive.serde2.Deserializer;
import org.apache.hadoop.hive.serde2.MetadataTypedColumnsetSerDe;
@@ -122,10 +139,12 @@ import org.apache.hadoop.hive.serde2.dyn
import org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe;
import org.apache.hadoop.hive.shims.HadoopShims;
import org.apache.hadoop.hive.shims.ShimLoader;
+import org.apache.hadoop.util.StringUtils;
import org.apache.hadoop.util.ToolRunner;
+
/**
* DDLTask implementation.
- *
+ *
**/
public class DDLTask extends Task<DDLWork> implements Serializable {
private static final long serialVersionUID = 1L;
@@ -302,6 +321,33 @@ public class DDLTask extends Task<DDLWor
return showPartitions(db, showParts);
}
+ RoleDDLDesc roleDDLDesc = work.getRoleDDLDesc();
+ if (roleDDLDesc != null) {
+ return roleDDL(roleDDLDesc);
+ }
+
+ GrantDesc grantDesc = work.getGrantDesc();
+ if (grantDesc != null) {
+ return grantOrRevokePrivileges(grantDesc.getPrincipals(), grantDesc
+ .getPrivileges(), grantDesc.getPrivilegeSubjectDesc(), grantDesc.getGrantor(), grantDesc.getGrantorType(), grantDesc.isGrantOption(), true);
+ }
+
+ RevokeDesc revokeDesc = work.getRevokeDesc();
+ if (revokeDesc != null) {
+ return grantOrRevokePrivileges(revokeDesc.getPrincipals(), revokeDesc
+ .getPrivileges(), revokeDesc.getPrivilegeSubjectDesc(), null, null, false, false);
+ }
+
+ ShowGrantDesc showGrantDesc = work.getShowGrantDesc();
+ if (showGrantDesc != null) {
+ return showGrants(showGrantDesc);
+ }
+
+ GrantRevokeRoleDDL grantOrRevokeRoleDDL = work.getGrantRevokeRoleDDL();
+ if (grantOrRevokeRoleDDL != null) {
+ return grantOrRevokeRole(grantOrRevokeRoleDDL);
+ }
+
ShowIndexesDesc showIndexes = work.getShowIndexesDesc();
if (showIndexes != null) {
return showIndexes(db, showIndexes);
@@ -325,6 +371,363 @@ public class DDLTask extends Task<DDLWor
return 0;
}
+ private int grantOrRevokeRole(GrantRevokeRoleDDL grantOrRevokeRoleDDL)
+ throws HiveException {
+ try {
+ boolean grantRole = grantOrRevokeRoleDDL.getGrant();
+ List<PrincipalDesc> principals = grantOrRevokeRoleDDL.getPrincipalDesc();
+ List<String> roles = grantOrRevokeRoleDDL.getRoles();
+ for (PrincipalDesc principal : principals) {
+ String userName = principal.getName();
+ for (String roleName : roles) {
+ if (grantRole) {
+ db.grantRole(roleName, userName, principal.getType(),
+ grantOrRevokeRoleDDL.getGrantor(), grantOrRevokeRoleDDL
+ .getGrantorType(), grantOrRevokeRoleDDL.isGrantOption());
+ } else {
+ db.revokeRole(roleName, userName, principal.getType());
+ }
+ }
+ }
+ } catch (Exception e) {
+ throw new HiveException(e);
+ }
+ return 0;
+ }
+
+ private int showGrants(ShowGrantDesc showGrantDesc) throws HiveException {
+ try {
+ Path resFile = new Path(showGrantDesc.getResFile());
+ FileSystem fs = resFile.getFileSystem(conf);
+ DataOutput outStream = fs.create(resFile);
+ PrincipalDesc principalDesc = showGrantDesc.getPrincipalDesc();
+ PrivilegeObjectDesc hiveObjectDesc = showGrantDesc.getHiveObj();
+ String principalName = principalDesc.getName();
+ if (hiveObjectDesc == null) {
+ List<HiveObjectPrivilege> users = db.showPrivilegeGrant(
+ HiveObjectType.GLOBAL, principalName, principalDesc.getType(),
+ null, null, null, null);
+ if (users != null && users.size() > 0) {
+ boolean first = true;
+ for (HiveObjectPrivilege usr : users) {
+ if (!first) {
+ outStream.write(terminator);
+ } else {
+ first = false;
+ }
+
+ writeGrantInfo(outStream, principalDesc.getType(), principalName,
+ null, null, null, null, usr.getGrantInfo());
+
+ }
+ }
+ } else {
+ String obj = hiveObjectDesc.getObject();
+ boolean notFound = true;
+ String dbName = null;
+ String tableName = null;
+ Table tableObj = null;
+ Database dbObj = null;
+
+ if (hiveObjectDesc.getTable()) {
+ String[] dbTab = obj.split("\\.");
+ if (dbTab.length == 2) {
+ dbName = dbTab[0];
+ tableName = dbTab[1];
+ } else {
+ dbName = db.getCurrentDatabase();
+ tableName = obj;
+ }
+ dbObj = db.getDatabase(dbName);
+ tableObj = db.getTable(dbName, tableName);
+ notFound = (dbObj == null || tableObj == null);
+ } else {
+ dbName = hiveObjectDesc.getObject();
+ dbObj = db.getDatabase(dbName);
+ notFound = (dbObj == null);
+ }
+ if (notFound) {
+ throw new HiveException(obj + " can not be found");
+ }
+
+ String partName = null;
+ List<String> partValues = null;
+ if (hiveObjectDesc.getPartSpec() != null) {
+ partName = Warehouse
+ .makePartName(hiveObjectDesc.getPartSpec(), false);
+ partValues = Warehouse.getPartValuesFromPartName(partName);
+ }
+
+ if (!hiveObjectDesc.getTable()) {
+ // show database level privileges
+ List<HiveObjectPrivilege> dbs = db.showPrivilegeGrant(HiveObjectType.DATABASE, principalName,
+ principalDesc.getType(), dbName, null, null, null);
+ if (dbs != null && dbs.size() > 0) {
+ boolean first = true;
+ for (HiveObjectPrivilege db : dbs) {
+ if (!first) {
+ outStream.write(terminator);
+ } else {
+ first = false;
+ }
+
+ writeGrantInfo(outStream, principalDesc.getType(), principalName,
+ dbName, null, null, null, db.getGrantInfo());
+
+ }
+ }
+
+ } else {
+ if (showGrantDesc.getColumns() != null) {
+ // show column level privileges
+ for (String columnName : showGrantDesc.getColumns()) {
+ List<HiveObjectPrivilege> columnss = db.showPrivilegeGrant(
+ HiveObjectType.COLUMN, principalName,
+ principalDesc.getType(), dbName, tableName, partValues,
+ columnName);
+ if (columnss != null && columnss.size() > 0) {
+ boolean first = true;
+ for (HiveObjectPrivilege col : columnss) {
+ if (!first) {
+ outStream.write(terminator);
+ } else {
+ first = false;
+ }
+
+ writeGrantInfo(outStream, principalDesc.getType(),
+ principalName, dbName, tableName, partName, columnName,
+ col.getGrantInfo());
+ }
+ }
+ }
+ } else if (hiveObjectDesc.getPartSpec() != null) {
+ // show partition level privileges
+ List<HiveObjectPrivilege> parts = db.showPrivilegeGrant(
+ HiveObjectType.PARTITION, principalName, principalDesc
+ .getType(), dbName, tableName, partValues, null);
+ if (parts != null && parts.size() > 0) {
+ boolean first = true;
+ for (HiveObjectPrivilege part : parts) {
+ if (!first) {
+ outStream.write(terminator);
+ } else {
+ first = false;
+ }
+
+ writeGrantInfo(outStream, principalDesc.getType(),
+ principalName, dbName, tableName, partName, null, part.getGrantInfo());
+
+ }
+ }
+ } else {
+ // show table level privileges
+ List<HiveObjectPrivilege> tbls = db.showPrivilegeGrant(
+ HiveObjectType.TABLE, principalName, principalDesc.getType(),
+ dbName, tableName, null, null);
+ if (tbls != null && tbls.size() > 0) {
+ boolean first = true;
+ for (HiveObjectPrivilege tbl : tbls) {
+ if (!first) {
+ outStream.write(terminator);
+ } else {
+ first = false;
+ }
+
+ writeGrantInfo(outStream, principalDesc.getType(),
+ principalName, dbName, tableName, null, null, tbl.getGrantInfo());
+
+ }
+ }
+ }
+ }
+ }
+ ((FSDataOutputStream) outStream).close();
+ } catch (FileNotFoundException e) {
+ LOG.info("show table status: " + stringifyException(e));
+ return 1;
+ } catch (IOException e) {
+ LOG.info("show table status: " + stringifyException(e));
+ return 1;
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new HiveException(e);
+ }
+ return 0;
+ }
+
+ private int grantOrRevokePrivileges(List<PrincipalDesc> principals,
+ List<PrivilegeDesc> privileges, PrivilegeObjectDesc privSubjectDesc,
+ String grantor, PrincipalType grantorType, boolean grantOption, boolean isGrant) {
+ if (privileges == null || privileges.size() == 0) {
+ console.printError("No privilege found.");
+ return 1;
+ }
+
+ String dbName = null;
+ String tableName = null;
+ Table tableObj = null;
+ Database dbObj = null;
+
+ try {
+
+ if (privSubjectDesc != null) {
+ if (privSubjectDesc.getPartSpec() != null && isGrant) {
+ throw new HiveException("Grant does not support partition level.");
+ }
+ String obj = privSubjectDesc.getObject();
+ boolean notFound = true;
+ if (privSubjectDesc.getTable()) {
+ String[] dbTab = obj.split("\\.");
+ if (dbTab.length == 2) {
+ dbName = dbTab[0];
+ tableName = dbTab[1];
+ } else {
+ dbName = db.getCurrentDatabase();
+ tableName = obj;
+ }
+ dbObj = db.getDatabase(dbName);
+ tableObj = db.getTable(dbName, tableName);
+ notFound = (dbObj == null || tableObj == null);
+ } else {
+ dbName = privSubjectDesc.getObject();
+ dbObj = db.getDatabase(dbName);
+ notFound = (dbObj == null);
+ }
+ if (notFound) {
+ throw new HiveException(obj + " can not be found");
+ }
+ }
+
+ PrivilegeBag privBag = new PrivilegeBag();
+ if (privSubjectDesc == null) {
+ for (int idx = 0; idx < privileges.size(); idx++) {
+ Privilege priv = privileges.get(idx).getPrivilege();
+ if (privileges.get(idx).getColumns() != null
+ && privileges.get(idx).getColumns().size() > 0) {
+ throw new HiveException(
+ "For user-level privileges, column sets should be null. columns="
+ + privileges.get(idx).getColumns().toString());
+ }
+
+ privBag.addToPrivileges(new HiveObjectPrivilege(new HiveObjectRef(
+ HiveObjectType.GLOBAL, null, null, null, null), null, null,
+ new PrivilegeGrantInfo(priv.getPriv(), 0, grantor, grantorType,
+ grantOption)));
+ }
+ } else {
+ org.apache.hadoop.hive.metastore.api.Partition partObj = null;
+
+ if ((!tableObj.isPartitioned())
+ && privSubjectDesc.getPartSpec() != null) {
+ throw new HiveException(
+ "Table is not partitioned, but partition name is present: partSpec="
+ + privSubjectDesc.getPartSpec().toString());
+ }
+
+
+ List<String> partValues = null;
+ if (privSubjectDesc.getPartSpec() != null) {
+ partObj = db.getPartition(tableObj, privSubjectDesc.getPartSpec(),
+ false).getTPartition();
+ partValues = partObj.getValues();
+ }
+
+ for (PrivilegeDesc privDesc : privileges) {
+ List<String> columns = privDesc.getColumns();
+ Privilege priv = privDesc.getPrivilege();
+ if (columns != null && columns.size() > 0) {
+ if (!priv.supportColumnLevel()) {
+ throw new HiveException(priv.getPriv()
+ + " does not support column level.");
+ }
+ if (privSubjectDesc == null || tableName == null) {
+ throw new HiveException(
+ "For user-level/database-level privileges, column sets should be null. columns="
+ + columns);
+ }
+ for (int i = 0; i < columns.size(); i++) {
+ privBag.addToPrivileges(new HiveObjectPrivilege(
+ new HiveObjectRef(HiveObjectType.COLUMN, dbName, tableName,
+ partValues, columns.get(i)), null, null, new PrivilegeGrantInfo(priv.getPriv(), 0, grantor, grantorType, grantOption)));
+ }
+ } else {
+ if (privSubjectDesc.getTable()) {
+ if (privSubjectDesc.getPartSpec() != null) {
+ privBag.addToPrivileges(new HiveObjectPrivilege(
+ new HiveObjectRef(HiveObjectType.PARTITION, dbName,
+ tableName, partValues, null), null, null, new PrivilegeGrantInfo(priv.getPriv(), 0, grantor, grantorType, grantOption)));
+ } else {
+ privBag
+ .addToPrivileges(new HiveObjectPrivilege(
+ new HiveObjectRef(HiveObjectType.TABLE, dbName,
+ tableName, null, null), null, null, new PrivilegeGrantInfo(priv.getPriv(), 0, grantor, grantorType, grantOption)));
+ }
+ } else {
+ privBag.addToPrivileges(new HiveObjectPrivilege(
+ new HiveObjectRef(HiveObjectType.DATABASE, dbName, null,
+ null, null), null, null, new PrivilegeGrantInfo(priv.getPriv(), 0, grantor, grantorType, grantOption)));
+ }
+ }
+ }
+ }
+
+ for (PrincipalDesc principal : principals) {
+ for (int i = 0; i < privBag.getPrivileges().size(); i++) {
+ HiveObjectPrivilege objPrivs = privBag.getPrivileges().get(i);
+ objPrivs.setPrincipalName(principal.getName());
+ objPrivs.setPrincipalType(principal.getType());
+ }
+ if (isGrant) {
+ db.grantPrivileges(privBag);
+ } else {
+ db.revokePrivileges(privBag);
+ }
+ }
+ } catch (Exception e) {
+ console.printError("Error: " + e.getMessage());
+ return 1;
+ }
+
+ return 0;
+ }
+
+ private int roleDDL(RoleDDLDesc roleDDLDesc) {
+ RoleDDLDesc.RoleOperation operation = roleDDLDesc.getOperation();
+ try {
+ if (operation.equals(RoleDDLDesc.RoleOperation.CREATE_ROLE)) {
+ db.createRole(roleDDLDesc.getName(), roleDDLDesc.getRoleOwnerName());
+ } else if (operation.equals(RoleDDLDesc.RoleOperation.DROP_ROLE)) {
+ db.dropRole(roleDDLDesc.getName());
+ } else if (operation.equals(RoleDDLDesc.RoleOperation.SHOW_ROLE_GRANT)) {
+ List<Role> roles = db.showRoleGrant(roleDDLDesc.getName(), roleDDLDesc
+ .getPrincipalType());
+ if (roles != null && roles.size() > 0) {
+ Path resFile = new Path(roleDDLDesc.getResFile());
+ FileSystem fs = resFile.getFileSystem(conf);
+ DataOutput outStream = fs.create(resFile);
+ for (Role role : roles) {
+ outStream.writeBytes("role name:" + role.getRoleName());
+ outStream.write(terminator);
+ }
+ ((FSDataOutputStream) outStream).close();
+ }
+ } else {
+ throw new HiveException("Unkown role operation "
+ + operation.getOperationName());
+ }
+ } catch (HiveException e) {
+ console.printError("Error in role operation "
+ + operation.getOperationName() + " on role name "
+ + roleDDLDesc.getName() + ", error message " + e.getMessage());
+ return 1;
+ } catch (IOException e) {
+ LOG.info("role ddl exception: " + stringifyException(e));
+ return 1;
+ }
+
+ return 0;
+ }
+
private int alterDatabase(AlterDatabaseDesc alterDbDesc) throws HiveException {
String dbName = alterDbDesc.getDatabaseName();
@@ -404,6 +807,16 @@ public class DDLTask extends Task<DDLWor
/**
* Add a partition to a table.
+ *
+ * @param db
+ * Database to add the partition to.
+ * @param addPartitionDesc
+ * Add this partition.
+ * @return Returns 0 when execution succeeds and above 0 if it fails.
+ * @throws HiveException
+ */
+ /**
+ * Add a partition to a table.
*
* @param db
* Database to add the partition to.
@@ -482,6 +895,7 @@ public class DDLTask extends Task<DDLWor
}
return 0;
}
+
/**
* Determines whether a partition has been archived
*
@@ -1627,9 +2041,9 @@ public class DDLTask extends Task<DDLWor
outStream.writeBytes(params.toString());
}
- } else {
- outStream.writeBytes("No such database: " + descDatabase.getDatabaseName());
- }
+ } else {
+ outStream.writeBytes("No such database: " + descDatabase.getDatabaseName());
+ }
outStream.write(terminator);
@@ -1822,9 +2236,9 @@ public class DDLTask extends Task<DDLWor
LOG.info("DDLTask: got data for " + tbl.getTableName());
- Path resFile = new Path(descTbl.getResFile());
- FileSystem fs = resFile.getFileSystem(conf);
- DataOutput outStream = fs.create(resFile);
+ Path resFile = new Path(descTbl.getResFile());
+ FileSystem fs = resFile.getFileSystem(conf);
+ DataOutput outStream = fs.create(resFile);
if (colPath.equals(tableName)) {
if (!descTbl.isFormatted()) {
@@ -1894,6 +2308,46 @@ public class DDLTask extends Task<DDLWor
return 0;
}
+ public static void writeGrantInfo(DataOutput outStream,
+ PrincipalType principalType, String principalName, String dbName,
+ String tableName, String partName, String columnName,
+ PrivilegeGrantInfo grantInfo) throws IOException {
+
+ String privilege = grantInfo.getPrivilege();
+ int createTime = grantInfo.getCreateTime();
+ String grantor = grantInfo.getGrantor();
+
+ if (dbName != null) {
+ writeKeyValuePair(outStream, "database", dbName);
+ }
+ if (tableName != null) {
+ writeKeyValuePair(outStream, "table", tableName);
+ }
+ if (partName != null) {
+ writeKeyValuePair(outStream, "partition", partName);
+ }
+ if (columnName != null) {
+ writeKeyValuePair(outStream, "columnName", columnName);
+ }
+
+ writeKeyValuePair(outStream, "principalName", principalName);
+ writeKeyValuePair(outStream, "principalType", "" + principalType);
+ writeKeyValuePair(outStream, "privilege", privilege);
+ writeKeyValuePair(outStream, "grantTime", "" + createTime);
+ if (grantor != null) {
+ writeKeyValuePair(outStream, "grantor", grantor);
+ }
+ }
+
+ private static void writeKeyValuePair(DataOutput outStream, String key,
+ String value) throws IOException {
+ outStream.write(terminator);
+ outStream.writeBytes(key);
+ outStream.write(separator);
+ outStream.writeBytes(value);
+ outStream.write(separator);
+ }
+
private void writeFileSystemStats(DataOutput outStream, List<Path> locations,
Path tabLoc, boolean partSpecified, int indent) throws IOException {
long totalFileSize = 0;
@@ -2521,7 +2975,6 @@ public class DDLTask extends Task<DDLWor
return 0;
}
-
/**
* Create a new table.
*
Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/MoveTask.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/MoveTask.java?rev=1057999&r1=1057998&r2=1057999&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/MoveTask.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/MoveTask.java Wed Jan 12 06:58:04 2011
@@ -197,7 +197,7 @@ public class MoveTask extends Task<MoveW
db.loadTable(new Path(tbd.getSourceDir()), tbd.getTable()
.getTableName(), tbd.getReplace(), tbd.getHoldDDLTime());
if (work.getOutputs() != null) {
- work.getOutputs().add(new WriteEntity(table));
+ work.getOutputs().add(new WriteEntity(table, true));
}
} else {
LOG.info("Partition is: " + tbd.getPartitionSpec().toString());
@@ -238,7 +238,7 @@ public class MoveTask extends Task<MoveW
for (LinkedHashMap<String, String> partSpec: dp) {
Partition partn = db.getPartition(table, partSpec, false);
- WriteEntity enty = new WriteEntity(partn);
+ WriteEntity enty = new WriteEntity(partn, true);
if (work.getOutputs() != null) {
work.getOutputs().add(enty);
}
@@ -270,7 +270,7 @@ public class MoveTask extends Task<MoveW
dc = new DataContainer(table.getTTable(), partn.getTPartition());
// add this partition to post-execution hook
if (work.getOutputs() != null) {
- work.getOutputs().add(new WriteEntity(partn));
+ work.getOutputs().add(new WriteEntity(partn, true));
}
}
}
Added: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/metadata/AuthorizationException.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/metadata/AuthorizationException.java?rev=1057999&view=auto
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/metadata/AuthorizationException.java (added)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/metadata/AuthorizationException.java Wed Jan 12 06:58:04 2011
@@ -0,0 +1,55 @@
+/**
+ * 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.hadoop.hive.ql.metadata;
+
+public class AuthorizationException extends RuntimeException {
+ /**
+ */
+ private static final long serialVersionUID = 1L;
+
+ public AuthorizationException() {
+ super();
+ }
+
+ /**
+ * Constructs an {@link AuthorizationException} with the specified detail
+ * message.
+ *
+ * @param s
+ * the detail message.
+ */
+ public AuthorizationException(String message) {
+ super(message);
+ }
+
+ /**
+ * Constructs an {@link AuthorizationException} with the specified cause.
+ *
+ * @param cause
+ * the cause
+ */
+ public AuthorizationException(Throwable cause) {
+ super(cause);
+ }
+
+
+ public AuthorizationException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java?rev=1057999&r1=1057998&r2=1057999&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java Wed Jan 12 06:58:04 2011
@@ -57,14 +57,23 @@ import org.apache.hadoop.hive.metastore.
import org.apache.hadoop.hive.metastore.api.Constants;
import org.apache.hadoop.hive.metastore.api.Database;
import org.apache.hadoop.hive.metastore.api.FieldSchema;
+import org.apache.hadoop.hive.metastore.api.HiveObjectPrivilege;
+import org.apache.hadoop.hive.metastore.api.HiveObjectRef;
+import org.apache.hadoop.hive.metastore.api.HiveObjectType;
import org.apache.hadoop.hive.metastore.api.Index;
import org.apache.hadoop.hive.metastore.api.InvalidOperationException;
import org.apache.hadoop.hive.metastore.api.MetaException;
import org.apache.hadoop.hive.metastore.api.NoSuchObjectException;
import org.apache.hadoop.hive.metastore.api.Order;
+import org.apache.hadoop.hive.metastore.api.PrincipalPrivilegeSet;
+import org.apache.hadoop.hive.metastore.api.PrincipalType;
+import org.apache.hadoop.hive.metastore.api.PrivilegeBag;
+import org.apache.hadoop.hive.metastore.api.Role;
import org.apache.hadoop.hive.metastore.api.SerDeInfo;
import org.apache.hadoop.hive.ql.exec.Utilities;
import org.apache.hadoop.hive.ql.index.HiveIndexHandler;
+import org.apache.hadoop.hive.ql.session.CreateTableAutomaticGrant;
+import org.apache.hadoop.hive.ql.session.SessionState;
import org.apache.hadoop.hive.serde2.Deserializer;
import org.apache.hadoop.hive.serde2.SerDeException;
import org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe;
@@ -86,7 +95,7 @@ public class Hive {
private HiveConf conf = null;
private IMetaStoreClient metaStoreClient;
private String currentDatabase;
-
+
private static ThreadLocal<Hive> hiveDB = new ThreadLocal() {
@Override
protected synchronized Object initialValue() {
@@ -444,7 +453,19 @@ public class Hive {
if (tbl.getParameters() != null) {
tbl.getParameters().remove(Constants.DDL_TIME);
}
- getMSC().createTable(tbl.getTTable());
+ org.apache.hadoop.hive.metastore.api.Table tTbl = tbl.getTTable();
+ PrincipalPrivilegeSet principalPrivs = new PrincipalPrivilegeSet();
+ SessionState ss = SessionState.get();
+ if (ss != null) {
+ CreateTableAutomaticGrant grants = ss.getCreateTableGrants();
+ if (grants != null) {
+ principalPrivs.setUserPrivileges(grants.getUserGrants());
+ principalPrivs.setGroupPrivileges(grants.getGroupGrants());
+ principalPrivs.setRolePrivileges(grants.getRoleGrants());
+ tTbl.setPrivileges(principalPrivs);
+ }
+ }
+ getMSC().createTable(tTbl);
} catch (AlreadyExistsException e) {
if (!ifNotExists) {
throw new HiveException(e);
@@ -775,7 +796,7 @@ public class Hive {
} catch (NoSuchObjectException e) {
if (throwException) {
LOG.error(StringUtils.stringifyException(e));
- throw new InvalidTableException("Table not found ", tableName);
+ throw new InvalidTableException("Table " + tableName + " not found ", tableName);
}
return null;
} catch (Exception e) {
@@ -915,6 +936,36 @@ public class Hive {
}
}
+ public boolean grantPrivileges(PrivilegeBag privileges)
+ throws HiveException {
+ try {
+ return getMSC().grant_privileges(privileges);
+ } catch (Exception e) {
+ throw new HiveException(e);
+ }
+ }
+
+ /**
+ * @param userName
+ * principal name
+ * @param isRole
+ * is the given principal name a role
+ * @param isGroup
+ * is the given principal name a group
+ * @param privileges
+ * a bag of privileges
+ * @return
+ * @throws HiveException
+ */
+ public boolean revokePrivileges(PrivilegeBag privileges)
+ throws HiveException {
+ try {
+ return getMSC().revoke_privileges(privileges);
+ } catch (Exception e) {
+ throw new HiveException(e);
+ }
+ }
+
/**
* Query metadata to see if a database with the given name already exists.
*
@@ -1083,7 +1134,7 @@ public class Hive {
public void loadTable(Path loadPath, String tableName, boolean replace,
boolean holdDDLTime) throws HiveException {
Table tbl = getTable(tableName);
-
+
if (replace) {
tbl.replaceFiles(loadPath);
} else {
@@ -1191,7 +1242,8 @@ public class Hive {
}
org.apache.hadoop.hive.metastore.api.Partition tpart = null;
try {
- tpart = getMSC().getPartition(tbl.getDbName(), tbl.getTableName(), pvals);
+ tpart = getMSC().getPartitionWithAuthInfo(tbl.getDbName(),
+ tbl.getTableName(), pvals, getUserName(), getGroupNames());
} catch (NoSuchObjectException nsoe) {
// this means no partition exists for the given partition
// key value pairs - thrift cannot handle null return values, hence
@@ -1283,8 +1335,8 @@ public class Hive {
if (tbl.isPartitioned()) {
List<org.apache.hadoop.hive.metastore.api.Partition> tParts;
try {
- tParts = getMSC().listPartitions(tbl.getDbName(), tbl.getTableName(),
- (short) -1);
+ tParts = getMSC().listPartitionsWithAuthInfo(tbl.getDbName(), tbl.getTableName(),
+ (short) -1, getUserName(), getGroupNames());
} catch (Exception e) {
LOG.error(StringUtils.stringifyException(e));
throw new HiveException(e);
@@ -1336,8 +1388,8 @@ public class Hive {
List<org.apache.hadoop.hive.metastore.api.Partition> partitions = null;
try {
- partitions = getMSC().listPartitions(tbl.getDbName(), tbl.getTableName(),
- partialPvals, (short) -1);
+ partitions = getMSC().listPartitionsWithAuthInfo(tbl.getDbName(), tbl.getTableName(),
+ partialPvals, (short) -1, getUserName(), getGroupNames());
} catch (Exception e) {
throw new HiveException(e);
}
@@ -1407,6 +1459,116 @@ public class Hive {
public void setCurrentDatabase(String currentDatabase) {
this.currentDatabase = currentDatabase;
}
+
+ public void createRole(String roleName, String ownerName)
+ throws HiveException {
+ try {
+ getMSC().create_role(new Role(roleName, -1, ownerName));
+ } catch (Exception e) {
+ throw new HiveException(e);
+ }
+ }
+
+ public void dropRole(String roleName) throws HiveException {
+ try {
+ getMSC().drop_role(roleName);
+ } catch (Exception e) {
+ throw new HiveException(e);
+ }
+ }
+
+ public List<Role> showRoleGrant(String principalName, PrincipalType principalType) throws HiveException {
+ try {
+ return getMSC().list_roles(principalName, principalType);
+ } catch (Exception e) {
+ throw new HiveException(e);
+ }
+ }
+
+ public boolean grantRole(String roleName, String userName,
+ PrincipalType principalType, String grantor, PrincipalType grantorType,
+ boolean grantOption) throws HiveException {
+ try {
+ return getMSC().grant_role(roleName, userName, principalType, grantor,
+ grantorType, grantOption);
+ } catch (Exception e) {
+ throw new HiveException(e);
+ }
+ }
+
+ public boolean revokeRole(String roleName, String userName,
+ PrincipalType principalType) throws HiveException {
+ try {
+ return getMSC().revoke_role(roleName, userName, principalType);
+ } catch (Exception e) {
+ throw new HiveException(e);
+ }
+ }
+
+ public List<Role> listRoles(String userName, PrincipalType principalType)
+ throws HiveException {
+ try {
+ return getMSC().list_roles(userName, principalType);
+ } catch (Exception e) {
+ throw new HiveException(e);
+ }
+ }
+
+ /**
+ * @param objectType
+ * hive object type
+ * @param db_name
+ * database name
+ * @param table_name
+ * table name
+ * @param part_values
+ * partition values
+ * @param column_name
+ * column name
+ * @param user_name
+ * user name
+ * @param group_names
+ * group names
+ * @return
+ * @throws HiveException
+ */
+ public PrincipalPrivilegeSet get_privilege_set(HiveObjectType objectType,
+ String db_name, String table_name, List<String> part_values,
+ String column_name, String user_name, List<String> group_names)
+ throws HiveException {
+ try {
+ HiveObjectRef hiveObj = new HiveObjectRef(objectType, db_name,
+ table_name, part_values, column_name);
+ return getMSC().get_privilege_set(hiveObj, user_name, group_names);
+ } catch (Exception e) {
+ throw new HiveException(e);
+ }
+ }
+
+ /**
+ * @param objectType
+ * hive object type
+ * @param principalName
+ * @param principalType
+ * @param dbName
+ * @param tableName
+ * @param partValues
+ * @param columnName
+ * @return
+ * @throws HiveException
+ */
+ public List<HiveObjectPrivilege> showPrivilegeGrant(
+ HiveObjectType objectType, String principalName,
+ PrincipalType principalType, String dbName, String tableName,
+ List<String> partValues, String columnName) throws HiveException {
+ try {
+ HiveObjectRef hiveObj = new HiveObjectRef(objectType, dbName, tableName,
+ partValues, columnName);
+ return getMSC().list_privileges(principalName, principalType, hiveObj);
+ } catch (Exception e) {
+ throw new HiveException(e);
+ }
+ }
static private void checkPaths(FileSystem fs, FileStatus[] srcs, Path destf,
boolean replace) throws HiveException {
@@ -1569,7 +1731,10 @@ public class Hive {
if (!fs.exists(destf.getParent())) {
fs.mkdirs(destf.getParent());
}
-
+ if (fs.exists(destf)) {
+ fs.delete(destf, true);
+ }
+
boolean b = fs.rename(srcs[0].getPath(), destf);
if (!b) {
throw new HiveException("Unable to move results from " + srcs[0].getPath()
@@ -1641,6 +1806,22 @@ public class Hive {
}
return metaStoreClient;
}
+
+ private String getUserName() {
+ SessionState ss = SessionState.get();
+ if (ss != null && ss.getAuthenticator() != null) {
+ return ss.getAuthenticator().getUserName();
+ }
+ return null;
+ }
+
+ private List<String> getGroupNames() {
+ SessionState ss = SessionState.get();
+ if (ss != null && ss.getAuthenticator() != null) {
+ return ss.getAuthenticator().getGroupNames();
+ }
+ return null;
+ }
public static List<FieldSchema> getFieldsFromDeserializer(String name,
Deserializer serde) throws HiveException {
Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/metadata/HiveUtils.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/metadata/HiveUtils.java?rev=1057999&r1=1057998&r2=1057999&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/metadata/HiveUtils.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/metadata/HiveUtils.java Wed Jan 12 06:58:04 2011
@@ -25,6 +25,10 @@ import org.apache.hadoop.hive.common.Jav
import org.apache.hadoop.hive.conf.HiveConf;
import org.apache.hadoop.hive.ql.index.HiveIndexHandler;
import org.apache.hadoop.hive.ql.parse.AbstractSemanticAnalyzerHook;
+import org.apache.hadoop.hive.ql.security.HadoopDefaultAuthenticator;
+import org.apache.hadoop.hive.ql.security.HiveAuthenticationProvider;
+import org.apache.hadoop.hive.ql.security.authorization.DefaultHiveAuthorizationProvider;
+import org.apache.hadoop.hive.ql.security.authorization.HiveAuthorizationProvider;
import org.apache.hadoop.util.ReflectionUtils;
import org.apache.hadoop.hive.metastore.api.FieldSchema;
@@ -171,6 +175,57 @@ public final class HiveUtils {
+ e.getMessage(), e);
}
}
+
+ @SuppressWarnings("unchecked")
+ public static HiveAuthorizationProvider getAuthorizeProviderManager(
+ Configuration conf, HiveAuthenticationProvider authenticator) throws HiveException {
+
+ String clsStr = HiveConf.getVar(conf,
+ HiveConf.ConfVars.HIVE_AUTHORIZATION_MANAGER);
+
+ HiveAuthorizationProvider ret = null;
+ try {
+ Class<? extends HiveAuthorizationProvider> cls = null;
+ if (clsStr == null || clsStr.trim().equals("")) {
+ cls = DefaultHiveAuthorizationProvider.class;
+ } else {
+ cls = (Class<? extends HiveAuthorizationProvider>) Class.forName(
+ clsStr, true, JavaUtils.getClassLoader());
+ }
+ if (cls != null) {
+ ret = ReflectionUtils.newInstance(cls, conf);
+ }
+ } catch (Exception e) {
+ throw new HiveException(e);
+ }
+ ret.setAuthenticator(authenticator);
+ return ret;
+ }
+
+ @SuppressWarnings("unchecked")
+ public static HiveAuthenticationProvider getAuthenticator(Configuration conf)
+ throws HiveException {
+
+ String clsStr = HiveConf.getVar(conf,
+ HiveConf.ConfVars.HIVE_AUTHENTICATOR_MANAGER);
+
+ HiveAuthenticationProvider ret = null;
+ try {
+ Class<? extends HiveAuthenticationProvider> cls = null;
+ if (clsStr == null || clsStr.trim().equals("")) {
+ cls = HadoopDefaultAuthenticator.class;
+ } else {
+ cls = (Class<? extends HiveAuthenticationProvider>) Class.forName(
+ clsStr, true, JavaUtils.getClassLoader());
+ }
+ if (cls != null) {
+ ret = ReflectionUtils.newInstance(cls, conf);
+ }
+ } catch (Exception e) {
+ throw new HiveException(e);
+ }
+ return ret;
+ }
public static AbstractSemanticAnalyzerHook getSemanticAnalyzerHook(
HiveConf conf, String hookName) throws HiveException{
Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/BaseSemanticAnalyzer.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/BaseSemanticAnalyzer.java?rev=1057999&r1=1057998&r2=1057999&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/BaseSemanticAnalyzer.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/BaseSemanticAnalyzer.java Wed Jan 12 06:58:04 2011
@@ -71,7 +71,7 @@ public abstract class BaseSemanticAnalyz
protected Context ctx;
protected HashMap<String, String> idToTableNameMap;
-
+
public static int HIVE_COLUMN_ORDER_ASC = 1;
public static int HIVE_COLUMN_ORDER_DESC = 0;
@@ -719,4 +719,8 @@ public abstract class BaseSemanticAnalyz
}
return partSpec;
}
+
+ public Hive getDb() {
+ return db;
+ }
}