PageRenderTime 37ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/release-0.1-rc2/hive/external/ql/src/java/org/apache/hadoop/hive/ql/security/authorization/PrivilegeRegistry.java

#
Java | 58 lines | 27 code | 10 blank | 21 comment | 0 complexity | 2fc30723e8e13b1e1a1c7cb602094358 MD5 | raw file
Possible License(s): Apache-2.0, BSD-3-Clause, JSON, CPL-1.0
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. package org.apache.hadoop.hive.ql.security.authorization;
  19. import java.util.HashMap;
  20. import org.apache.hadoop.hive.ql.security.authorization.Privilege.PrivilegeType;
  21. /**
  22. * PrivilegeRegistry is used to do privilege lookups. Given a privilege name, it
  23. * will return the Privilege object.
  24. */
  25. public class PrivilegeRegistry {
  26. protected static HashMap<PrivilegeType, Privilege> Registry = new HashMap<PrivilegeType, Privilege>();
  27. static {
  28. Registry.put(Privilege.ALL.getPriv(), Privilege.ALL);
  29. Registry.put(Privilege.ALTER_DATA.getPriv(), Privilege.ALTER_DATA);
  30. Registry.put(Privilege.ALTER_METADATA.getPriv(), Privilege.ALTER_METADATA);
  31. Registry.put(Privilege.CREATE.getPriv(), Privilege.CREATE);
  32. Registry.put(Privilege.DROP.getPriv(), Privilege.DROP);
  33. Registry.put(Privilege.INDEX.getPriv(), Privilege.INDEX);
  34. Registry.put(Privilege.LOCK.getPriv(), Privilege.LOCK);
  35. Registry.put(Privilege.SELECT.getPriv(), Privilege.SELECT);
  36. Registry.put(Privilege.SHOW_DATABASE.getPriv(),
  37. Privilege.SHOW_DATABASE);
  38. }
  39. public static Privilege getPrivilege(PrivilegeType privilegeType) {
  40. return Registry.get(privilegeType);
  41. }
  42. public static Privilege getPrivilege(int privilegeToken) {
  43. return Registry.get(Privilege.getPrivTypeByToken(privilegeToken));
  44. }
  45. public static Privilege getPrivilege(String privilegeName) {
  46. return Registry.get(Privilege.getPrivTypeByName(privilegeName));
  47. }
  48. }