gpt4 book ai didi

org.apache.zookeeper.client.ZooKeeperSaslClient类的使用及代码示例

转载 作者:知者 更新时间:2024-03-18 08:07:31 31 4
gpt4 key购买 nike

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

ZooKeeperSaslClient介绍

[英]This class manages SASL authentication for the client. It allows ClientCnxn to authenticate using SASL with a Zookeeper server.
[中]此类管理客户端的SASL身份验证。它允许ClientCnxn通过Zookeeper服务器使用SASL进行身份验证。

代码示例

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

saslToken = createSaslToken(serverToken);
if (saslToken != null) {
  sendSaslPacket(saslToken, cnxn);
    this.getLoginContext() + "' with exception: {}", e);
saslState = SaslState.FAILED;
gotLastPacket = true;

代码示例来源:origin: org.apache.zookeeper/zookeeper

public boolean clientTunneledAuthenticationInProgress() {
  // 1. SASL client is disabled.
  if (!ZooKeeperSaslClient.isEnabled()) {
    return false;
  }
  // 2. SASL login failed.
  if (saslLoginFailed == true) {
    return false;
  }
  // 3. SendThread has not created the authenticating object yet,
  // therefore authentication is (at the earliest stage of being) in progress.
  if (zooKeeperSaslClient == null) {
    return true;
  }
  // 4. authenticating object exists, so ask it for its progress.
  return zooKeeperSaslClient.clientTunneledAuthenticationInProgress();
}

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

