Authenticator authenticator = new Authenticator();
try
{
authenticator.setCName( new PrincipalName( srvTktReq.getTgt().getClientName(), PrincipalNameType.KRB_NT_PRINCIPAL ) );
}
catch( ParseException e )
{
throw new IllegalArgumentException( "Couldn't parse the given principal", e );
}
authenticator.setCRealm( srvTktReq.getTgt().getRealm() );
authenticator.setCTime( new KerberosTime() );
authenticator.setCusec( 0 );
if( srvTktReq.getSubSessionKey() != null )
{
sessionKey = srvTktReq.getSubSessionKey();
authenticator.setSubKey( sessionKey );
}
EncryptedData authnData = cipherTextHandler.encrypt( sessionKey, getEncoded( authenticator ), KeyUsage.TGS_REQ_PA_TGS_REQ_PADATA_AP_REQ_TGS_SESS_KEY );
ApReq apReq = new ApReq();
apReq.setAuthenticator( authnData );
apReq.setTicket( srvTktReq.getTgt().getTicket() );
apReq.setApOptions( srvTktReq.getApOptions() );
KdcReqBody tgsReqBody = new KdcReqBody();
tgsReqBody.setKdcOptions( srvTktReq.getKdcOptions() );
tgsReqBody.setRealm( KdcClientUtil.extractRealm( serverPrincipal ) );
tgsReqBody.setTill( getDefaultTill() );
int currentNonce = nonceGenerator.nextInt();
tgsReqBody.setNonce( currentNonce );
tgsReqBody.setEType( config.getEncryptionTypes() );
PrincipalName principalName = new PrincipalName( KdcClientUtil.extractName( serverPrincipal ), KerberosPrincipal.KRB_NT_SRV_HST );
tgsReqBody.setSName( principalName );
TgsReq tgsReq = new TgsReq();
tgsReq.setKdcReqBody( tgsReqBody );