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  
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      appendCoprocessor(conf, CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY,
27        VisibilityController.class.getName());
28      appendCoprocessor(conf, CoprocessorHost.REGION_COPROCESSOR_CONF_KEY,
29        VisibilityController.class.getName());
30    }
31  
32    private static void appendCoprocessor(Configuration conf, String property, String value) {
33      if (conf.get(property) == null) {
34        conf.set(property, VisibilityController.class.getName());
35      } else {
36        conf.set(property, conf.get(property) + "," + VisibilityController.class.getName());
37      }
38    }
39  
40  }