}
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);
assertTrue(resp.isCommitted());
}
//
Map<String, String[]> params = new HashMap<String, String[]>();
params.put("initialURI", new String[]{"/bar"});
String url = resp.renderURL("/", params, null);
return new InvokeGetResponse(url);
}
else if (getRequestCount() == 1)
{
assertEquals("/bar", wciController.getInitialURI(req));
if ("Tomcat/7.x".equals(container.getContainerInfo()) || "JBossas/6.x".equals(container.getContainerInfo()))
{
assertEquals("login", v.value);
container.logout(req, resp);
assertEquals("logout", v.value);
assertNull(req.getUserPrincipal());
}
else
{
// Test logout
assertNotNull(req.getSession(false));
assertEquals("login", v.value);
container.logout(req, resp);
assertNull(req.getSession(false));
// Test logout Event
assertEquals("logout", v.value);
}
String url = resp.renderURL("/", null, null);
return new InvokeGetResponse(url);
}
else if (getRequestCount() == 2)
{
assertEquals(
"/home/j_security_check?j_username=foo&j_password=bar",
wciController.getAuthURI(req, resp, credentials.getUsername(), credentials.getPassword())
);
wciController.sendAuth(req, resp, credentials.getUsername(), credentials.getPassword());
assertTrue(resp.isCommitted());
return new EndTestResponse();
}
return new FailureResponse(Failure.createAssertionFailure("End test reached"));
}