long contextId =
contextBody.in_context_msg().client_context_id;
threadLocal.sasReply =
createMsgCtxError(contextId,
4 /* major status: no context */);
throw new NO_PERMISSION("SAS context does not exist.");
}
else if (contextBody.discriminator() == MTEstablishContext.value)
{
EstablishContext message = contextBody.establish_msg();
threadLocal.contextId = message.client_context_id;
threadLocal.sasContextReceived = true;
if (message.client_authentication_token != null
&& message.client_authentication_token.length > 0)
{
if (traceEnabled)
log.trace("received client authentication token");
InitialContextToken authToken =
CSIv2Util.decodeInitialContextToken(
message.client_authentication_token,
codec);
if (authToken == null)
{
threadLocal.sasReply =
createMsgCtxError(message.client_context_id,
2 /* major status:
invalid mechanism */);
throw new NO_PERMISSION("Could not decode " +
"initial context token.");
}
threadLocal.incomingUsername = authToken.username;
threadLocal.incomingPassword = authToken.password;
threadLocal.incomingTargetName =
CSIv2Util.decodeGssExportedName(authToken.target_name);
if (threadLocal.incomingTargetName == null)
{
threadLocal.sasReply =
createMsgCtxError(message.client_context_id,
2 /* major status:
invalid mechanism */);
throw new NO_PERMISSION("Could not decode target name " +
"in initial context token.");
}
threadLocal.authenticationTokenReceived = true;
}
if (message.identity_token != null)
{
if (traceEnabled)
log.trace("received identity token");
threadLocal.incomingIdentity = message.identity_token;
if (message.identity_token.discriminator() == ITTPrincipalName.value)
{
// Extract the RFC2743-encoded name
// from CDR encapsulation
Any a = codec.decode_value(
message.identity_token.principal_name(),
GSS_NT_ExportedNameHelper.type());
byte[] encodedName = GSS_NT_ExportedNameHelper.extract(a);
// Decode the principal name
threadLocal.incomingPrincipalName =
CSIv2Util.decodeGssExportedName(encodedName);
if (threadLocal.incomingPrincipalName == null)
{
threadLocal.sasReply =
createMsgCtxError(message.client_context_id,
2 /* major status:
invalid mechanism */);
throw new NO_PERMISSION("Could not decode " +
"incoming principal name.");
}
}
}
threadLocal.sasReply = (threadLocal.contextId == 0) ?