StringBuffer tmp = new StringBuffer();
CSIv2Util.toString(secMech, tmp);
log.trace(tmp);
}
// these "null tokens" will be changed if needed
IdentityToken identityToken = absentIdentityToken;
byte[] encodedAuthenticationToken = noAuthenticationToken;
if ((secMech.sas_context_mech.target_supports
& IdentityAssertion.value) != 0)
{
// will create identity token
Principal p = null;
RunAsIdentity runAs = SecurityAssociation.peekRunAsIdentity();
if (runAs != null)
{
// will use run-as identity
p = runAs;
}
else
{
// will use caller identity
p = SecurityAssociation.getPrincipal();
}
if (p != null)
{
// The name scope needs to be externalized
String name = p.getName();
if (name.indexOf('@') < 0)
name += "@default"; // hardcoded (REVISIT!)
byte[] principalName = name.getBytes("UTF-8");
// encode the principal name as mandated by RFC2743
byte[] encodedName =
CSIv2Util.encodeGssExportedName(principalName);
// encapsulate the encoded name
Any any = ORB.init().create_any();
byte[] encapsulatedEncodedName = null;
GSS_NT_ExportedNameHelper.insert(any, encodedName);
try
{
encapsulatedEncodedName = codec.encode_value(any);
}
catch (InvalidTypeForEncoding e)
{
throw new RuntimeException("Unexpected exception: " + e);
}
// create identity token
identityToken = new IdentityToken();
identityToken.principal_name(encapsulatedEncodedName);
}
else if ((secMech.sas_context_mech.supported_identity_types
& ITTAnonymous.value) != 0)
{
// no run-as or caller identity and the target
// supports ITTAnonymous: use the anonymous identity
identityToken = new IdentityToken();
identityToken.anonymous(true);
}
}
if ((secMech.as_context_mech.target_requires
& EstablishTrustInClient.value) != 0)