org.apache.accumulo.server.security.handler.ZKAuthenticator类的使用及代码示例

x33g5p2x  于2022-02-05 转载在 其他  
字(9.9k)|赞(0)|评价(0)|浏览(101)

本文整理了Java中org.apache.accumulo.server.security.handler.ZKAuthenticator类的一些代码示例,展示了ZKAuthenticator类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZKAuthenticator类的具体详情如下:
包路径:org.apache.accumulo.server.security.handler.ZKAuthenticator
类名称:ZKAuthenticator

ZKAuthenticator介绍

暂无

代码示例

代码示例来源:origin: apache/accumulo

public static synchronized Authenticator getInstance() {
 if (zkAuthenticatorInstance == null)
  zkAuthenticatorInstance = new ZKAuthenticator();
 return zkAuthenticatorInstance;
}

代码示例来源:origin: apache/accumulo

@Override
public void initializeSecurity(String principal, byte[] token) {
 try {
  // remove old settings from zookeeper first, if any
  IZooReaderWriter zoo = context.getZooReaderWriter();
  synchronized (zooCache) {
   zooCache.clear();
   if (zoo.exists(ZKUserPath)) {
    zoo.recursiveDelete(ZKUserPath, NodeMissingPolicy.SKIP);
    log.info("Removed {}/ from zookeeper", ZKUserPath);
   }
   // prep parent node of users with root username
   zoo.putPersistentData(ZKUserPath, principal.getBytes(UTF_8), NodeExistsPolicy.FAIL);
   constructUser(principal, ZKSecurityTool.createPass(token));
  }
 } catch (KeeperException | AccumuloException | InterruptedException e) {
  log.error("{}", e.getMessage(), e);
  throw new RuntimeException(e);
 }
}

代码示例来源:origin: apache/accumulo

protected static Authenticator getAuthenticator(ServerContext context, boolean initialize) {
 Authenticator toRet = Property.createInstanceFromPropertyName(context.getConfiguration(),
   Property.INSTANCE_SECURITY_AUTHENTICATOR, Authenticator.class,
   ZKAuthenticator.getInstance());
 toRet.initialize(context, initialize);
 return toRet;
}

代码示例来源:origin: apache/accumulo

@Override
public synchronized boolean userExists(String user) {
 user = Base64.getEncoder().encodeToString(user.getBytes(UTF_8));
 return zkAuthenticator.userExists(user);
}

代码示例来源:origin: apache/accumulo

@Override
public Set<String> listUsers() {
 Set<String> base64Users = zkAuthenticator.listUsers();
 Set<String> readableUsers = new HashSet<>();
 for (String base64User : base64Users) {
  readableUsers.add(new String(Base64.getDecoder().decode(base64User), UTF_8));
 }
 return readableUsers;
}

代码示例来源:origin: apache/accumulo

@Override
public synchronized void dropUser(String user) throws AccumuloSecurityException {
 final String encodedUser = Base64.getEncoder().encodeToString(user.getBytes(UTF_8));
 try {
  zkAuthenticator.dropUser(encodedUser);
 } catch (AccumuloSecurityException e) {
  throw new AccumuloSecurityException(user, e.asThriftException().getCode(), e.getCause());
 }
}

代码示例来源:origin: apache/accumulo

@Override
public void initialize(ServerContext context, boolean initialize) {
 this.context = context;
 zooCache = new ZooCache(context.getZooReaderWriter(), null);
 impersonation = new UserImpersonation(context.getConfiguration());
 zkAuthenticator.initialize(context, initialize);
 zkUserPath = Constants.ZROOT + "/" + context.getInstanceID() + "/users";
}

代码示例来源:origin: apache/accumulo

@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);
    context.getZooReaderWriter().putPrivatePersistentData(ZKUserPath + "/" + principal,
      ZKSecurityTool.createPass(pt.getPassword()), NodeExistsPolicy.OVERWRITE);
   }
  } catch (KeeperException e) {
   log.error("{}", e.getMessage(), e);
   throw new AccumuloSecurityException(principal, SecurityErrorCode.CONNECTION_ERROR, e);
  } catch (InterruptedException e) {
   log.error("{}", e.getMessage(), e);
   throw new RuntimeException(e);
  } catch (AccumuloException e) {
   log.error("{}", e.getMessage(), e);
   throw new AccumuloSecurityException(principal, SecurityErrorCode.DEFAULT_SECURITY_ERROR, e);
  }
 } else
  // user doesn't exist
  throw new AccumuloSecurityException(principal, SecurityErrorCode.USER_DOESNT_EXIST);
}

代码示例来源:origin: org.apache.accumulo/accumulo-server-base

@Override
public Set<String> listUsers() throws AccumuloSecurityException {
 Set<String> base64Users = zkAuthenticator.listUsers();
 Set<String> readableUsers = new HashSet<>();
 for (String base64User : base64Users) {
  readableUsers.add(new String(Base64.decodeBase64(base64User), UTF_8));
 }
 return readableUsers;
}

代码示例来源:origin: org.apache.accumulo/accumulo-server-base

@Override
public synchronized void dropUser(String user) throws AccumuloSecurityException {
 final String encodedUser = Base64.encodeBase64String(user.getBytes(UTF_8));
 try {
  zkAuthenticator.dropUser(encodedUser);
 } catch (AccumuloSecurityException e) {
  throw new AccumuloSecurityException(user, e.asThriftException().getCode(), e.getCause());
 }
}

