Search in sources :

Example 1 with AuthPacket

use of org.apache.zookeeper_voltpatches.proto.AuthPacket in project voltdb by VoltDB.

the class AuthPacket method equals.

@Override
public boolean equals(Object peer_) {
    if (!(peer_ instanceof AuthPacket)) {
        return false;
    }
    if (peer_ == this) {
        return true;
    }
    AuthPacket peer = (AuthPacket) peer_;
    boolean ret = false;
    ret = (type == peer.type);
    if (!ret)
        return ret;
    ret = scheme.equals(peer.scheme);
    if (!ret)
        return ret;
    ret = org.apache.jute_voltpatches.Utils.bufEquals(auth, peer.auth);
    if (!ret)
        return ret;
    return ret;
}
Also used : AuthPacket(org.apache.zookeeper_voltpatches.proto.AuthPacket)

Example 2 with AuthPacket

use of org.apache.zookeeper_voltpatches.proto.AuthPacket in project voltdb by VoltDB.

the class AuthPacket method compareTo.

public int compareTo(Object peer_) throws ClassCastException {
    if (!(peer_ instanceof AuthPacket)) {
        throw new ClassCastException("Comparing different types of records.");
    }
    AuthPacket peer = (AuthPacket) peer_;
    int ret = 0;
    ret = (type == peer.type) ? 0 : ((type < peer.type) ? -1 : 1);
    if (ret != 0)
        return ret;
    ret = scheme.compareTo(peer.scheme);
    if (ret != 0)
        return ret;
    {
        byte[] my = auth;
        byte[] ur = peer.auth;
        ret = org.apache.jute_voltpatches.Utils.compareBytes(my, 0, my.length, ur, 0, ur.length);
    }
    if (ret != 0)
        return ret;
    return ret;
}
Also used : AuthPacket(org.apache.zookeeper_voltpatches.proto.AuthPacket)

Example 3 with AuthPacket

use of org.apache.zookeeper_voltpatches.proto.AuthPacket in project voltdb by VoltDB.

the class ClientCnxn method addAuthInfo.

public void addAuthInfo(String scheme, byte[] auth) {
    if (!zooKeeper.state.isAlive()) {
        return;
    }
    authInfo.add(new AuthData(scheme, auth));
    queuePacket(new RequestHeader(-4, OpCode.auth), null, new AuthPacket(0, scheme, auth), null, null, null, null, null, null);
}
Also used : AuthPacket(org.apache.zookeeper_voltpatches.proto.AuthPacket) RequestHeader(org.apache.zookeeper_voltpatches.proto.RequestHeader)

Example 4 with AuthPacket

use of org.apache.zookeeper_voltpatches.proto.AuthPacket in project voltdb by VoltDB.

the class NIOServerCnxn method readRequest.

private void readRequest() throws IOException {
    // We have the request, now process and setup for next
    InputStream bais = new ByteBufferInputStream(incomingBuffer);
    BinaryInputArchive bia = BinaryInputArchive.getArchive(bais);
    RequestHeader h = new RequestHeader();
    h.deserialize(bia, "header");
    // Through the magic of byte buffers, txn will not be
    // pointing
    // to the start of the txn
    incomingBuffer = incomingBuffer.slice();
    if (h.getType() == OpCode.auth) {
        AuthPacket authPacket = new AuthPacket();
        ZooKeeperServer.byteBuffer2Record(incomingBuffer, authPacket);
        String scheme = authPacket.getScheme();
        AuthenticationProvider ap = ProviderRegistry.getProvider(scheme);
        if (ap == null || (ap.handleAuthentication(this, authPacket.getAuth()) != KeeperException.Code.OK)) {
            if (ap == null) {
                LOG.warn("No authentication provider for scheme: " + scheme + " has " + ProviderRegistry.listProviders());
            } else {
                LOG.warn("Authentication failed for scheme: " + scheme);
            }
            // send a response...
            ReplyHeader rh = new ReplyHeader(h.getXid(), 0, KeeperException.Code.AUTHFAILED.intValue());
            sendResponse(rh, null, null);
            // ... and close connection
            sendCloseSession();
            disableRecv();
        } else {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Authentication succeeded for scheme: " + scheme);
            }
            ReplyHeader rh = new ReplyHeader(h.getXid(), 0, KeeperException.Code.OK.intValue());
            sendResponse(rh, null, null);
        }
        return;
    } else {
        Request si = new Request(this, sessionId, h.getXid(), h.getType(), incomingBuffer, authInfo);
        si.setOwner(ServerCnxn.me);
        zk.submitRequest(si);
    }
    if (h.getXid() >= 0) {
        synchronized (this) {
            outstandingRequests++;
        }
        synchronized (this.factory) {
            // check throttling
            if (zk.getInProcess() > factory.outstandingLimit) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Throttling recv " + zk.getInProcess());
                }
                disableRecv();
            // following lines should not be needed since we are
            // already reading
            // } else {
            // enableRecv();
            }
        }
    }
}
Also used : BinaryInputArchive(org.apache.jute_voltpatches.BinaryInputArchive) ReplyHeader(org.apache.zookeeper_voltpatches.proto.ReplyHeader) InputStream(java.io.InputStream) AuthPacket(org.apache.zookeeper_voltpatches.proto.AuthPacket) AuthenticationProvider(org.apache.zookeeper_voltpatches.server.auth.AuthenticationProvider) ConnectRequest(org.apache.zookeeper_voltpatches.proto.ConnectRequest) RequestHeader(org.apache.zookeeper_voltpatches.proto.RequestHeader)

Aggregations

AuthPacket (org.apache.zookeeper_voltpatches.proto.AuthPacket)4 RequestHeader (org.apache.zookeeper_voltpatches.proto.RequestHeader)2 InputStream (java.io.InputStream)1 BinaryInputArchive (org.apache.jute_voltpatches.BinaryInputArchive)1 ConnectRequest (org.apache.zookeeper_voltpatches.proto.ConnectRequest)1 ReplyHeader (org.apache.zookeeper_voltpatches.proto.ReplyHeader)1 AuthenticationProvider (org.apache.zookeeper_voltpatches.server.auth.AuthenticationProvider)1