当前位置: 首页>>代码示例>>Java>>正文


Java User.runAs方法代码示例

本文整理汇总了Java中org.apache.hadoop.hbase.security.User.runAs方法的典型用法代码示例。如果您正苦于以下问题:Java User.runAs方法的具体用法?Java User.runAs怎么用?Java User.runAs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.hadoop.hbase.security.User的用法示例。


在下文中一共展示了User.runAs方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: verifyUserDeniedForDeleteMultipleVersions

import org.apache.hadoop.hbase.security.User; //导入方法依赖的package包/类
private void verifyUserDeniedForDeleteMultipleVersions(final User user, final byte[] row,
    final byte[] q1, final byte[] q2) throws IOException, InterruptedException {
  user.runAs(new PrivilegedExceptionAction<Void>() {
    @Override
    public Void run() throws Exception {
      try (Connection connection = ConnectionFactory.createConnection(conf)) {
        try (Table t = connection.getTable(TEST_TABLE.getTableName())) {
          Delete d = new Delete(row);
          d.addColumns(TEST_FAMILY1, q1);
          d.addColumns(TEST_FAMILY1, q2);
          t.delete(d);
          fail(user.getShortName() + " should not be allowed to delete the row");
        } catch (Exception e) {

        }
      }
      return null;
    }
  });
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:21,代码来源:TestCellACLWithMultipleVersions.java

示例2: verifyUserDeniedForDeleteExactVersion

import org.apache.hadoop.hbase.security.User; //导入方法依赖的package包/类
private void verifyUserDeniedForDeleteExactVersion(final User user, final byte[] row,
    final byte[] q1, final byte[] q2) throws IOException, InterruptedException {
  user.runAs(new PrivilegedExceptionAction<Void>() {
    @Override
    public Void run() throws Exception {
      try (Connection connection = ConnectionFactory.createConnection(conf)) {
        try (Table t = connection.getTable(TEST_TABLE.getTableName())) {
          Delete d = new Delete(row, 127);
          d.addColumns(TEST_FAMILY1, q1);
          d.addColumns(TEST_FAMILY1, q2);
          d.addFamily(TEST_FAMILY2, 129);
          t.delete(d);
          fail(user.getShortName() + " can not do the delete");
        } catch (Exception e) {

        }
      }
      return null;
    }
  });
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:22,代码来源:TestCellACLWithMultipleVersions.java

示例3: verifyUserAllowedforCheckAndDelete

import org.apache.hadoop.hbase.security.User; //导入方法依赖的package包/类
private void verifyUserAllowedforCheckAndDelete(final User user, final byte[] row,
    final byte[] q1, final byte[] value) throws IOException, InterruptedException {
  user.runAs(new PrivilegedExceptionAction<Void>() {
    @Override
    public Void run() throws Exception {
      try (Connection connection = ConnectionFactory.createConnection(conf)) {
        try (Table t = connection.getTable(TEST_TABLE.getTableName())) {
          Delete d = new Delete(row);
          d.addColumn(TEST_FAMILY1, q1, 120);
          t.checkAndDelete(row, TEST_FAMILY1, q1, value, d);
        }
      }
      return null;
    }
  });
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:17,代码来源:TestCellACLWithMultipleVersions.java

示例4: verifyUserDeniedForCheckAndDelete

import org.apache.hadoop.hbase.security.User; //导入方法依赖的package包/类
private void verifyUserDeniedForCheckAndDelete(final User user, final byte[] row,
    final byte[] value) throws IOException, InterruptedException {
  user.runAs(new PrivilegedExceptionAction<Void>() {
    @Override
    public Void run() throws Exception {
      try (Connection connection = ConnectionFactory.createConnection(conf)) {
        try (Table t = connection.getTable(TEST_TABLE.getTableName())) {
          Delete d = new Delete(row);
          d.addColumns(TEST_FAMILY1, TEST_Q1);
          t.checkAndDelete(row, TEST_FAMILY1, TEST_Q1, value, d);
          fail(user.getShortName() + " should not be allowed to do checkAndDelete");
        } catch (Exception e) {
        }
      }
      return null;
    }
  });
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:19,代码来源:TestCellACLWithMultipleVersions.java

示例5: verifyAllowed

import org.apache.hadoop.hbase.security.User; //导入方法依赖的package包/类
/** This fails only in case of ADE or empty list for any of the actions. */
public static void verifyAllowed(User user, AccessTestAction... actions) throws Exception {
  for (AccessTestAction action : actions) {
    try {
      Object obj = user.runAs(action);
      if (obj != null && obj instanceof List<?>) {
        List<?> results = (List<?>) obj;
        if (results != null && results.isEmpty()) {
          fail("Empty non null results from action for user '" + user.getShortName() + "'");
        }
      }
    } catch (AccessDeniedException ade) {
      fail("Expected action to pass for user '" + user.getShortName() + "' but was denied");
    }
  }
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:17,代码来源:SecureTestUtil.java

示例6: verifyIfEmptyList

import org.apache.hadoop.hbase.security.User; //导入方法依赖的package包/类
/** This passes only in case of empty list for all users. */
public static void verifyIfEmptyList(AccessTestAction action, User... users) throws Exception {
  for (User user : users) {
    try {
      Object obj = user.runAs(action);
      if (obj != null && obj instanceof List<?>) {
        List<?> results = (List<?>) obj;
        if (results != null && !results.isEmpty()) {
          fail("Unexpected action results: " +  results + " for user '"
              + user.getShortName() + "'");
        }
      } else {
        fail("Unexpected results for user '" + user.getShortName() + "'");
      }
    } catch (AccessDeniedException ade) {
      fail("Expected action to pass for user '" + user.getShortName() + "' but was denied");
    }
  }
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:20,代码来源:SecureTestUtil.java

示例7: verifyUserDeniedForIncrementMultipleVersions

import org.apache.hadoop.hbase.security.User; //导入方法依赖的package包/类
private void verifyUserDeniedForIncrementMultipleVersions(final User user, final byte[] row,
    final byte[] q1) throws IOException, InterruptedException {
  user.runAs(new PrivilegedExceptionAction<Void>() {
    @Override
    public Void run() throws Exception {
      try (Connection connection = ConnectionFactory.createConnection(conf)) {
        try (Table t = connection.getTable(TEST_TABLE.getTableName())) {
          Increment inc = new Increment(row);
          inc.setTimeRange(0, 127);
          inc.addColumn(TEST_FAMILY1, q1, 2L);
          t.increment(inc);
          fail(user.getShortName() + " cannot do the increment.");
        } catch (Exception e) {

        }
      }
      return null;
    }
  });
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:21,代码来源:TestCellACLWithMultipleVersions.java

示例8: verifyUserDeniedForPutMultipleVersions

import org.apache.hadoop.hbase.security.User; //导入方法依赖的package包/类
private void verifyUserDeniedForPutMultipleVersions(final User user, final byte[] row,
    final byte[] q1, final byte[] q2, final byte[] value) throws IOException,
    InterruptedException {
  user.runAs(new PrivilegedExceptionAction<Void>() {
    @Override
    public Void run() throws Exception {
      try (Connection connection = ConnectionFactory.createConnection(conf)) {
        try (Table t = connection.getTable(TEST_TABLE.getTableName())) {
          Put p = new Put(row);
          // column Q1 covers version at 123 fr which user2 do not have permission
          p.addColumn(TEST_FAMILY1, q1, 124, value);
          p.addColumn(TEST_FAMILY1, q2, value);
          t.put(p);
          fail(user.getShortName() + " cannot do the put.");
        } catch (Exception e) {

        }
      }
      return null;
    }
  });
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:23,代码来源:TestCellACLWithMultipleVersions.java

示例9: testAccessControlClientUserPerms

import org.apache.hadoop.hbase.security.User; //导入方法依赖的package包/类
@Test (timeout=180000)
public void testAccessControlClientUserPerms() throws Exception {
  TableName tname = TableName.valueOf("testAccessControlClientUserPerms");
  createTestTable(tname);
  try {
    final String regex = tname.getNameWithNamespaceInclAsString();
    User testUserPerms = User.createUserForTesting(conf, "testUserPerms", new String[0]);
    assertEquals(0, testUserPerms.runAs(getPrivilegedAction(regex)).size());
    // Grant TABLE ADMIN privs to testUserPerms
    grantOnTable(TEST_UTIL, testUserPerms.getShortName(), tname, null, null, Action.ADMIN);
    List<UserPermission> perms = testUserPerms.runAs(getPrivilegedAction(regex));
    assertNotNull(perms);
    // Superuser, testUserPerms
    assertEquals(2, perms.size());
  } finally {
    deleteTable(TEST_UTIL, tname);
  }
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:19,代码来源:TestAccessController.java

示例10: addRegionServer

import org.apache.hadoop.hbase.security.User; //导入方法依赖的package包/类
public JVMClusterUtil.RegionServerThread addRegionServer(
    final Configuration config, final int index, User user)
throws IOException, InterruptedException {
  return user.runAs(
      new PrivilegedExceptionAction<JVMClusterUtil.RegionServerThread>() {
        public JVMClusterUtil.RegionServerThread run() throws Exception {
          return addRegionServer(config, index);
        }
      });
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:11,代码来源:LocalHBaseCluster.java

示例11: addMaster

import org.apache.hadoop.hbase.security.User; //导入方法依赖的package包/类
public JVMClusterUtil.MasterThread addMaster(
    final Configuration c, final int index, User user)
throws IOException, InterruptedException {
  return user.runAs(
      new PrivilegedExceptionAction<JVMClusterUtil.MasterThread>() {
        public JVMClusterUtil.MasterThread run() throws Exception {
          return addMaster(c, index);
        }
      });
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:11,代码来源:LocalHBaseCluster.java

示例12: verifyIfNull

import org.apache.hadoop.hbase.security.User; //导入方法依赖的package包/类
/** This passes only in case of null for all users. */
public static void verifyIfNull(AccessTestAction  action, User... users) throws Exception {
  for (User user : users) {
    try {
      Object obj = user.runAs(action);
      if (obj != null) {
        fail("Non null results from action for user '" + user.getShortName() + "' : " + obj);
      }
    } catch (AccessDeniedException ade) {
      fail("Expected action to pass for user '" + user.getShortName() + "' but was denied");
    }
  }
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:14,代码来源:SecureTestUtil.java

示例13: obtainToken

import org.apache.hadoop.hbase.security.User; //导入方法依赖的package包/类
/**
 * Obtain and return an authentication token for the current user.
 * @param conn The HBase cluster connection
 * @return the authentication token instance
 */
public static Token<AuthenticationTokenIdentifier> obtainToken(
    final Connection conn, User user) throws IOException, InterruptedException {
  return user.runAs(new PrivilegedExceptionAction<Token<AuthenticationTokenIdentifier>>() {
    @Override
    public Token<AuthenticationTokenIdentifier> run() throws Exception {
      return obtainToken(conn);
    }
  });
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:15,代码来源:TokenUtil.java

示例14: testWALCoprocessorReplay

import org.apache.hadoop.hbase.security.User; //导入方法依赖的package包/类
/**
 * Test WAL replay behavior with WALObserver.
 */
@Test
public void testWALCoprocessorReplay() throws Exception {
  // WAL replay is handled at HRegion::replayRecoveredEdits(), which is
  // ultimately called by HRegion::initialize()
  TableName tableName = TableName.valueOf("testWALCoprocessorReplay");
  final HTableDescriptor htd = getBasic3FamilyHTableDescriptor(tableName);
  MultiVersionConcurrencyControl mvcc = new MultiVersionConcurrencyControl();
  // final HRegionInfo hri =
  // createBasic3FamilyHRegionInfo(Bytes.toString(tableName));
  // final HRegionInfo hri1 =
  // createBasic3FamilyHRegionInfo(Bytes.toString(tableName));
  final HRegionInfo hri = new HRegionInfo(tableName, null, null);

  final Path basedir =
      FSUtils.getTableDir(this.hbaseRootDir, tableName);
  deleteDir(basedir);
  fs.mkdirs(new Path(basedir, hri.getEncodedName()));

  final Configuration newConf = HBaseConfiguration.create(this.conf);

  // WAL wal = new WAL(this.fs, this.dir, this.oldLogDir, this.conf);
  WAL wal = wals.getWAL(UNSPECIFIED_REGION);
  // Put p = creatPutWith2Families(TEST_ROW);
  WALEdit edit = new WALEdit();
  long now = EnvironmentEdgeManager.currentTime();
  // addFamilyMapToWALEdit(p.getFamilyMap(), edit);
  final int countPerFamily = 1000;
  // for (HColumnDescriptor hcd: hri.getTableDesc().getFamilies()) {
  for (HColumnDescriptor hcd : htd.getFamilies()) {
    addWALEdits(tableName, hri, TEST_ROW, hcd.getName(), countPerFamily,
        EnvironmentEdgeManager.getDelegate(), wal, htd, mvcc);
  }
  wal.append(htd, hri, new WALKey(hri.getEncodedNameAsBytes(), tableName, now, mvcc), edit, true);
  // sync to fs.
  wal.sync();

  User user = HBaseTestingUtility.getDifferentUser(newConf,
      ".replay.wal.secondtime");
  user.runAs(new PrivilegedExceptionAction() {
    public Object run() throws Exception {
      Path p = runWALSplit(newConf);
      LOG.info("WALSplit path == " + p);
      FileSystem newFS = FileSystem.get(newConf);
      // Make a new wal for new region open.
      final WALFactory wals2 = new WALFactory(conf, null, currentTest.getMethodName()+"2");
      WAL wal2 = wals2.getWAL(UNSPECIFIED_REGION);;
      HRegion region = HRegion.openHRegion(newConf, FileSystem.get(newConf), hbaseRootDir,
          hri, htd, wal2, TEST_UTIL.getHBaseCluster().getRegionServer(0), null);
      long seqid2 = region.getOpenSeqNum();

      SampleRegionWALObserver cp2 =
        (SampleRegionWALObserver)region.getCoprocessorHost().findCoprocessor(
            SampleRegionWALObserver.class.getName());
      // TODO: asserting here is problematic.
      assertNotNull(cp2);
      assertTrue(cp2.isPreWALRestoreCalled());
      assertTrue(cp2.isPostWALRestoreCalled());
      assertFalse(cp2.isPreWALRestoreDeprecatedCalled());
      assertFalse(cp2.isPostWALRestoreDeprecatedCalled());
      region.close();
      wals2.close();
      return null;
    }
  });
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:69,代码来源:TestWALObserver.java

示例15: testCloseWithFailingFlush

import org.apache.hadoop.hbase.security.User; //导入方法依赖的package包/类
@Test (timeout=60000)
public void testCloseWithFailingFlush() throws Exception {
  final Configuration conf = HBaseConfiguration.create(CONF);
  // Only retry once.
  conf.setInt("hbase.hstore.flush.retries.number", 1);
  final User user =
    User.createUserForTesting(conf, this.name.getMethodName(), new String[]{"foo"});
  // Inject our faulty LocalFileSystem
  conf.setClass("fs.file.impl", FaultyFileSystem.class, FileSystem.class);
  user.runAs(new PrivilegedExceptionAction<Object>() {
    @Override
    public Object run() throws Exception {
      // Make sure it worked (above is sensitive to caching details in hadoop core)
      FileSystem fs = FileSystem.get(conf);
      Assert.assertEquals(FaultyFileSystem.class, fs.getClass());
      FaultyFileSystem ffs = (FaultyFileSystem)fs;
      HRegion region = null;
      try {
        // Initialize region
        region = initHRegion(tableName, name.getMethodName(), conf, COLUMN_FAMILY_BYTES);
        long size = region.getMemstoreSize();
        Assert.assertEquals(0, size);
        // Put one item into memstore.  Measure the size of one item in memstore.
        Put p1 = new Put(row);
        p1.add(new KeyValue(row, COLUMN_FAMILY_BYTES, qual1, 1, (byte[])null));
        region.put(p1);
        // Manufacture an outstanding snapshot -- fake a failed flush by doing prepare step only.
        Store store = region.getStore(COLUMN_FAMILY_BYTES);
        StoreFlushContext storeFlushCtx = store.createFlushContext(12345);
        storeFlushCtx.prepare();
        // Now add two entries to the foreground memstore.
        Put p2 = new Put(row);
        p2.add(new KeyValue(row, COLUMN_FAMILY_BYTES, qual2, 2, (byte[])null));
        p2.add(new KeyValue(row, COLUMN_FAMILY_BYTES, qual3, 3, (byte[])null));
        region.put(p2);
        // Now try close on top of a failing flush.
        region.close();
        fail();
      } catch (IOException dse) {
        // Expected
        LOG.info("Expected DroppedSnapshotException");
      } finally {
        // Make it so all writes succeed from here on out so can close clean
        ffs.fault.set(false);
        region.getWAL().rollWriter(true);
        HRegion.closeHRegion(region);
      }
      return null;
    }
  });
  FileSystem.closeAllForUGI(user.getUGI());
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:53,代码来源:TestHRegion.java


注:本文中的org.apache.hadoop.hbase.security.User.runAs方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。