(final ChannelBuffer buf,
final Channel chan)
| 101 | } |
| 102 | |
| 103 | @Override |
| 104 | public ChannelBuffer handleResponse(final ChannelBuffer buf, |
| 105 | final Channel chan) { |
| 106 | if (sasl_client == null) { |
| 107 | return buf; |
| 108 | } |
| 109 | |
| 110 | if (!sasl_client.isComplete()) { |
| 111 | final int state = buf.readInt(); |
| 112 | |
| 113 | //0 is success, 1 is an exception |
| 114 | //If unsuccessful let common exception handling do the work |
| 115 | if (state != 0) { |
| 116 | // We expect HBase to return a simple formated exception in the format: |
| 117 | // int length | exception class | int length | exception message |
| 118 | if (buf.readableBytes() < 8) { |
| 119 | throw new SecurityException("Sasl initialization failed with a " |
| 120 | + "status of [" + state + "] and an unknown exception. " |
| 121 | + "Check HBase logs.: " + this); |
| 122 | } |
| 123 | int len = buf.readInt(); |
| 124 | byte[] temp = new byte[len]; |
| 125 | buf.readBytes(temp); |
| 126 | final String exception = new String(temp); |
| 127 | |
| 128 | len = buf.readInt(); |
| 129 | temp = new byte[len]; |
| 130 | buf.readBytes(temp); |
| 131 | final String msg = new String(temp); |
| 132 | |
| 133 | throw new SecurityException("Sasl initialization failed with a " |
| 134 | + "status of [" + state + "] and exception [" + exception |
| 135 | + "] and message [" + msg + "]: " + this); |
| 136 | } |
| 137 | |
| 138 | final int len = buf.readInt(); |
| 139 | final byte[] b = new byte[len]; |
| 140 | buf.readBytes(b); |
| 141 | //if (LOG.isDebugEnabled()) { |
| 142 | // LOG.debug("Got SASL challenge: "+Bytes.pretty(b)); |
| 143 | //} |
| 144 | |
| 145 | final byte[] challenge_bytes = processChallenge(b); |
| 146 | |
| 147 | if (challenge_bytes != null) { |
| 148 | final byte[] out_bytes = new byte[4 + challenge_bytes.length]; |
| 149 | //if (LOG.isDebugEnabled()) { |
| 150 | // LOG.debug("Sending SASL response: "+Bytes.pretty(out_bytes)); |
| 151 | //} |
| 152 | final ChannelBuffer out_buffer = ChannelBuffers.wrappedBuffer(out_bytes); |
| 153 | out_buffer.clear(); |
| 154 | out_buffer.writeInt(challenge_bytes.length); |
| 155 | out_buffer.writeBytes(challenge_bytes); |
| 156 | Channels.write(chan, out_buffer); |
| 157 | } |
| 158 | |
| 159 | if (sasl_client.isComplete()) { |
| 160 | final String qop = (String)sasl_client.getNegotiatedProperty(Sasl.QOP); |
nothing calls this directly
no test coverage detected