/** * validate a session for a client * * @param clientId * the client to be revalidated * @param timeout * the timeout for which the session is valid * @return * @throws IOException */ void validateSession(ServerCnxn cnxn, long clientId, int timeout) throws IOException { LOG.info("Revalidating client: 0x" + Long.toHexString(clientId)); ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); dos.writeLong(clientId); dos.writeInt(timeout); dos.close(); QuorumPacket qp = new QuorumPacket(Leader.REVALIDATE, -1, baos .toByteArray(), null); pendingRevalidations.put(clientId, cnxn); if (LOG.isTraceEnabled()) { ZooTrace.logTraceMessage(LOG, ZooTrace.SESSION_TRACE_MASK, "To validate session 0x" + Long.toHexString(clientId)); } writePacket(qp, true); }
protected void revalidate(QuorumPacket qp) throws IOException { ByteArrayInputStream bis = new ByteArrayInputStream(qp .getData()); DataInputStream dis = new DataInputStream(bis); long sessionId = dis.readLong(); boolean valid = dis.readBoolean(); ServerCnxn cnxn = pendingRevalidations .remove(sessionId); if (cnxn == null) { LOG.warn("Missing session 0x" + Long.toHexString(sessionId) + " for validation"); } else { zk.finishSessionInit(cnxn, valid); } if (LOG.isTraceEnabled()) { ZooTrace.logTraceMessage(LOG, ZooTrace.SESSION_TRACE_MASK, "Session 0x" + Long.toHexString(sessionId) + " is valid: " + valid); } }
public KeeperException.Code handleAuthentication(ServerCnxn cnxn, byte[] authData) { String id = new String(authData); try { String digest = generateDigest(id); if (digest.equals(superDigest)) { cnxn.addAuthInfo(new Id("super", "")); } cnxn.addAuthInfo(new Id(getScheme(), digest)); return KeeperException.Code.OK; } catch (NoSuchAlgorithmException e) { LOG.error("Missing algorithm",e); } return KeeperException.Code.AUTHFAILED; }
protected void revalidate(QuorumPacket qp) throws IOException { ByteArrayInputStream bis = new ByteArrayInputStream(qp .getData()); DataInputStream dis = new DataInputStream(bis); long sessionId = dis.readLong(); boolean valid = dis.readBoolean(); ServerCnxn cnxn = pendingRevalidations.remove(sessionId); if (cnxn == null) { LOG.warn("Missing session 0x" + Long.toHexString(sessionId) + " for validation"); } else { zk.finishSessionInit(cnxn, valid); } if (LOG.isTraceEnabled()) { ZooTrace.logTraceMessage(LOG, ZooTrace.SESSION_TRACE_MASK, "Session 0x" + Long.toHexString(sessionId) + " is valid: " + valid); } }
@Override public void commandRun() { if (!isZKServerRunning()) { pw.println(ZK_NOT_SERVING); } else { pw.print("Zookeeper version: "); pw.println(Version.getFullVersion()); if (zkServer instanceof ReadOnlyZooKeeperServer) { pw.println("READ-ONLY mode; serving only read-only clients"); } if (len == FourLetterCommands.statCmd) { LOG.info("Stat command output"); pw.println("Clients:"); for(ServerCnxn c : factory.getConnections()){ c.dumpConnectionInfo(pw, true); pw.println(); } pw.println(); } pw.print(zkServer.serverStats().toString()); pw.print("Node count: "); pw.println(zkServer.getZKDatabase().getNodeCount()); } }
@Test(timeout=30000) public void testFourLetterWordsAllDisabledByDefault() throws Exception { stopServer(); ServerCnxn.resetWhiteList(); System.setProperty("zookeeper.4lw.commands.whitelist", "stat"); startServer(); // Default white list for 3.5.x is empty, so all command should fail. verifyAllCommandsFail(); TestableZooKeeper zk = createClient(); verifyAllCommandsFail(); zk.getData("/", true, null); verifyAllCommandsFail(); zk.close(); verifyFuzzyMatch("stat", "Outstanding"); verifyAllCommandsFail(); }
@Test(timeout=30000) public void testFourLetterWordsEnableSomeCommands() throws Exception { stopServer(); ServerCnxn.resetWhiteList(); System.setProperty("zookeeper.4lw.commands.whitelist", "stat, ruok, isro"); startServer(); // stat, ruok and isro are white listed. verifyFuzzyMatch("stat", "Outstanding"); verifyExactMatch("ruok", "imok"); verifyExactMatch("isro", "rw"); // Rest of commands fail. verifyExactMatch("conf", generateExpectedMessage("conf")); verifyExactMatch("cons", generateExpectedMessage("cons")); verifyExactMatch("crst", generateExpectedMessage("crst")); verifyExactMatch("dump", generateExpectedMessage("dump")); verifyExactMatch("envi", generateExpectedMessage("envi")); verifyExactMatch("gtmk", generateExpectedMessage("gtmk")); verifyExactMatch("stmk", generateExpectedMessage("stmk")); verifyExactMatch("srst", generateExpectedMessage("srst")); verifyExactMatch("wchc", generateExpectedMessage("wchc")); verifyExactMatch("wchp", generateExpectedMessage("wchp")); verifyExactMatch("wchs", generateExpectedMessage("wchs")); verifyExactMatch("mntr", generateExpectedMessage("mntr")); }
@Override public void commandRun() { if (zkServer == null) { pw.println(ZK_NOT_SERVING); } else { pw.print("Zookeeper version: "); pw.println(Version.getFullVersion()); if (zkServer instanceof ReadOnlyZooKeeperServer) { pw.println("READ-ONLY mode; serving only read-only clients"); } if (len == FourLetterCommands.statCmd) { LOG.info("Stat command output"); pw.println("Clients:"); for(ServerCnxn c : factory.getConnections()){ c.dumpConnectionInfo(pw, true); pw.println(); } pw.println(); } pw.print(zkServer.serverStats().toString()); pw.print("Node count: "); pw.println(zkServer.getZKDatabase().getNodeCount()); } }
@Override protected void revalidateSession(ServerCnxn cnxn, long sessionId, int sessionTimeout) throws IOException { super.revalidateSession(cnxn, sessionId, sessionTimeout); try { // setowner as the leader itself, unless updated // via the follower handlers setOwner(sessionId, ServerCnxn.me); } catch (SessionExpiredException e) { // this is ok, it just means that the session revalidation failed. } }
public KeeperException.Code handleAuthentication(ServerCnxn cnxn, byte[] authData) { // Should never call this: SASL authentication is negotiated at session initiation. // TODO: consider substituting current implementation of direct ClientCnxn manipulation with // a call to this method (SASLAuthenticationProvider:handleAuthentication()) at session initiation. return KeeperException.Code.AUTHFAILED; }
public KeeperException.Code handleAuthentication(ServerCnxn cnxn, byte[] authData) { String id = cnxn.getRemoteSocketAddress().getAddress().getHostAddress(); cnxn.addAuthInfo(new Id(getScheme(), id)); return KeeperException.Code.OK; }
@Override protected void revalidateSession(ServerCnxn cnxn, long sessionId, int sessionTimeout) throws IOException { if (upgradeableSessionTracker.isLocalSession(sessionId)) { super.revalidateSession(cnxn, sessionId, sessionTimeout); } else { getLearner().validateSession(cnxn, sessionId, sessionTimeout); } }