Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
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.session;
 
 import java.util.List;
 import java.util.Map;
 
 import  org.apache.hadoop.hive.metastore.api.PrincipalType;
 import  org.apache.hadoop.hive.metastore.api.PrivilegeGrantInfo;
 
 public class CreateTableAutomaticGrant {
   private Map<StringList<PrivilegeGrantInfo>> userGrants;
   private Map<StringList<PrivilegeGrantInfo>> groupGrants;
   private Map<StringList<PrivilegeGrantInfo>> roleGrants;
 
   public static CreateTableAutomaticGrant create(HiveConf conf)
       throws HiveException {
     grants.userGrants = getGrantMap(HiveConf.getVar(conf,
     grants.groupGrants = getGrantMap(HiveConf.getVar(conf,
     grants.roleGrants = getGrantMap(HiveConf.getVar(conf,
     
     String grantor = null;
     if (SessionState.get() != null
         && SessionState.get().getAuthenticator() != null) {
       grantor = SessionState.get().getAuthenticator().getUserName();
       List<PrivilegeGrantInfo> ownerGrant = getGrantorInfoList(HiveConf.getVar(conf,
       if(ownerGrant != null) {
         if (grants.userGrants == null) {
           grants.userGrants = new HashMap<StringList<PrivilegeGrantInfo>>();
         }
         grants.userGrants.put(grantorownerGrant);
       }
     }
     return grants;
   }
 
   private static Map<StringList<PrivilegeGrantInfo>> getGrantMap(String grantMapStr)
       throws HiveException {
     if (grantMapStr != null && !grantMapStr.trim().equals("")) {
       String[] grantArrayStr = grantMapStr.split(";");
       Map<StringList<PrivilegeGrantInfo>> grantsMap = new HashMap<StringList<PrivilegeGrantInfo>>();
       for (String grantStr : grantArrayStr) {
         String[] principalListAndPrivList = grantStr.split(":");
         if (principalListAndPrivList.length != 2
             || principalListAndPrivList[0] == null
             || principalListAndPrivList[0].trim().equals("")) {
           throw new HiveException(
               "Can not understand the config privilege definition " + grantStr);
         }
         String userList = principalListAndPrivList[0];
         String privList = principalListAndPrivList[1];
         List<PrivilegeGrantInfo> grantInfoList = getGrantorInfoList(privList);
         if(grantInfoList != null) {
           String[] users = userList.split(",");
           for (String user : users) {
             grantsMap.put(usergrantInfoList);
           }
         }
       }
       return grantsMap;
     }
     return null;
   }
 
   private static List<PrivilegeGrantInfo> getGrantorInfoList(String privList)
       throws HiveException {
     if (privList == null || privList.trim().equals("")) {
       return null;
     }
     checkPrivilege(privList);
     String[] grantArray = privList.split(",");
     List<PrivilegeGrantInfo> grantInfoList = new ArrayList<PrivilegeGrantInfo>();
    String grantor = null;
    if (SessionState.get().getAuthenticator() != null) {
      grantor = SessionState.get().getAuthenticator().getUserName();  
    }
    for (String grant : grantArray) {
      grantInfoList.add(new PrivilegeGrantInfo(grant, -1, grantor,
          PrincipalType.USER, true));
    }
    return grantInfoList;
  }
  private static void checkPrivilege(String ownerGrantsInConfig)
      throws HiveException {
    String[] ownerGrantArray = ownerGrantsInConfig.split(",");
    // verify the config
    for (String ownerGrant : ownerGrantArray) {
      Privilege prive = PrivilegeRegistry.getPrivilege(ownerGrant);
      if (prive == null) {
        throw new HiveException("Privilege " + ownerGrant + " is not found.");
      }
    }
  }
  public Map<StringList<PrivilegeGrantInfo>> getUserGrants() {
    return ;
  }
  public Map<StringList<PrivilegeGrantInfo>> getGroupGrants() {
    return ;
  }
  public Map<StringList<PrivilegeGrantInfo>> getRoleGrants() {
    return ;
  }
New to GrepCode? Check out our FAQ X