View Javadoc

1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
3    * agreements. See the NOTICE file distributed with this work for additional information regarding
4    * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
5    * "License"); you may not use this file except in compliance with the License. You may obtain a
6    * copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable
7    * law or agreed to in writing, software distributed under the License is distributed on an "AS IS"
8    * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
9    * for the specific language governing permissions and limitations under the License.
10   */
11  package org.apache.hadoop.hbase.security.visibility;
12  
13  import java.io.IOException;
14  
15  import org.apache.hadoop.conf.Configuration;
16  import org.apache.hadoop.hbase.coprocessor.CoprocessorHost;
17  import org.apache.hadoop.hbase.security.User;
18  
19  /**
20   * Utility methods for testing visibility labels.
21   */
22  public class VisibilityTestUtil {
23  
24    public static void enableVisiblityLabels(Configuration conf) throws IOException {
25      conf.setInt("hfile.format.version", 3);
26      conf.setBoolean(User.HBASE_SECURITY_AUTHORIZATION_CONF_KEY, true);
27      appendCoprocessor(conf, CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY,
28        VisibilityController.class.getName());
29      appendCoprocessor(conf, CoprocessorHost.REGION_COPROCESSOR_CONF_KEY,
30        VisibilityController.class.getName());
31    }
32  
33    private static void appendCoprocessor(Configuration conf, String property, String value) {
34      if (conf.get(property) == null) {
35        conf.set(property, VisibilityController.class.getName());
36      } else {
37        conf.set(property, conf.get(property) + "," + VisibilityController.class.getName());
38      }
39    }
40  
41  }