代码示例来源:origin: org.apache.accumulo/accumulo-server-base

@Override
public void initialize(String instanceId, boolean initialize) {
 zkAuthenticator.initialize(instanceId, initialize);
 zkUserPath = Constants.ZROOT + "/" + instanceId + "/users";
}

代码示例来源:origin: apache/accumulo

@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) {
  log.error("{}", e.getMessage(), e);
  throw new RuntimeException(e);
 } catch (AccumuloException e) {
  log.error("{}", e.getMessage(), e);
  throw new AccumuloSecurityException(principal, SecurityErrorCode.DEFAULT_SECURITY_ERROR, e);
 }
}

代码示例来源:origin: org.apache.accumulo/accumulo-server-base

@Override
public synchronized boolean userExists(String user) throws AccumuloSecurityException {
 user = Base64.encodeBase64String(user.getBytes(UTF_8));
 return zkAuthenticator.userExists(user);
}

代码示例来源:origin: org.apache.accumulo/accumulo-server

protected static Authenticator getAuthenticator(String instanceId, boolean initialize) {
 Authenticator toRet = Master.createInstanceFromPropertyName(ServerConfiguration.getSiteConfiguration(), Property.INSTANCE_SECURITY_AUTHENTICATOR,
   Authenticator.class, ZKAuthenticator.getInstance());
 toRet.initialize(instanceId, initialize);
 return toRet;
}

代码示例来源:origin: org.apache.accumulo/accumulo-server

public static synchronized Authenticator getInstance() {
 if (zkAuthenticatorInstance == null)
  zkAuthenticatorInstance = new ZKAuthenticator();
 return zkAuthenticatorInstance;
}

代码示例来源:origin: org.apache.accumulo/accumulo-server

@Override
public void initializeSecurity(TCredentials credentials, String principal, byte[] token) throws AccumuloSecurityException {
 try {
  // remove old settings from zookeeper first, if any
  IZooReaderWriter zoo = ZooReaderWriter.getRetryingInstance();
  synchronized (zooCache) {
   zooCache.clear();
   if (zoo.exists(ZKUserPath)) {
    zoo.recursiveDelete(ZKUserPath, NodeMissingPolicy.SKIP);
    log.info("Removed " + ZKUserPath + "/" + " from zookeeper");
   }
   // prep parent node of users with root username
   zoo.putPersistentData(ZKUserPath, principal.getBytes(UTF_8), NodeExistsPolicy.FAIL);
   constructUser(principal, ZKSecurityTool.createPass(token));
  }
 } catch (KeeperException e) {
  log.error(e, e);
  throw new RuntimeException(e);
 } catch (InterruptedException e) {
  log.error(e, e);
  throw new RuntimeException(e);
 } catch (AccumuloException e) {
  log.error(e, e);
  throw new RuntimeException(e);
 }
}

代码示例来源:origin: org.apache.accumulo/accumulo-server

@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);
  } catch (InterruptedException e) {
   log.error(e, e);
   throw new RuntimeException(e);
  } catch (AccumuloException e) {
   log.error(e, e);
   throw new AccumuloSecurityException(principal, SecurityErrorCode.DEFAULT_SECURITY_ERROR, e);
  }
 } else
  throw new AccumuloSecurityException(principal, SecurityErrorCode.USER_DOESNT_EXIST); // user doesn't exist
}

代码示例来源:origin: org.apache.accumulo/accumulo-server-base

protected static Authenticator getAuthenticator(String instanceId, boolean initialize) {
 Authenticator toRet = SiteConfiguration.getInstance().instantiateClassProperty(
   Property.INSTANCE_SECURITY_AUTHENTICATOR, Authenticator.class,
   ZKAuthenticator.getInstance());
 toRet.initialize(instanceId, initialize);
 return toRet;
}

代码示例来源:origin: org.apache.accumulo/accumulo-server-base

public static synchronized Authenticator getInstance() {
 if (zkAuthenticatorInstance == null)
  zkAuthenticatorInstance = new ZKAuthenticator();
 return zkAuthenticatorInstance;
}

代码示例来源:origin: org.apache.accumulo/accumulo-server-base

@Override
public void initializeSecurity(TCredentials credentials, String principal, byte[] token)
  throws AccumuloSecurityException {
 try {
  // remove old settings from zookeeper first, if any
  IZooReaderWriter zoo = ZooReaderWriter.getInstance();
  synchronized (zooCache) {
   zooCache.clear();
   if (zoo.exists(ZKUserPath)) {
    zoo.recursiveDelete(ZKUserPath, NodeMissingPolicy.SKIP);
    log.info("Removed " + ZKUserPath + "/" + " from zookeeper");
   }
   // prep parent node of users with root username
   zoo.putPersistentData(ZKUserPath, principal.getBytes(UTF_8), NodeExistsPolicy.FAIL);
   constructUser(principal, ZKSecurityTool.createPass(token));
  }
 } catch (KeeperException e) {
  log.error("{}", e.getMessage(), e);
  throw new RuntimeException(e);
 } catch (InterruptedException e) {
  log.error("{}", e.getMessage(), e);
  throw new RuntimeException(e);
 } catch (AccumuloException e) {
  log.error("{}", e.getMessage(), e);
  throw new RuntimeException(e);
 }
}

相关文章