Package org.apache.accumulo.core.client.security.tokens

Examples of org.apache.accumulo.core.client.security.tokens.PasswordToken


          }
          break;
        case CREATE_USER:
          user = "__CREATE_USER_WITHOUT_PERM_TEST__";
          try {
            test_user_conn.securityOperations().createLocalUser(user, new PasswordToken(password));
            throw new IllegalStateException("Should NOT be able to create a user");
          } catch (AccumuloSecurityException e) {
            if (e.getSecurityErrorCode() != SecurityErrorCode.PERMISSION_DENIED
                || root_conn.securityOperations().authenticateUser(user, new PasswordToken(password)))
              throw e;
          }
          break;
        case DROP_USER:
          user = "__DROP_USER_WITHOUT_PERM_TEST__";
          root_conn.securityOperations().createLocalUser(user, new PasswordToken(password));
          try {
            test_user_conn.securityOperations().dropLocalUser(user);
            throw new IllegalStateException("Should NOT be able to delete a user");
          } catch (AccumuloSecurityException e) {
            if (e.getSecurityErrorCode() != SecurityErrorCode.PERMISSION_DENIED
                || !root_conn.securityOperations().authenticateUser(user, new PasswordToken(password)))
              throw e;
          }
          break;
        case ALTER_USER:
          user = "__ALTER_USER_WITHOUT_PERM_TEST__";
          root_conn.securityOperations().createLocalUser(user, new PasswordToken(password));
          try {
            test_user_conn.securityOperations().changeUserAuthorizations(user, new Authorizations("A", "B"));
            throw new IllegalStateException("Should NOT be able to alter a user");
          } catch (AccumuloSecurityException e) {
            if (e.getSecurityErrorCode() != SecurityErrorCode.PERMISSION_DENIED || !root_conn.securityOperations().getUserAuthorizations(user).isEmpty())
View Full Code Here


          if (root_conn.tableOperations().list().contains(tableName) || !root_conn.tableOperations().list().contains(table2))
            throw new IllegalStateException("Should be able to rename a table");
          break;
        case CREATE_USER:
          user = "__CREATE_USER_WITH_PERM_TEST__";
          test_user_conn.securityOperations().createLocalUser(user, new PasswordToken(password));
          if (!root_conn.securityOperations().authenticateUser(user, new PasswordToken(password)))
            throw new IllegalStateException("Should be able to create a user");
          break;
        case DROP_USER:
          user = "__DROP_USER_WITH_PERM_TEST__";
          root_conn.securityOperations().createLocalUser(user, new PasswordToken(password));
          test_user_conn.securityOperations().dropLocalUser(user);
          if (root_conn.securityOperations().authenticateUser(user, new PasswordToken(password)))
            throw new IllegalStateException("Should be able to delete a user");
          break;
        case ALTER_USER:
          user = "__ALTER_USER_WITH_PERM_TEST__";
          root_conn.securityOperations().createLocalUser(user, new PasswordToken(password));
          test_user_conn.securityOperations().changeUserAuthorizations(user, new Authorizations("A", "B"));
          if (root_conn.securityOperations().getUserAuthorizations(user).isEmpty())
            throw new IllegalStateException("Should be able to alter a user");
          break;
        case SYSTEM:
View Full Code Here

    if (users.contains(tableUserName))
      conn.securityOperations().dropLocalUser(tableUserName);
    if (users.contains(systemUserName))
      conn.securityOperations().dropLocalUser(systemUserName);
   
    PasswordToken sysUserPass = new PasswordToken("sysUser");
    conn.securityOperations().createLocalUser(systemUserName, sysUserPass);
   
    WalkingSecurity.get(state).setTableName(secTableName);
    state.set("rootUserPass", CredentialHelper.extractToken(state.getCredentials()));
   
    WalkingSecurity.get(state).setSysUserName(systemUserName);
    WalkingSecurity.get(state).createUser(systemUserName, sysUserPass);
   
    WalkingSecurity.get(state).changePassword(tableUserName, new PasswordToken(new byte[0]));
   
    WalkingSecurity.get(state).setTabUserName(tableUserName);
   
    for (TablePermission tp : TablePermission.values()) {
      WalkingSecurity.get(state).revokeTablePermission(systemUserName, secTableName, tp);
View Full Code Here

  @Override
  public void createUser(String principal, AuthenticationToken token) throws AccumuloSecurityException {
    try {
      if (!(token instanceof PasswordToken))
        throw new AccumuloSecurityException(principal, SecurityErrorCode.INVALID_TOKEN);
      PasswordToken pt = (PasswordToken) token;
      constructUser(principal, ZKSecurityTool.createPass(pt.getPassword()));
    } catch (KeeperException e) {
      if (e.code().equals(KeeperException.Code.NODEEXISTS))
        throw new AccumuloSecurityException(principal, SecurityErrorCode.USER_EXISTS, e);
      throw new AccumuloSecurityException(principal, SecurityErrorCode.CONNECTION_ERROR, e);
    } catch (InterruptedException e) {
View Full Code Here

 
  @Override
  public void changePassword(String principal, AuthenticationToken token) throws AccumuloSecurityException {
    if (!(token instanceof PasswordToken))
      throw new AccumuloSecurityException(principal, SecurityErrorCode.INVALID_TOKEN);
    PasswordToken pt = (PasswordToken) token;
    if (userExists(principal)) {
      try {
        synchronized (zooCache) {
          zooCache.clear(ZKUserPath + "/" + principal);
          ZooReaderWriter.getRetryingInstance().putPrivatePersistentData(ZKUserPath + "/" + principal, ZKSecurityTool.createPass(pt.getPassword()),
              NodeExistsPolicy.OVERWRITE);
        }
      } catch (KeeperException e) {
        log.error(e, e);
        throw new AccumuloSecurityException(principal, SecurityErrorCode.CONNECTION_ERROR, e);
View Full Code Here

 
  @Override
  public boolean authenticateUser(String principal, AuthenticationToken token) throws AccumuloSecurityException {
    if (!(token instanceof PasswordToken))
      throw new AccumuloSecurityException(principal, SecurityErrorCode.INVALID_TOKEN);
    PasswordToken pt = (PasswordToken) token;
    byte[] pass;
    String zpath = ZKUserPath + "/" + principal;
    pass = zooCache.get(zpath);
    boolean result = ZKSecurityTool.checkPass(pt.getPassword(), pass);
    if (!result) {
      zooCache.clear(zpath);
      pass = zooCache.get(zpath);
      result = ZKSecurityTool.checkPass(pt.getPassword(), pass);
    }
    return result;
  }
View Full Code Here

    for (int i = 0; i < 9 && !success; i++) {
      try {
        exec("insert a b c d -l foo", false, "does not have authorization", true, new ErrorMessageCallback() {
          public String getErrorMessage() {
            try {
              Connector c = new ZooKeeperInstance(cluster.getInstanceName(), cluster.getZooKeepers()).getConnector("root", new PasswordToken(secret));
              return "Current auths for root are: " + c.securityOperations().getUserAuthorizations("root").toString();
            } catch (Exception e) {
              return "Could not check authorizations";
            }
          }
        });
        success = true;
      } catch (AssertionError e) {
        Thread.sleep(200);
      }
    }
    // If we still couldn't do it, try again and let it fail
    if (!success) {
      exec("insert a b c d -l foo", false, "does not have authorization", true, new ErrorMessageCallback() {
        public String getErrorMessage() {
          try {
            Connector c = new ZooKeeperInstance(cluster.getInstanceName(), cluster.getZooKeepers()).getConnector("root", new PasswordToken(secret));
            return "Current auths for root are: " + c.securityOperations().getUserAuthorizations("root").toString();
          } catch (Exception e) {
            return "Could not check authorizations";
          }
        }
View Full Code Here

    for (int i = 0; i < 6; i++) {
      exec("insert " + i + " cf cq value", true);
    }

    ZooKeeperInstance instance = new ZooKeeperInstance(cluster.getInstanceName(), cluster.getZooKeepers());
    Connector connector = instance.getConnector("root", new PasswordToken(secret));
    final Scanner s = connector.createScanner(table, Constants.NO_AUTHS);
    IteratorSetting cfg = new IteratorSetting(30, SlowIterator.class);
    cfg.addOption("sleepTime", "500");
    s.addScanIterator(cfg);
View Full Code Here

    return getFiles(tableId).size();
  }
 
  private String getTableId(String tableName) throws Exception {
    ZooKeeperInstance zki = new ZooKeeperInstance(cluster.getInstanceName(), cluster.getZooKeepers());
    Connector conn = zki.getConnector("root", new PasswordToken(secret));
   
    for (int i = 0; i < 5; i++) {
      Map<String,String> nameToId = conn.tableOperations().tableIdMap();
      if (nameToId.containsKey(tableName)) {
        return nameToId.get(tableName);
View Full Code Here

  }

  @Test(timeout = 5 * 60 * 1000)
  public void test() throws Exception {
    ZooKeeperInstance zk = new ZooKeeperInstance(cluster.getInstanceName(), cluster.getZooKeepers());
    Connector c = zk.getConnector("root", new PasswordToken(secret));
    for (int i = 0; i < 20; i++) {
      final String tableName = testName.getMethodName() + i;
      log.debug("Creating " + tableName);
      c.tableOperations().create(tableName);
      log.debug("Deleting rows from " + tableName);
View Full Code Here

TOP

Related Classes of org.apache.accumulo.core.client.security.tokens.PasswordToken

Copyright © 2018 www.massapicom. 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.