(ChannelBuffer buf, Channel chan)
| 100 | } |
| 101 | |
| 102 | @Override |
| 103 | public ChannelBuffer handleResponse(ChannelBuffer buf, Channel chan) { |
| 104 | if (sasl_client == null) { |
| 105 | return buf; |
| 106 | } |
| 107 | |
| 108 | if (!sasl_client.isComplete()) { |
| 109 | final int readIdx = buf.readerIndex(); |
| 110 | //RPCID is always -33 during SASL handshake |
| 111 | final int rpcid = buf.readInt(); |
| 112 | if (rpcid != -33) { |
| 113 | LOG.warn("Expected a value of -33 during SASL handshake, recieved " + rpcid); |
| 114 | } |
| 115 | |
| 116 | //read rpc state |
| 117 | final int state = buf.readInt(); |
| 118 | |
| 119 | //0 is success |
| 120 | //If unsuccessful let common exception handling do the work |
| 121 | if (state != 0) { |
| 122 | buf.readerIndex(readIdx); |
| 123 | return buf; |
| 124 | } |
| 125 | |
| 126 | //Get length |
| 127 | //check for special case in length, for request to fallback simple auth |
| 128 | //let's not support this if we don't have to; seems like a security loophole |
| 129 | final int len = buf.readInt(); |
| 130 | if (len == SWITCH_TO_SIMPLE_AUTH) { |
| 131 | throw new IllegalStateException("Server is requesting to fallback " |
| 132 | + "to simple authentication"); |
| 133 | } |
| 134 | |
| 135 | final byte[] b = new byte[len]; |
| 136 | buf.readBytes(b); |
| 137 | //if (LOG.isDebugEnabled()) { |
| 138 | // LOG.debug("Got SASL challenge: " + Bytes.pretty(b)); |
| 139 | //} |
| 140 | |
| 141 | final byte[] challengeBytes = processChallenge(b); |
| 142 | |
| 143 | if (challengeBytes != null) { |
| 144 | final byte[] outBytes = new byte[4 + challengeBytes.length]; |
| 145 | //if (LOG.isDebugEnabled()) { |
| 146 | // LOG.debug("Sending SASL response: " + Bytes.pretty(outBytes)); |
| 147 | //} |
| 148 | ChannelBuffer outBuffer = ChannelBuffers.wrappedBuffer(outBytes); |
| 149 | outBuffer.clear(); |
| 150 | outBuffer.writeInt(challengeBytes.length); |
| 151 | outBuffer.writeBytes(challengeBytes); |
| 152 | Channels.write(chan, outBuffer); |
| 153 | } |
| 154 | |
| 155 | if (sasl_client.isComplete()) { |
| 156 | final String qop = (String) sasl_client.getNegotiatedProperty(Sasl.QOP); |
| 157 | LOG.info("SASL client context established. Negotiated QoP: " + qop + |
| 158 | " on for: " + region_client); |
| 159 | sendRPCHeader(chan); |
nothing calls this directly
no test coverage detected