use of org.dcache.xrootd.tpc.protocol.messages.InboundAuthenticationResponse in project xrootd4j by dCache.
the class GSIBucketUtils method deserializeData.
public static BucketData deserializeData(InboundAuthenticationResponse response) throws XrootdException {
BucketData data = new BucketData();
ByteBuf buffer = response.getDataBuffer();
data.protocol = deserializeProtocol(buffer);
data.step = deserializeStep(buffer);
try {
data.bucketMap.putAll(GSIBucketUtils.deserializeBuckets(buffer));
/*
* if pxyreq, do not deserialize and unpack the main bucket.
*/
if (data.step != kXGS_pxyreq) {
RawBucket mainBucket = (RawBucket) data.bucketMap.remove(kXRS_main);
ByteBuf mainBuffer = wrappedBuffer(mainBucket.getContent());
/*
* protocol and server step are repeated inside this bucket;
* skip.
*/
mainBuffer.readerIndex(8);
data.bucketMap.putAll(GSIBucketUtils.deserializeBuckets(mainBuffer));
}
} catch (IOException e) {
throw new XrootdException(kXR_IOError, e.toString());
}
response.releaseBuffer();
if (LOGGER.isTraceEnabled()) {
LOGGER.trace(describe("// Inbound Authentication Response", b -> dumpBuckets(b, data.bucketMap.values(), getServerStep(data.step)), response.getStreamId(), response.getRequestId(), response.getStatus()));
}
return data;
}
use of org.dcache.xrootd.tpc.protocol.messages.InboundAuthenticationResponse in project xrootd4j by dCache.
the class GSIClientAuthenticationHandler method sendAuthenticationRequest.
@Override
protected void sendAuthenticationRequest(ChannelHandlerContext ctx) throws XrootdException {
/*
* sendAuthenticationRequest is called by onLoginResponse first,
* then by onAuthenticationResponse. The request handler
* should be created on the login response.
*/
if (requestHandler == null) {
requestHandler = createRequestHandler();
}
ChannelId id = ctx.channel().id();
int streamId = client.getStreamId();
XrootdTpcInfo tpcInfo = client.getInfo();
OutboundAuthenticationRequest request;
InboundAuthenticationResponse response = client.getAuthResponse();
if (response != null) {
BucketData data = deserializeData(response);
serverStep = data.getStep();
if (!data.getProtocol().equals(PROTOCOL)) {
throw new XrootdException(kGSErrBadProtocol, "server replied " + "with incorrect protocol: " + data.getProtocol());
}
switch(serverStep) {
case kXGS_cert:
request = requestHandler.handleCertStep(response, data, ctx);
LOGGER.debug("sendAuthenticationRequest to {}, channel {}, " + "stream {}, step: cert.", tpcInfo.getSrc(), id, streamId);
break;
case kXGS_pxyreq:
/*
* This is a TPC client only. It tells the server
* it does not sign proxy requests. If this
* step is received here, we should reject it.
* Fall through to exception.
*/
default:
throw new XrootdException(kGSErrBadOpt, "client does not handle requested " + "authentication step " + getServerStep(serverStep) + ".");
}
} else {
request = requestHandler.handleCertReqStep();
LOGGER.debug("sendAuthenticationRequest to {}, channel {}, " + "stream {}, step: cert request.", tpcInfo.getSrc(), id, streamId);
}
requestHandler.updateLastRequest();
client.setExpectedResponse(kXR_auth);
client.setAuthResponse(null);
ctx.writeAndFlush(request, ctx.newPromise()).addListener(FIRE_EXCEPTION_ON_FAILURE);
client.startTimer(ctx);
}
use of org.dcache.xrootd.tpc.protocol.messages.InboundAuthenticationResponse in project xrootd4j by dCache.
the class XrootdClientDecoder method decode.
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) {
ChannelId id = ctx.channel().id();
int readable = in.readableBytes();
if (readable < SERVER_RESPONSE_LEN) {
return;
}
int pos = in.readerIndex();
int headerFrameLength = in.getInt(pos + 4);
if (headerFrameLength < 0) {
LOGGER.error("Decoder {}, channel {}: received illegal " + "frame length in " + "xrootd header: {}." + " Closing channel.", sourceUrn, id, headerFrameLength);
ctx.channel().close();
return;
}
int length = SERVER_RESPONSE_LEN + headerFrameLength;
if (readable < length) {
return;
}
ByteBuf frame = in.readSlice(length);
int requestId = client.getExpectedResponse();
try {
switch(frame.getUnsignedShort(2)) {
case kXR_error:
LOGGER.debug("Decoder {}, channel {}: adding error response.", sourceUrn, id);
out.add(new InboundErrorResponse(frame));
return;
case kXR_wait:
LOGGER.debug("Decoder {}, channel {}: adding wait response.", sourceUrn, id);
out.add(new InboundWaitResponse(frame, requestId));
return;
case kXR_waitresp:
LOGGER.debug("Decoder {}, channel {}: adding waitresp response.", sourceUrn, id);
out.add(new InboundWaitRespResponse(frame, requestId));
return;
case kXR_redirect:
LOGGER.debug("Decoder {}, channel {}: adding redirect response.", sourceUrn, id);
out.add(new InboundRedirectResponse(frame, requestId));
return;
case kXR_attn:
LOGGER.debug("Decoder {}, channel {}: adding attn response.", sourceUrn, id);
out.add(new InboundAttnResponse(frame, requestId));
return;
}
switch(requestId) {
case kXR_handshake:
LOGGER.debug("Decoder {}, channel {}: adding handshake response.", sourceUrn, id);
out.add(new InboundHandshakeResponse(frame));
break;
case kXR_protocol:
LOGGER.debug("Decoder {}, channel {}: adding protocol response.", sourceUrn, id);
out.add(new InboundProtocolResponse(frame));
break;
case kXR_login:
LOGGER.debug("Decoder {}, channel {}: adding login response.", sourceUrn, id);
out.add(new InboundLoginResponse(frame));
break;
case kXR_auth:
LOGGER.debug("Decoder {}, channel {}: adding authentication response.", sourceUrn, id);
out.add(new InboundAuthenticationResponse(frame));
break;
case kXR_open:
LOGGER.debug("Decoder {}, channel {}: adding open response.", sourceUrn, id);
out.add(new InboundOpenReadOnlyResponse(frame));
break;
case kXR_read:
LOGGER.debug("Decoder {}, channel {}: adding read response.", sourceUrn, id);
out.add(new InboundReadResponse(frame));
break;
case kXR_query:
LOGGER.debug("Decoder {}, channel {}: adding query response.", sourceUrn, id);
out.add(new InboundChecksumResponse(frame));
break;
case kXR_close:
LOGGER.debug("Decoder {}, channel {}: adding close response.", sourceUrn, id);
out.add(new InboundCloseResponse(frame));
break;
case kXR_endsess:
LOGGER.debug("Decoder {}, channel {}: adding endsess response.", sourceUrn, id);
out.add(new InboundEndSessionResponse(frame));
break;
default:
LOGGER.debug("Decoder {}, channel {}, received incorrect " + "response of request type {}.", sourceUrn, id, requestId);
throw new XrootdException(kXR_error, "received incorrect response type.");
}
} catch (ParseException | XrootdException e) {
LOGGER.error("Decoder {}, channel {}: error for request type {}: {}. " + "Closing channel.", requestId, id, e.getMessage());
client.setError(e);
client.shutDown(ctx);
}
}
Aggregations