1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase.security.visibility;
19
20 import java.io.IOException;
21
22 import org.apache.commons.logging.Log;
23 import org.apache.commons.logging.LogFactory;
24 import org.apache.hadoop.hbase.classification.InterfaceAudience;
25 import org.apache.hadoop.conf.Configuration;
26 import org.apache.hadoop.util.ReflectionUtils;
27
28
29
30
31 @InterfaceAudience.Private
32 public class VisibilityLabelServiceManager {
33
34 private static final Log LOG = LogFactory.getLog(VisibilityLabelServiceManager.class);
35
36 public static final String VISIBILITY_LABEL_SERVICE_CLASS =
37 "hbase.regionserver.visibility.label.service.class";
38 private static final VisibilityLabelServiceManager INSTANCE = new VisibilityLabelServiceManager();
39
40 private volatile VisibilityLabelService visibilityLabelService = null;
41 private String vlsClazzName = null;
42
43 private VisibilityLabelServiceManager() {
44
45 }
46
47 public static VisibilityLabelServiceManager getInstance() {
48 return INSTANCE;
49 }
50
51
52
53
54
55
56
57 public VisibilityLabelService getVisibilityLabelService(Configuration conf) throws IOException {
58 String vlsClassName = conf.get(VISIBILITY_LABEL_SERVICE_CLASS,
59 DefaultVisibilityLabelServiceImpl.class.getCanonicalName()).trim();
60 if (this.visibilityLabelService != null) {
61 checkForClusterLevelSingleConf(vlsClassName);
62 return this.visibilityLabelService;
63 }
64 synchronized (this) {
65 if (this.visibilityLabelService != null) {
66 checkForClusterLevelSingleConf(vlsClassName);
67 return this.visibilityLabelService;
68 }
69 this.vlsClazzName = vlsClassName;
70 try {
71 this.visibilityLabelService = (VisibilityLabelService) ReflectionUtils.newInstance(
72 Class.forName(vlsClassName), conf);
73 } catch (ClassNotFoundException e) {
74 throw new IOException(e);
75 }
76 return this.visibilityLabelService;
77 }
78 }
79
80 private void checkForClusterLevelSingleConf(String vlsClassName) {
81 assert this.vlsClazzName != null;
82 if (!this.vlsClazzName.equals(vlsClassName)) {
83 LOG.warn("Trying to use table specific value for config "
84 + "'hbase.regionserver.visibility.label.service.class' which is not supported."
85 + " Will use the cluster level VisibilityLabelService class " + this.vlsClazzName);
86 }
87 }
88
89
90
91
92
93 public VisibilityLabelService getVisibilityLabelService() {
94
95
96
97 if (this.visibilityLabelService == null) {
98 throw new IllegalStateException("VisibilityLabelService not yet instantiated");
99 }
100 return this.visibilityLabelService;
101 }
102 }