org.apache.hadoop.hbase.security.access.AccessControlLists Java Examples

The following examples show how to use org.apache.hadoop.hbase.security.access.AccessControlLists. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HBase.java    From pxf with Apache License 2.0 6 votes vote down vote up
private void grantPermissions(Table table,
                              String user, Action... actions)
        throws Exception {

    ReportUtils.report(report, getClass(), config.toString());
    ReportUtils.report(report, getClass(),"grant request for user=" + user + " table" + table);
    String hbaseAuthEnabled = config.get("hbase.security.authorization");
    if (!isAuthorizationEnabled && (hbaseAuthEnabled == null || !hbaseAuthEnabled.equals("true"))) {
        ReportUtils.report(report, getClass(),
                "HBase security authorization is not enabled, cannot grant permissions");
        return;
    }

    org.apache.hadoop.hbase.client.Table acl = connection.getTable(AccessControlLists.ACL_TABLE_NAME);
    try {
        BlockingRpcChannel service = acl.coprocessorService(HConstants.EMPTY_START_ROW);
        AccessControlProtos.AccessControlService.BlockingInterface protocol = AccessControlProtos.AccessControlService.newBlockingStub(service);
        if (table == null) {
            ProtobufUtil.grant(protocol, user, actions);
        } else {
            ProtobufUtil.grant(protocol, user, TableName.valueOf(table.getName()), null, null, actions);
        }
    } finally {
        acl.close();
    }
}
 
Example #2
Source File: TestBase.java    From hbase-tools with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void setUpOnce() throws Exception {
    miniCluster = System.getProperty("cluster.type").equals("mini");
    securedCluster = System.getProperty("cluster.secured").equals("true");
    System.out.println("realCluster - " + !miniCluster);
    System.out.println("securedCluster - " + securedCluster);

    Util.setLoggingThreshold("ERROR");

    if (miniCluster) {
        if (hbase == null) {
            conf = HBaseConfiguration.create(new Configuration(true));
            conf.setInt("hbase.master.info.port", -1);
            conf.set("zookeeper.session.timeout", "3600000");
            conf.set("dfs.client.socket-timeout", "3600000");
            hbase = new HBaseTestingUtility(conf);

            if (securedCluster) {
                enableSecurity(conf);
                verifyConfiguration(conf);
                hbase.startMiniCluster(RS_COUNT);
                hbase.waitTableEnabled(AccessControlLists.ACL_TABLE_NAME.getName(), 10000);
            } else {
                hbase.startMiniCluster(RS_COUNT);
            }
            updateTestZkQuorum();
            admin = new HBaseAdminWrapper(conf);
        }
    } else {
        if (admin == null) {
            final String argsFileName = securedCluster ? "../../testClusterRealSecured.args" : "../../testClusterRealNonSecured.args";
            if (!Util.isFile(argsFileName)) {
                throw new IllegalStateException("You have to define args file " + argsFileName + " for tests.");
            }

            String[] testArgs = {argsFileName};
            Args args = new TestArgs(testArgs);
            admin = HBaseClient.getAdmin(args);
            conf = admin.getConfiguration();
            RS_COUNT = getServerNameList().size();
        }
    }
    previousBalancerRunning = admin.setBalancerRunning(false, true);
    hConnection = HConnectionManager.createConnection(conf);

    createNamespace(admin, TEST_NAMESPACE);

    USER_RW = User.createUserForTesting(conf, "rwuser", new String[0]);
}
 
Example #3
Source File: TestBase.java    From hbase-tools with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void setUpOnce() throws Exception {
    miniCluster = System.getProperty("cluster.type").equals("mini");
    securedCluster = System.getProperty("cluster.secured").equals("true");
    System.out.println("realCluster - " + !miniCluster);
    System.out.println("securedCluster - " + securedCluster);

    Util.setLoggingThreshold("ERROR");

    if (miniCluster) {
        if (hbase == null) {
            conf = HBaseConfiguration.create(new Configuration(true));
            conf.setInt("hbase.master.info.port", -1);
            conf.set("zookeeper.session.timeout", "3600000");
            conf.set("dfs.client.socket-timeout", "3600000");
            hbase = new HBaseTestingUtility(conf);

            if (securedCluster) {
                enableSecurity(conf);
                verifyConfiguration(conf);
                hbase.startMiniCluster(RS_COUNT);
                hbase.waitTableEnabled(AccessControlLists.ACL_TABLE_NAME.getName(), 10000);
            } else {
                hbase.startMiniCluster(RS_COUNT);
            }
            updateTestZkQuorum();
            admin = new HBaseAdminWrapper(conf);
        }
    } else {
        if (admin == null) {
            final String argsFileName = securedCluster ? "../../testClusterRealSecured.args" : "../../testClusterRealNonSecured.args";
            if (!Util.isFile(argsFileName)) {
                throw new IllegalStateException("You have to define args file " + argsFileName + " for tests.");
            }

            String[] testArgs = {argsFileName};
            Args args = new TestArgs(testArgs);
            admin = HBaseClient.getAdmin(args);
            conf = admin.getConfiguration();
            RS_COUNT = getServerNameList().size();
        }
    }
    previousBalancerRunning = admin.setBalancerRunning(false, true);
    hConnection = HConnectionManager.createConnection(conf);

    createNamespace(admin, TEST_NAMESPACE);

    USER_RW = User.createUserForTesting(conf, "rwuser", new String[0]);
}
 
