1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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.commons.lang.StringUtils;
26 import org.apache.hadoop.conf.Configuration;
27 import org.apache.hadoop.hbase.io.hfile.HFile;
28 import org.apache.hadoop.hbase.security.User;
29 import org.apache.hadoop.hbase.security.access.AccessController;
30 import org.apache.hadoop.hbase.util.LoadTestTool;
31 import org.apache.hadoop.hbase.util.test.LoadTestDataGeneratorWithACL;
32 import org.apache.hadoop.util.ToolRunner;
33 import org.junit.experimental.categories.Category;
34
35
36
37
38
39
40
41
42 @Category(IntegrationTests.class)
43 public class IntegrationTestIngestWithACL extends IntegrationTestIngest {
44
45 private static final char COLON = ':';
46 public static final char HYPHEN = '-';
47 private static final int SPECIAL_PERM_CELL_INSERTION_FACTOR = 100;
48 public static final String OPT_SUPERUSER = "superuser";
49 public static final String OPT_USERS = "userlist";
50 public static final String OPT_AUTHN = "authinfo";
51 private String superUser = "owner";
52 private String userNames = "user1,user2,user3,user4";
53 private String authnFileName;
54 @Override
55 public void setUpCluster() throws Exception {
56 util = getTestingUtil(null);
57 Configuration conf = util.getConfiguration();
58 conf.setInt(HFile.FORMAT_VERSION_KEY, 3);
59 conf.set("hbase.coprocessor.master.classes", AccessController.class.getName());
60 conf.set("hbase.coprocessor.region.classes", AccessController.class.getName());
61
62 super.setUpCluster();
63 }
64
65 @Override
66 protected String[] getArgsForLoadTestTool(String mode, String modeSpecificArg, long startKey,
67 long numKeys) {
68 String[] args = super.getArgsForLoadTestTool(mode, modeSpecificArg, startKey, numKeys);
69 List<String> tmp = new ArrayList<String>(Arrays.asList(args));
70 tmp.add(HYPHEN + LoadTestTool.OPT_GENERATOR);
71 StringBuilder sb = new StringBuilder(LoadTestDataGeneratorWithACL.class.getName());
72 sb.append(COLON);
73 if (User.isHBaseSecurityEnabled(getConf())) {
74 sb.append(authnFileName);
75 sb.append(COLON);
76 }
77 sb.append(superUser);
78 sb.append(COLON);
79 sb.append(userNames);
80 sb.append(COLON);
81 sb.append(Integer.toString(SPECIAL_PERM_CELL_INSERTION_FACTOR));
82 tmp.add(sb.toString());
83 return tmp.toArray(new String[tmp.size()]);
84 }
85 @Override
86 protected void addOptions() {
87 super.addOptions();
88 super.addOptWithArg(OPT_SUPERUSER,
89 "Super user name used to add the ACL permissions");
90 super.addOptWithArg(OPT_USERS,
91 "List of users to be added with the ACLs. Should be comma seperated.");
92 super
93 .addOptWithArg(
94 OPT_AUTHN,
95 "The name of the properties file that contains kerberos key tab file and principal definitions. " +
96 "The principal key in the file should be of the form hbase.<username>.kerberos.principal." +
97 " The keytab key in the file should be of the form hbase.<username>.keytab.file. Example: " +
98 "hbase.user1.kerberos.principal=user1/fully.qualified.domain.name@YOUR-REALM.COM, " +
99 "hbase.user1.keytab.file=<filelocation>.");
100 }
101
102 @Override
103 protected void processOptions(CommandLine cmd) {
104 super.processOptions(cmd);
105 if (cmd.hasOption(OPT_SUPERUSER)) {
106 superUser = cmd.getOptionValue(OPT_SUPERUSER);
107 }
108 if (cmd.hasOption(OPT_USERS)) {
109 userNames = cmd.getOptionValue(OPT_USERS);
110 }
111 if (User.isHBaseSecurityEnabled(getConf())) {
112 boolean authFileNotFound = false;
113 if (cmd.hasOption(OPT_AUTHN)) {
114 authnFileName = cmd.getOptionValue(OPT_AUTHN);
115 if (StringUtils.isEmpty(authnFileName)) {
116 authFileNotFound = true;
117 }
118 } else {
119 authFileNotFound = true;
120 }
121 if (authFileNotFound) {
122 super.printUsage();
123 System.exit(EXIT_FAILURE);
124 }
125 }
126 }
127
128 public static void main(String[] args) throws Exception {
129 Configuration conf = HBaseConfiguration.create();
130 IntegrationTestingUtility.setUseDistributedCluster(conf);
131 int ret = ToolRunner.run(conf, new IntegrationTestIngestWithACL(), args);
132 System.exit(ret);
133 }
134 }