Examples of TablePermission


Examples of org.apache.accumulo.core.security.TablePermission

  @Override
  public void visit(State state, Properties props) throws Exception {
    Connector conn = state.getInstance().getConnector(WalkingSecurity.get(state).getTabUserName(), WalkingSecurity.get(state).getTabToken());
   
    String action = props.getProperty("action", "_random");
    TablePermission tp;
    if ("_random".equalsIgnoreCase(action)) {
      Random r = new Random();
      tp = TablePermission.values()[r.nextInt(TablePermission.values().length)];
    } else {
      tp = TablePermission.valueOf(action);
View Full Code Here

Examples of org.apache.accumulo.core.security.TablePermission

          return;
      }
      throw new AccumuloException("Unexpected exception!", ae);
    }
    String action = props.getProperty("action", "_random");
    TablePermission tp;
    if ("_random".equalsIgnoreCase(action)) {
      Random r = new Random();
      tp = TablePermission.values()[r.nextInt(TablePermission.values().length)];
    } else {
      tp = TablePermission.valueOf(action);
View Full Code Here

Examples of org.apache.accumulo.core.security.TablePermission

  @Override
  public void visit(State state, Properties props) throws Exception {
    Connector conn = state.getInstance().getConnector(WalkingSecurity.get(state).getTabUserName(), WalkingSecurity.get(state).getTabToken());
   
    String action = props.getProperty("action", "_random");
    TablePermission tp;
    if ("_random".equalsIgnoreCase(action)) {
      Random r = new Random();
      tp = TablePermission.values()[r.nextInt(TablePermission.values().length)];
    } else {
      tp = TablePermission.valueOf(action);
View Full Code Here

Examples of org.apache.accumulo.core.security.TablePermission

    EnumSet<TablePermission> more = EnumSet.allOf(TablePermission.class);
    more.removeAll(perms);
   
    if (rand.nextBoolean() && more.size() > 0) {
      List<TablePermission> moreList = new ArrayList<TablePermission>(more);
      TablePermission choice = moreList.get(rand.nextInt(moreList.size()));
      log.debug("adding permission " + choice);
      conn.securityOperations().grantTablePermission(userName, tableName, choice);
    } else {
      if (perms.size() > 0) {
        List<TablePermission> permList = new ArrayList<TablePermission>(perms);
        TablePermission choice = permList.get(rand.nextInt(permList.size()));
        log.debug("removing permission " + choice);
        conn.securityOperations().revokeTablePermission(userName, tableName, choice);
      }
    }
  }
View Full Code Here

Examples of org.apache.accumulo.core.security.TablePermission

      target = WalkingSecurity.get(state).getSysUserName();
   
    boolean exists = WalkingSecurity.get(state).userExists(target);
    boolean tableExists = WalkingSecurity.get(state).getTableExists();
   
    TablePermission tabPerm;
    if (perm.equals("random")) {
      Random r = new Random();
      int i = r.nextInt(TablePermission.values().length);
      tabPerm = TablePermission.values()[i];
    } else
      tabPerm = TablePermission.valueOf(perm);
    String tableName = WalkingSecurity.get(state).getTableName();
    boolean hasPerm = WalkingSecurity.get(state).hasTablePermission(target, tableName, tabPerm);
    boolean canGive;
    String sourceUser;
    AuthenticationToken sourceToken;
    if ("system".equals(sourceUserProp)) {
      sourceUser = WalkingSecurity.get(state).getSysUserName();
      sourceToken = WalkingSecurity.get(state).getSysToken();
    } else if ("table".equals(sourceUserProp)) {
      sourceUser = WalkingSecurity.get(state).getTabUserName();
      sourceToken = WalkingSecurity.get(state).getTabToken();
    } else {
      sourceUser = state.getUserName();
      sourceToken = state.getToken();
    }
    Connector conn = state.getInstance().getConnector(sourceUser, sourceToken);
   
    canGive = WalkingSecurity.get(state).canGrantTable(CredentialHelper.create(sourceUser, sourceToken, state.getInstance().getInstanceID()), target, WalkingSecurity.get(state).getTableName());

    // toggle
    if (!"take".equals(action) && !"give".equals(action)) {
      try {
        boolean res;
        if (hasPerm != (res = state.getConnector().securityOperations().hasTablePermission(target, tableName, tabPerm)))
          throw new AccumuloException("Test framework and accumulo are out of sync for user " + conn.whoami() + " for perm " + tabPerm.name()
              + " with local vs. accumulo being " + hasPerm + " " + res);
       
        if (hasPerm)
          action = "take";
        else
View Full Code Here

Examples of org.apache.accumulo.core.security.TablePermission

      target = SecurityHelper.getSysUserName(state);
   
    boolean exists = SecurityHelper.getTabUserExists(state);
    boolean tableExists = SecurityHelper.getTableExists(state);
   
    TablePermission tabPerm;
    if (perm.equals("random")) {
      Random r = new Random();
      int i = r.nextInt(TablePermission.values().length);
      tabPerm = TablePermission.values()[i];
    } else
      tabPerm = TablePermission.valueOf(perm);
   
    boolean hasPerm = SecurityHelper.getTabPerm(state, target, tabPerm);
    boolean canGive;
    if ("system".equals(sourceUser)) {
      conn = SecurityHelper.getSystemConnector(state);
      canGive = SecurityHelper.getSysPerm(state, SecurityHelper.getSysUserName(state), SystemPermission.ALTER_USER)
          || SecurityHelper.getTabPerm(state, SecurityHelper.getSysUserName(state), TablePermission.GRANT);
    } else if ("table".equals(sourceUser)) {
      conn = state.getInstance().getConnector(SecurityHelper.getTabUserName(state), SecurityHelper.getTabUserPass(state));
      canGive = SecurityHelper.getTabPerm(state, SecurityHelper.getTabUserName(state), TablePermission.GRANT);
    } else {
      conn = state.getConnector();
      canGive = true;
    }
   
    // toggle
    if (!"take".equals(action) && !"give".equals(action)) {
      try {
        boolean res;
        if (hasPerm != (res = state.getConnector().securityOperations().hasTablePermission(target, SecurityHelper.getTableName(state), tabPerm)))
          throw new AccumuloException("Test framework and accumulo are out of sync for user " + conn.whoami() + " for perm " + tabPerm.name()
              + " with local vs. accumulo being " + hasPerm + " " + res);
       
        if (hasPerm)
          action = "take";
        else
          action = "give";
      } catch (AccumuloSecurityException ae) {
        switch (ae.getErrorCode()) {
          case USER_DOESNT_EXIST:
            if (exists)
              throw new AccumuloException("Framework and Accumulo are out of sync, we think user exists", ae);
            else
              return;
          case TABLE_DOESNT_EXIST:
            if (tabExists)
              throw new AccumuloException(conn.whoami(), ae);
            else
              return;
          default:
            throw ae;
        }
      }
    }
   
    if ("take".equals(action)) {
      try {
        conn.securityOperations().revokeTablePermission(target, SecurityHelper.getTableName(state), tabPerm);
      } catch (AccumuloSecurityException ae) {
        switch (ae.getErrorCode()) {
          case GRANT_INVALID:
            if (tabPerm.equals(SystemPermission.GRANT))
              return;
          case PERMISSION_DENIED:
            if (canGive)
              throw new AccumuloException("Test user failed to give permission when it should have worked", ae);
            return;
          case USER_DOESNT_EXIST:
            if (exists)
              throw new AccumuloException("Table user doesn't exist and they SHOULD.", ae);
            return;
          case TABLE_DOESNT_EXIST:
            if (tableExists)
              throw new AccumuloException("Table doesn't exist but it should", ae);
            return;
          default:
            throw new AccumuloException("Got unexpected exception", ae);
        }
      }
      SecurityHelper.setTabPerm(state, target, tabPerm, false);
    } else if ("give".equals(action)) {
      try {
        conn.securityOperations().grantTablePermission(target, SecurityHelper.getTableName(state), tabPerm);
      } catch (AccumuloSecurityException ae) {
        switch (ae.getErrorCode()) {
          case GRANT_INVALID:
            if (tabPerm.equals(SystemPermission.GRANT))
              return;
            throw new AccumuloException("Got a grant invalid on non-System.GRANT option", ae);
          case PERMISSION_DENIED:
            if (canGive)
              throw new AccumuloException("Test user failed to give permission when it should have worked", ae);
View Full Code Here

Examples of org.apache.accumulo.core.security.TablePermission

          return;
      }
      throw new AccumuloException("Unexpected exception!", ae);
    }
    String action = props.getProperty("action", "_random");
    TablePermission tp;
    if ("_random".equalsIgnoreCase(action)) {
      Random r = new Random();
      tp = TablePermission.values()[r.nextInt(TablePermission.values().length)];
    } else {
      tp = TablePermission.valueOf(action);
View Full Code Here

Examples of org.apache.accumulo.core.security.TablePermission

    EnumSet<TablePermission> more = EnumSet.allOf(TablePermission.class);
    more.removeAll(perms);
   
    if (rand.nextBoolean() && more.size() > 0) {
      List<TablePermission> moreList = new ArrayList<TablePermission>(more);
      TablePermission choice = moreList.get(rand.nextInt(moreList.size()));
      log.debug("adding permission " + choice);
      conn.securityOperations().grantTablePermission(userName, tableName, choice);
    } else {
      if (perms.size() > 0) {
        List<TablePermission> permList = new ArrayList<TablePermission>(perms);
        TablePermission choice = permList.get(rand.nextInt(permList.size()));
        log.debug("removing permission " + choice);
        conn.securityOperations().revokeTablePermission(userName, tableName, choice);
      }
    }
  }
View Full Code Here

Examples of org.apache.hadoop.hbase.security.access.TablePermission

  public static TablePermission toTablePermission(AccessControlProtos.Permission proto) {
    if(proto.getType() == AccessControlProtos.Permission.Type.Global) {
      AccessControlProtos.GlobalPermission perm = proto.getGlobalPermission();
      List<Permission.Action> actions = toPermissionActions(perm.getActionList());

      return new TablePermission(null, null, null,
          actions.toArray(new Permission.Action[actions.size()]));
    }
    if(proto.getType() == AccessControlProtos.Permission.Type.Namespace) {
      AccessControlProtos.NamespacePermission perm = proto.getNamespacePermission();
      List<Permission.Action> actions = toPermissionActions(perm.getActionList());

      if(!proto.hasNamespacePermission()) {
        throw new IllegalStateException("Namespace must not be empty in NamespacePermission");
      }
      String namespace = perm.getNamespaceName().toStringUtf8();
      return new TablePermission(namespace, actions.toArray(new Permission.Action[actions.size()]));
    }
    if(proto.getType() == AccessControlProtos.Permission.Type.Table) {
      AccessControlProtos.TablePermission perm = proto.getTablePermission();
      List<Permission.Action> actions = toPermissionActions(perm.getActionList());

      byte[] qualifier = null;
      byte[] family = null;
      TableName table = null;

      if (!perm.hasTableName()) {
        throw new IllegalStateException("TableName cannot be empty");
      }
      table = ProtobufUtil.toTableName(perm.getTableName());

      if (perm.hasFamily()) family = perm.getFamily().toByteArray();
      if (perm.hasQualifier()) qualifier = perm.getQualifier().toByteArray();

      return new TablePermission(table, family, qualifier,
          actions.toArray(new Permission.Action[actions.size()]));
    }
    throw new IllegalStateException("Unrecognize Perm Type: "+proto.getType());
  }
View Full Code Here

Examples of org.apache.hadoop.hbase.security.access.TablePermission

   * @return the protobuf Permission
   */
  public static AccessControlProtos.Permission toPermission(Permission perm) {
    AccessControlProtos.Permission.Builder ret = AccessControlProtos.Permission.newBuilder();
    if (perm instanceof TablePermission) {
      TablePermission tablePerm = (TablePermission)perm;
      if(tablePerm.hasNamespace()) {
        ret.setType(AccessControlProtos.Permission.Type.Namespace);

        AccessControlProtos.NamespacePermission.Builder builder =
            AccessControlProtos.NamespacePermission.newBuilder();
        builder.setNamespaceName(ByteString.copyFromUtf8(tablePerm.getNamespace()));
        for (Permission.Action a : perm.getActions()) {
          builder.addAction(toPermissionAction(a));
        }
        ret.setNamespacePermission(builder);
      } else if (tablePerm.hasTable()) {
        ret.setType(AccessControlProtos.Permission.Type.Table);

        AccessControlProtos.TablePermission.Builder builder =
            AccessControlProtos.TablePermission.newBuilder();
        builder.setTableName(ProtobufUtil.toProtoTableName(tablePerm.getTableName()));
        if (tablePerm.hasFamily()) {
          builder.setFamily(ByteString.copyFrom(tablePerm.getFamily()));
        }
        if (tablePerm.hasQualifier()) {
          builder.setQualifier(ByteString.copyFrom(tablePerm.getQualifier()));
        }
        for (Permission.Action a : perm.getActions()) {
          builder.addAction(toPermissionAction(a));
        }
        ret.setTablePermission(builder);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.