private WCIController wciController = new TestController();
@Override
public DriverResponse service(TestServlet testServlet, WebRequest req, WebResponse resp) throws ServletException, IOException
{
Credentials credentials = wciController.getCredentials(req, resp);
if (getRequestCount() == 0)
{
assertEquals("/home", wciController.getInitialURI(req));
req.setAttribute("javax.servlet.forward.request_uri", "/foo");
assertEquals("/foo", wciController.getInitialURI(req));
// Test Ticket Expiration
String expireTicket = GenericAuthentication.TICKET_SERVICE.createTicket(new Credentials("foo", "bar"), 5);
boolean expired = false;
try
{
Thread.sleep(5);
GenericAuthentication.TICKET_SERVICE.validateTicket(expireTicket, true);
}
catch (InterruptedException ignore)
{
}
catch (AuthenticationException ae)
{
expired = true;
}
if (!expired) return new FailureResponse(Failure.createAssertionFailure(""));
assertNull(req.getUserPrincipal());
container = DefaultServletContainerFactory.getInstance().getServletContainer();
container.addAuthenticationListener(new TestListener(v));
assertEquals("", v.value);
container.login(req, resp, credentials, TicketService.DEFAULT_VALIDITY);
if ("Tomcat/7.x".equals(container.getContainerInfo()) || "JBossas/6.x".equals(container.getContainerInfo()))
{
assertEquals("login", v.value);
assertNotNull(req.getUserPrincipal());
assertTrue(req.isUserInRole("test"));
}
else
{
// Test Ticket Service
String ticket = GenericAuthentication.TICKET_SERVICE.createTicket(credentials, TicketService.DEFAULT_VALIDITY);
Credentials resultCredentials = GenericAuthentication.TICKET_SERVICE.validateTicket(ticket, false);
assertEquals(credentials.getUsername(), resultCredentials.getUsername());
assertEquals(credentials.getPassword(), resultCredentials.getPassword());
assertNotNull(GenericAuthentication.TICKET_SERVICE.validateTicket(ticket, true));
assertNull(GenericAuthentication.TICKET_SERVICE.validateTicket(ticket, true));
// Test login Event
assertEquals("login", v.value);