View Javadoc

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.hbase;
19  
20  import java.util.ArrayList;
21  import java.util.Arrays;
22  import java.util.List;
23  
24  import org.apache.commons.cli.CommandLine;
25  import org.apache.hadoop.conf.Configuration;
26  import org.apache.hadoop.hbase.io.hfile.HFile;
27  import org.apache.hadoop.hbase.security.access.AccessController;
28  import org.apache.hadoop.hbase.util.LoadTestTool;
29  import org.apache.hadoop.hbase.util.test.LoadTestDataGeneratorWithACL;
30  import org.apache.hadoop.util.ToolRunner;
31  import org.junit.experimental.categories.Category;
32  /**
33   * /**
34   * An Integration class for tests that does something with the cluster while running
35   * {@link LoadTestTool} to write and verify some data.
36   * Verifies whether cells for users with only WRITE permissions are not read back
37   * and cells with READ permissions are read back. 
38   * Every operation happens in the user's specific context
39   */
40  @Category(IntegrationTests.class)
41  public class IntegrationTestIngestWithACL extends IntegrationTestIngest {
42  
43    private static final char COLON = ':';
44    public static final char HYPHEN = '-';
45    private static final int SPECIAL_PERM_CELL_INSERTION_FACTOR = 100;
46    public static final String OPT_SUPERUSER = "superuser";
47    public static final String OPT_USERS = "userlist";
48    private String superUser = "owner";
49    private String userNames = "user1,user2,user3,user4"; 
50    @Override
51    public void setUpCluster() throws Exception {
52      util = getTestingUtil(null);
53      Configuration conf = util.getConfiguration();
54      conf.setInt(HFile.FORMAT_VERSION_KEY, 3);
55      conf.set("hbase.coprocessor.master.classes", AccessController.class.getName());
56      conf.set("hbase.coprocessor.region.classes", AccessController.class.getName());
57      // conf.set("hbase.superuser", "admin");
58      super.setUpCluster();
59    }
60  
61    @Override
62    protected String[] getArgsForLoadTestTool(String mode, String modeSpecificArg, long startKey,
63        long numKeys) {
64      String[] args = super.getArgsForLoadTestTool(mode, modeSpecificArg, startKey, numKeys);
65      List<String> tmp = new ArrayList<String>(Arrays.asList(args));
66      tmp.add(HYPHEN + LoadTestTool.OPT_GENERATOR);
67      StringBuilder sb = new StringBuilder(LoadTestDataGeneratorWithACL.class.getName());
68      sb.append(COLON);
69      sb.append(superUser);
70      sb.append(COLON);
71      sb.append(userNames);
72      sb.append(COLON);
73      sb.append(Integer.toString(SPECIAL_PERM_CELL_INSERTION_FACTOR));
74      tmp.add(sb.toString());
75      return tmp.toArray(new String[tmp.size()]);
76    }
77    @Override
78    protected void addOptions() {
79      super.addOptions();
80      super.addOptWithArg(OPT_SUPERUSER,
81          "Super user name used to add the ACL permissions");
82      super.addOptWithArg(OPT_USERS,
83          "List of users to be added with the ACLs.  Should be comma seperated.");
84    }
85  
86    @Override
87    protected void processOptions(CommandLine cmd) {
88      super.processOptions(cmd);
89      if (cmd.hasOption(OPT_SUPERUSER)) {
90        superUser = cmd.getOptionValue(OPT_SUPERUSER);
91      }
92      if (cmd.hasOption(OPT_USERS)) {
93        userNames = cmd.getOptionValue(OPT_USERS);
94      }
95    }
96  
97    public static void main(String[] args) throws Exception {
98      Configuration conf = HBaseConfiguration.create();
99      IntegrationTestingUtility.setUseDistributedCluster(conf);
100     int ret = ToolRunner.run(conf, new IntegrationTestIngestWithACL(), args);
101     System.exit(ret);
102   }
103 }