{
KdcReq request = tgsContext.getRequest();
Ticket tgt = tgsContext.getTgt();
Ticket newTicket = tgsContext.getNewTicket();
TgsRep reply = new TgsRep();
reply.setCName( tgt.getEncTicketPart().getCName() );
reply.setCRealm( tgt.getEncTicketPart().getCRealm() );
reply.setTicket( newTicket );
EncKdcRepPart encKdcRepPart = new EncKdcRepPart();
encKdcRepPart.setKey( newTicket.getEncTicketPart().getKey() );
encKdcRepPart.setNonce( request.getKdcReqBody().getNonce() );
// TODO - resp.last-req := fetch_last_request_info(client); requires store
// FIXME temporary fix, IMO we should create some new ATs to store this info in DIT
LastReq lastReq = new LastReq();
lastReq.addEntry( new LastReqEntry( LastReqType.TIME_OF_INITIAL_REQ, new KerberosTime() ) );
encKdcRepPart.setLastReq( lastReq );
encKdcRepPart.setFlags( newTicket.getEncTicketPart().getFlags() );
encKdcRepPart.setClientAddresses( newTicket.getEncTicketPart().getClientAddresses() );
encKdcRepPart.setAuthTime( newTicket.getEncTicketPart().getAuthTime() );
encKdcRepPart.setStartTime( newTicket.getEncTicketPart().getStartTime() );
encKdcRepPart.setEndTime( newTicket.getEncTicketPart().getEndTime() );
encKdcRepPart.setSName( newTicket.getSName() );
encKdcRepPart.setSRealm( newTicket.getRealm() );
if ( newTicket.getEncTicketPart().getFlags().isRenewable() )
{
encKdcRepPart.setRenewTill( newTicket.getEncTicketPart().getRenewTill() );
}
if ( LOG_KRB.isDebugEnabled() )
{
monitorContext( tgsContext );
monitorReply( reply, encKdcRepPart );
}
EncTgsRepPart encTgsRepPart = new EncTgsRepPart();
encTgsRepPart.setEncKdcRepPart( encKdcRepPart );
Authenticator authenticator = tgsContext.getAuthenticator();
EncryptedData encryptedData;
if ( authenticator.getSubKey() != null )
{
encryptedData = cipherTextHandler.seal( authenticator.getSubKey(), encTgsRepPart,
KeyUsage.TGS_REP_ENC_PART_TGS_AUTHNT_SUB_KEY );
}
else
{
encryptedData = cipherTextHandler.seal( tgt.getEncTicketPart().getKey(), encTgsRepPart,
KeyUsage.TGS_REP_ENC_PART_TGS_SESS_KEY );
}
reply.setEncPart( encryptedData );
reply.setEncKdcRepPart( encKdcRepPart );
tgsContext.setReply( reply );
}