EncTicketPart encTicketPart = getTicketArchetype( clientPrincipal );
// Make changes to test.
encTicketPart.setFlag( TicketFlag.MAY_POSTDATE );
// Service ticket end time will be limited by TGT end time.
encTicketPart.setEndTime( new KerberosTime( now + 3 * KerberosTime.DAY ) );
// Seal the ticket for the server.
KerberosPrincipal serverPrincipal = new KerberosPrincipal( "krbtgt/EXAMPLE.COM@EXAMPLE.COM" );
String passPhrase = "randomKey";
EncryptionKey serverKey = getEncryptionKey( serverPrincipal, passPhrase );
Ticket tgt = getTicket( encTicketPart, serverPrincipal, serverKey );
KdcReqBody kdcReqBody = new KdcReqBody();
kdcReqBody.setSName( getPrincipalName( "hnelson" ) );
kdcReqBody.setRealm( "EXAMPLE.COM" );
kdcReqBody.setEType( config.getEncryptionTypes() );
kdcReqBody.setNonce( random.nextInt() );
KdcOptions kdcOptions = new KdcOptions();
kdcOptions.set( KdcOptions.POSTDATED );
kdcReqBody.setKdcOptions( kdcOptions );
KerberosTime requestedStartTime = new KerberosTime( now + KerberosTime.DAY );
kdcReqBody.setFrom( requestedStartTime );
KerberosTime requestedEndTime = new KerberosTime( now + 2 * KerberosTime.DAY );
kdcReqBody.setTill( requestedEndTime );
KdcReq message = getKdcRequest( tgt, kdcReqBody );
handler.messageReceived( session, message );
Object msg = session.getMessage();
assertEquals( "session.getMessage() instanceOf", TgsRep.class, msg.getClass() );
TgsRep reply = ( TgsRep ) msg;
assertTrue( "Requested start time", requestedStartTime.equals( reply.getStartTime() ) );
assertTrue( "Requested end time", requestedEndTime.equals( reply.getEndTime() ) );
assertTrue( "POSTDATED flag", reply.getFlags().isPostdated() );
assertTrue( "INVALID flag", reply.getFlags().isInvalid() );
assertTrue( "Requested start time", requestedStartTime.equals( reply.getTicket().getEncTicketPart().getStartTime() ) );
assertTrue( "Requested end time", requestedEndTime.equals( reply.getEndTime() ) );
assertTrue( "POSTDATED flag", reply.getTicket().getEncTicketPart().getFlags().isPostdated() );
assertTrue( "INVALID flag", reply.getTicket().getEncTicketPart().getFlags().isInvalid() );
}