Java Code Examples for org.apache.hadoop.hbase.util.Bytes#len()

The following examples show how to use org.apache.hadoop.hbase.util.Bytes#len() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: hbase   File: AccessControlUtil.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Validates whether specified user has permission to perform actions on the mentioned table,
 * column family or column qualifier.
 * @param controller RpcController
 * @param protocol the AccessControlService protocol proxy
 * @param tableName Table name, it shouldn't be null or empty.
 * @param columnFamily The column family. Optional argument, can be empty. If empty then
 *          validation will happen at table level.
 * @param columnQualifier The column qualifier. Optional argument, can be empty. If empty then
 *          validation will happen at table and column family level. columnQualifier will not be
 *          considered if columnFamily is passed as null or empty.
 * @param userName User name, it shouldn't be null or empty.
 * @param actions Actions
 * @return true if access allowed, otherwise false
 * @throws ServiceException
 * @deprecated Use {@link Admin#hasUserPermissions(String, List)} instead.
 */
@Deprecated
public static boolean hasPermission(RpcController controller,
    AccessControlService.BlockingInterface protocol, TableName tableName, byte[] columnFamily,
    byte[] columnQualifier, String userName, Permission.Action[] actions)
    throws ServiceException {
  AccessControlProtos.TablePermission.Builder tablePermissionBuilder =
      AccessControlProtos.TablePermission.newBuilder();
  tablePermissionBuilder
      .setTableName(ProtobufUtil.toProtoTableName(tableName));
  if (Bytes.len(columnFamily) > 0) {
    tablePermissionBuilder.setFamily(UnsafeByteOperations.unsafeWrap(columnFamily));
  }
  if (Bytes.len(columnQualifier) > 0) {
    tablePermissionBuilder.setQualifier(UnsafeByteOperations.unsafeWrap(columnQualifier));
  }
  for (Permission.Action a : actions) {
    tablePermissionBuilder.addAction(toPermissionAction(a));
  }
  AccessControlProtos.HasPermissionRequest request = AccessControlProtos.HasPermissionRequest
      .newBuilder().setTablePermission(tablePermissionBuilder)
      .setUserName(ByteString.copyFromUtf8(userName)).build();
  AccessControlProtos.HasPermissionResponse response =
      protocol.hasPermission(controller, request);
  return response.getHasPermission();
}
 
Example 2
Source Project: hbase   File: AccessControlUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * A utility used to get user table permissions based on the column family, column qualifier and
 * user name.
 * @param controller RpcController
 * @param protocol the AccessControlService protocol proxy
 * @param t optional table name
 * @param columnFamily Column family
 * @param columnQualifier Column qualifier
 * @param userName User name, if empty then all user permissions will be retrieved.
 * @throws ServiceException
 * @deprecated Use {@link Admin#getUserPermissions(GetUserPermissionsRequest)} instead.
 */
@Deprecated
public static List<UserPermission> getUserPermissions(RpcController controller,
    AccessControlService.BlockingInterface protocol, TableName t, byte[] columnFamily,
    byte[] columnQualifier, String userName) throws ServiceException {
  AccessControlProtos.GetUserPermissionsRequest.Builder builder =
      AccessControlProtos.GetUserPermissionsRequest.newBuilder();
  if (t != null) {
    builder.setTableName(ProtobufUtil.toProtoTableName(t));
  }
  if (Bytes.len(columnFamily) > 0) {
    builder.setColumnFamily(ByteString.copyFrom(columnFamily));
  }
  if (Bytes.len(columnQualifier) > 0) {
    builder.setColumnQualifier(ByteString.copyFrom(columnQualifier));
  }
  if (!StringUtils.isEmpty(userName)) {
    builder.setUserName(ByteString.copyFromUtf8(userName));
  }

  builder.setType(AccessControlProtos.Permission.Type.Table);
  AccessControlProtos.GetUserPermissionsRequest request = builder.build();
  AccessControlProtos.GetUserPermissionsResponse response =
      protocol.getUserPermissions(controller, request);
  List<UserPermission> perms = new ArrayList<>(response.getUserPermissionCount());
  for (AccessControlProtos.UserPermission perm : response.getUserPermissionList()) {
    perms.add(toUserPermission(perm));
  }
  return perms;
}
 
Example 3
Source Project: hbase   File: Scan.java    License: Apache License 2.0 3 votes vote down vote up
/**
 * Set the start row of the scan.
 * <p>
 * If the specified row does not exist, or the {@code inclusive} is {@code false}, the Scanner
 * will start from the next closest row after the specified row.
 * @param startRow row to start scanner at or after
 * @param inclusive whether we should include the start row when scan
 * @return this
 * @throws IllegalArgumentException if startRow does not meet criteria for a row key (when length
 *           exceeds {@link HConstants#MAX_ROW_LENGTH})
 */
public Scan withStartRow(byte[] startRow, boolean inclusive) {
  if (Bytes.len(startRow) > HConstants.MAX_ROW_LENGTH) {
    throw new IllegalArgumentException("startRow's length must be less than or equal to "
        + HConstants.MAX_ROW_LENGTH + " to meet the criteria" + " for a row key.");
  }
  this.startRow = startRow;
  this.includeStartRow = inclusive;
  return this;
}
 
Example 4
Source Project: hbase   File: Scan.java    License: Apache License 2.0 3 votes vote down vote up
/**
 * Set the stop row of the scan.
 * <p>
 * The scan will include rows that are lexicographically less than (or equal to if
 * {@code inclusive} is {@code true}) the provided stopRow.
 * @param stopRow row to end at
 * @param inclusive whether we should include the stop row when scan
 * @return this
 * @throws IllegalArgumentException if stopRow does not meet criteria for a row key (when length
 *           exceeds {@link HConstants#MAX_ROW_LENGTH})
 */
public Scan withStopRow(byte[] stopRow, boolean inclusive) {
  if (Bytes.len(stopRow) > HConstants.MAX_ROW_LENGTH) {
    throw new IllegalArgumentException("stopRow's length must be less than or equal to "
        + HConstants.MAX_ROW_LENGTH + " to meet the criteria" + " for a row key.");
  }
  this.stopRow = stopRow;
  this.includeStopRow = inclusive;
  return this;
}