if ((isComplete() == false) &&
  (isFailed() == false)) {
  return true;
if (isComplete() || isFailed()) {
  if (gotLastPacket == false) {

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

@Test
public void testSaslConfig() throws Exception {
  ZooKeeper zk = createClient();
  try {
    zk.getChildren("/", false);
    Assert.assertFalse(zk.getSaslClient().
      clientTunneledAuthenticationInProgress());
    Assert.assertEquals(zk.getSaslClient().getSaslState(),
      ZooKeeperSaslClient.SaslState.COMPLETE);
    Assert.assertNotNull(
      javax.security.auth.login.Configuration.getConfiguration().
        getAppConfigurationEntry("MyZookeeperClient"));
    Assert.assertSame(zk.getSaslClient().getLoginContext(),
      "MyZookeeperClient");
  } catch (KeeperException e) {
    Assert.fail("test failed :" + e);
  } finally {
    zk.close();
  }
}

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

if (zooKeeperSaslClient.getSaslState() == ZooKeeperSaslClient.SaslState.INITIAL) {
  try {
    zooKeeperSaslClient.initialize(ClientCnxn.this);
  } catch (SaslException e) {
    LOG.error("SASL authentication with Zookeeper Quorum member failed: " + e);
KeeperState authState = zooKeeperSaslClient.getKeeperState();
if (authState != null) {
  if (authState == KeeperState.AuthFailed) {

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

private byte[] createSaslToken() throws SaslException {
  saslState = SaslState.INTERMEDIATE;
  return createSaslToken(saslToken);
}

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

public void processResult(int rc, String path, Object ctx, byte data[], Stat stat) {
    // processResult() is used by ClientCnxn's sendThread to respond to
    // data[] contains the Zookeeper Server's SASL token.
    // ctx is the ZooKeeperSaslClient object. We use this object's respondToServer() method
    // to reply to the Zookeeper Server's SASL token
    ZooKeeperSaslClient client = ((ClientCnxn)ctx).zooKeeperSaslClient;
    if (client == null) {
      LOG.warn("sasl client was unexpectedly null: cannot respond to Zookeeper server.");
      return;
    }
    byte[] usedata = data;
    if (data != null) {
      LOG.debug("ServerSaslResponseCallback(): saslToken server response: (length="+usedata.length+")");
    }
    else {
      usedata = new byte[0];
      LOG.debug("ServerSaslResponseCallback(): using empty data[] as server response (length="+usedata.length+")");
    }
    client.respondToServer(usedata, (ClientCnxn)ctx);
  }
}

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

public void initialize(ClientCnxn cnxn) throws SaslException {
  if (saslClient == null) {
    saslState = SaslState.FAILED;
    throw new SaslException("saslClient failed to initialize properly: it's null.");
  }
  if (saslState == SaslState.INITIAL) {
    if (saslClient.hasInitialResponse()) {
      sendSaslPacket(cnxn);
    }
    else {
      byte[] emptyToken = new byte[0];
      sendSaslPacket(emptyToken, cnxn);
    }
    saslState = SaslState.INTERMEDIATE;
  }
}

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

public boolean tunnelAuthInProgress() {
  // 1. SASL client is disabled.
  if (!clientConfig.isSaslClientEnabled()) {
    return false;
  }
  // 2. SASL login failed.
  if (saslLoginFailed == true) {
    return false;
  }
  // 3. SendThread has not created the authenticating object yet,
  // therefore authentication is (at the earliest stage of being) in progress.
  if (zooKeeperSaslClient == null) {
    return true;
  }
  // 4. authenticating object exists, so ask it for its progress.
  return zooKeeperSaslClient.clientTunneledAuthenticationInProgress();
}

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

try {
  if (zooKeeperSaslClient != null) {
    zooKeeperSaslClient.shutdown();
  zooKeeperSaslClient = new ZooKeeperSaslClient(SaslServerPrincipal.getServerPrincipal(addr, clientConfig),
    clientConfig);
} catch (LoginException e) {

代码示例来源:origin: org.apache.zookeeper/zookeeper

private void startConnect(InetSocketAddress addr) throws IOException {
  // initializing it for new connection
  saslLoginFailed = false;
  state = States.CONNECTING;
  setName(getName().replaceAll("\\(.*\\)",
      "(" + addr.getHostName() + ":" + addr.getPort() + ")"));
  if (ZooKeeperSaslClient.isEnabled()) {
    try {
      String principalUserName = System.getProperty(
          ZK_SASL_CLIENT_USERNAME, "zookeeper");
      zooKeeperSaslClient =
        new ZooKeeperSaslClient(
            principalUserName+"/"+addr.getHostName());
    } catch (LoginException e) {
      // An authentication error occurred when the SASL client tried to initialize:
      // for Kerberos this means that the client failed to authenticate with the KDC.
      // This is different from an authentication error that occurs during communication
      // with the Zookeeper server, which is handled below.
      LOG.warn("SASL configuration failed: " + e + " Will continue connection to Zookeeper server without "
       + "SASL authentication, if Zookeeper server allows it.");
      eventThread.queueEvent(new WatchedEvent(
       Watcher.Event.EventType.None,
       Watcher.Event.KeeperState.AuthFailed, null));
      saslLoginFailed = true;
    }
  }
  logStartConnect(addr);
  clientCnxnSocket.connect(addr);
}

代码示例来源:origin: org.apache.zookeeper/zookeeper

this.saslClient = createSaslClient(serverPrincipal, clientSection);
} else {

代码示例来源:origin: org.apache.zookeeper/zookeeper

if (zooKeeperSaslClient.getSaslState() == ZooKeeperSaslClient.SaslState.INITIAL) {
  try {
    zooKeeperSaslClient.initialize(ClientCnxn.this);
  } catch (SaslException e) {
    LOG.error("SASL authentication with Zookeeper Quorum member failed: " + e);
KeeperState authState = zooKeeperSaslClient.getKeeperState();
if (authState != null) {
  if (authState == KeeperState.AuthFailed) {

代码示例来源:origin: org.apache.zookeeper/zookeeper

private byte[] createSaslToken() throws SaslException {
  saslState = SaslState.INTERMEDIATE;
  return createSaslToken(saslToken);
}

代码示例来源:origin: org.apache.zookeeper/zookeeper

public void processResult(int rc, String path, Object ctx, byte data[], Stat stat) {
    // processResult() is used by ClientCnxn's sendThread to respond to
    // data[] contains the Zookeeper Server's SASL token.
    // ctx is the ZooKeeperSaslClient object. We use this object's respondToServer() method
    // to reply to the Zookeeper Server's SASL token
    ZooKeeperSaslClient client = ((ClientCnxn)ctx).zooKeeperSaslClient;
    if (client == null) {
      LOG.warn("sasl client was unexpectedly null: cannot respond to Zookeeper server.");
      return;
    }
    byte[] usedata = data;
    if (data != null) {
      LOG.debug("ServerSaslResponseCallback(): saslToken server response: (length="+usedata.length+")");
    }
    else {
      usedata = new byte[0];
      LOG.debug("ServerSaslResponseCallback(): using empty data[] as server response (length="+usedata.length+")");
    }
    client.respondToServer(usedata, (ClientCnxn)ctx);
  }
}

代码示例来源:origin: org.apache.zookeeper/zookeeper

public void initialize(ClientCnxn cnxn) throws SaslException {
  if (saslClient == null) {
    saslState = SaslState.FAILED;
    throw new SaslException("saslClient failed to initialize properly: it's null.");
  }
  if (saslState == SaslState.INITIAL) {
    if (saslClient.hasInitialResponse()) {
      sendSaslPacket(cnxn);
    }
    else {
      byte[] emptyToken = new byte[0];
      sendSaslPacket(emptyToken, cnxn);
    }
    saslState = SaslState.INTERMEDIATE;
  }
}

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

this.saslClient = createSaslClient(serverPrincipal, clientSection);
} else {

代码示例来源:origin: org.apache.zookeeper/zookeeper

saslToken = createSaslToken(serverToken);
if (saslToken != null) {
  sendSaslPacket(saslToken, cnxn);
    this.getLoginContext() + "' with exception: {}", e);
saslState = SaslState.FAILED;
gotLastPacket = true;

代码示例来源:origin: org.apache.zookeeper/zookeeper

if ((isComplete() == false) &&
  (isFailed() == false)) {
  return true;
if (isComplete() || isFailed()) {
  if (gotLastPacket == false) {

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

private void sendSaslPacket(ClientCnxn cnxn) throws SaslException {
  if (LOG.isDebugEnabled()) {
    LOG.debug("ClientCnxn:sendSaslPacket:length="+saslToken.length);
  }
  GetSASLRequest request = new GetSASLRequest();
  request.setToken(createSaslToken());
  SetSASLResponse response = new SetSASLResponse();
  ServerSaslResponseCallback cb = new ServerSaslResponseCallback();
  try {
    cnxn.sendPacket(request,response,cb, ZooDefs.OpCode.sasl);
  } catch (IOException e) {
    throw new SaslException("Failed to send SASL packet to server due " +
     "to IOException:", e);
  }
}

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com