public static void addUserPermission(Configuration conf, UserPermission userPerm, Table t,
    boolean mergeExistingPermissions) throws IOException {
    Permission permission = userPerm.getPermission();
    Permission.Action[] actions = permission.getActions();
    byte[] rowKey = userPermissionRowKey(permission);
    Put p = new Put(rowKey);
    byte[] key = userPermissionKey(userPerm);

    if ((actions == null) || (actions.length == 0)) {
      String msg = "No actions associated with user '" + userPerm.getUser() + "'";
      LOG.warn(msg);
      throw new IOException(msg);
    }

    Set<Permission.Action> actionSet = new TreeSet<Permission.Action>();
    if (mergeExistingPermissions) {
      List<UserPermission> perms = getUserPermissions(conf, rowKey, null, null, null, false);
      UserPermission currentPerm = null;
      for (UserPermission perm : perms) {
        if (userPerm.equalsExceptActions(perm)) {
          currentPerm = perm;
          break;
        }
      }

      if (currentPerm != null && currentPerm.getPermission().getActions() != null) {
        actionSet.addAll(Arrays.asList(currentPerm.getPermission().getActions()));
      }
    }

    // merge current action with new action.
    actionSet.addAll(Arrays.asList(actions));

    // serialize to byte array.
    byte[] value = new byte[actionSet.size()];
    int index = 0;
    for (Permission.Action action : actionSet) {
      value[index++] = action.code();
    }
    p.add(CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY).setRow(p.getRow())
      .setFamily(ACL_LIST_FAMILY).setQualifier(key).setTimestamp(p.getTimestamp()).setType(Type.Put)
      .setValue(value).build());
    if (LOG.isDebugEnabled()) {
      LOG.debug("Writing permission with rowKey " + Bytes.toString(rowKey) + " "
        + Bytes.toString(key) + ": " + Bytes.toStringBinary(value));
    }
    try {
      t.put(p);
    } finally {
      t.close();
    }
  }
Stores a new user permission grant in the access control lists table.
@param conf     the configuration
@param userPerm the details of the permission to be granted
@param t        acl table instance. It is closed upon method return.
@throws IOException in the case of an error accessing the metadata table
hbase-server/src/main/java/org/apache/hadoop/hbase/security/access/PermissionStorage.java