Example #4
Source File: TestBase.java    From hbase-tools with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void setUpOnce() throws Exception {
    miniCluster = System.getProperty("cluster.type").equals("mini");
    securedCluster = System.getProperty("cluster.secured").equals("true");
    System.out.println("realCluster - " + !miniCluster);
    System.out.println("securedCluster - " + securedCluster);

    Util.setLoggingThreshold("ERROR");

    if (miniCluster) {
        if (hbase == null) {
            conf = HBaseConfiguration.create(new Configuration(true));
            conf.setInt("hbase.master.info.port", -1);
            conf.set("zookeeper.session.timeout", "3600000");
            conf.set("dfs.client.socket-timeout", "3600000");
            hbase = new HBaseTestingUtility(conf);

            if (securedCluster) {
                enableSecurity(conf);
                verifyConfiguration(conf);
                hbase.startMiniCluster(RS_COUNT);
                hbase.waitTableEnabled(AccessControlLists.ACL_TABLE_NAME.getName(), 10000);
            } else {
                hbase.startMiniCluster(RS_COUNT);
            }
            updateTestZkQuorum();
            admin = new HBaseAdminWrapper(conf);
        }
    } else {
        if (admin == null) {
            final String argsFileName = securedCluster ? "../../testClusterRealSecured.args" : "../../testClusterRealNonSecured.args";
            if (!Util.isFile(argsFileName)) {
                throw new IllegalStateException("You have to define args file " + argsFileName + " for tests.");
            }

            String[] testArgs = {argsFileName};
            Args args = new TestArgs(testArgs);
            admin = HBaseClient.getAdmin(args);
            conf = admin.getConfiguration();
            RS_COUNT = getServerNameList().size();
        }
    }
    previousBalancerRunning = admin.setBalancerRunning(false, true);
    hConnection = HConnectionManager.createConnection(conf);

    createNamespace(admin, TEST_NAMESPACE);

    USER_RW = User.createUserForTesting(conf, "rwuser", new String[0]);
}
 
Example #5
Source File: TestBase.java    From hbase-tools with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void setUpOnce() throws Exception {
    miniCluster = System.getProperty("cluster.type").equals("mini");
    securedCluster = System.getProperty("cluster.secured").equals("true");
    System.out.println("realCluster - " + !miniCluster);
    System.out.println("securedCluster - " + securedCluster);

    Util.setLoggingThreshold("ERROR");

    if (miniCluster) {
        if (hbase == null) {
            hbase = new HBaseTestingUtility();
            conf = hbase.getConfiguration();
            conf.set("zookeeper.session.timeout", "3600000");
            conf.set("dfs.client.socket-timeout", "3600000");

            if (securedCluster) {
                hbase.startMiniCluster(RS_COUNT);
                hbase.waitTableEnabled(AccessControlLists.ACL_TABLE_NAME, 30000L);
                admin = new HBaseAdminWrapper(conf);
            } else {
                hbase.startMiniCluster(RS_COUNT);
                admin = hbase.getHBaseAdmin();
            }
        }
    } else {
        if (admin == null) {
            final String argsFileName = securedCluster ? "../../testClusterRealSecured.args" : "../../testClusterRealNonSecured.args";
            if (!Util.isFile(argsFileName)) {
                throw new IllegalStateException("You have to define args file " + argsFileName + " for tests.");
            }

            String[] testArgs = {argsFileName};
            Args args = new TestArgs(testArgs);
            admin = HBaseClient.getAdmin(args);
            conf = admin.getConfiguration();
            RS_COUNT = getServerNameList().size();
        }
    }
    previousBalancerRunning = admin.setBalancerRunning(false, true);
    hConnection = HConnectionManager.createConnection(conf);

    USER_RW = User.createUserForTesting(conf, "rwuser", new String[0]);
}